Can't we watch the structure attributes in x-data using x-effect? #4527
-
I don't know if it's a bug, or if it works as it should.
The first two buttons work as expected. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
Okay, I investigated more and found that this is not a bug—it's how AlpineJS is designed to work. Since the items object reference hasn't changed, Alpine doesn't detect the update to a property inside it. Now, this could be a feature request for Alpine to introduce something like Vue.set() (or another method) to explicitly trigger reactivity for nested properties. Do you think this kind of feature aligns with AlpineJS’s philosophy, or does it go against its lightweight and declarative nature? |
Beta Was this translation helpful? Give feedback.
-
Yes, it's intended, as the thing you accessed has not been reassigned. If you did I don't see any reason why you would want to have it respond to things not being accessed. Why rerun effects that give the same result? |
Beta Was this translation helpful? Give feedback.
-
Thank you @ekwoka for your answer. So, I guess it means that If you're interested, I've passed each item to another Alpine element to be used as its own state/data. When these child elements change the item, I'd like to be informed at the parent level. (I might eventually use a custom event for that)
|
Beta Was this translation helpful? Give feedback.
Yes, it's intended, as the thing you accessed has not been reassigned.
If you did
console.log(JSON.stringify(items))
it would trigger on all possible changes.I don't see any reason why you would want to have it respond to things not being accessed. Why rerun effects that give the same result?