volt icon indicating copy to clipboard operation
volt copied to clipboard

Trigger hook on parent array property

Open undjike opened this issue 1 year ago • 8 comments

This PR addresses issue https://github.com/livewire/volt/issues/107.

It allows triggering the update hook on the parent array property when a change is made to a key.

Before : When updating on a key, the hook is only triggered for that key.

updated([
    'profiles' => function () {
        // Not triggered
    },
    /*'profiles.0' => function () {
        // You need to explicitly listen for the key being updated.
        // There can be several keys.
        // You must listen to them all if you want to take action on any changes made to the parent array.
    }*/
]);

With this PR : When updating on a key, the hook is triggered on the parent array, if not explicitly listening for changes to the key.

updated([
    'profiles' => function ($key) {
        // Triggered, and the modified key is passed as a parameter.
    }
]);

That said... I'm wondering whether we should make it more dynamic to handle deep subkey as well.

updated([
    'profiles.admin' => function () {
        // Triggered on change made to key 'profiles.admin.0'.
    }
]);

This PR will forward the hook to the parent property profiles not to profiles.admin.

undjike avatar Jun 29 '24 15:06 undjike

If we are going to merge this it should probably handle your last case of deep subkeys.

taylorotwell avatar Jul 02 '24 15:07 taylorotwell

Mark as ready for review again when you want me to take another look please. Thanks!

taylorotwell avatar Jul 02 '24 15:07 taylorotwell

Added support for deep subkeys. Hope the codebase is still in line with the package behaviour.

undjike avatar Jul 03 '24 05:07 undjike

Hello @taylorotwell any comment ?

undjike avatar Jul 06 '24 18:07 undjike

@taylorotwell let me know if there is something you want me to adjust.

undjike avatar Jul 20 '24 13:07 undjike

@undjike @taylorotwell any updates on this PR?

alexmanase avatar Dec 23 '24 12:12 alexmanase

Any updates here?

philippbuerger avatar Jan 22 '25 10:01 philippbuerger

Is there any update on this issue?

robbyrice avatar Mar 28 '25 10:03 robbyrice