Replies: 1 comment 12 replies
-
The reason why the old value would be the "same" is that it is. It's an object. The object is the same by reference, not unique on each go. I think if we knew more about what your true intent is, we could give better advice. |
Beta Was this translation helpful? Give feedback.
12 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am trying to catch any Alpine.store/object property changes but I can't seem to get it to work successfully.
Using Alpine.effect it seems I need to wrap the object within JSON.stringify to get effect to trigger on every property change, which feels a bit like a hack but the biggest problem here is that I won't have access to the previous value. So I can't really detect which value has been changed:
Another option is probably using $watch which should provide us with the previous value, which seems to work well when watching a specific property, but when watching the entire store/object both value and oldValue seem to always end up being the same. (I actually only need to know the key, but if I'd have the old object and the new object I could parse out the changes myself)
Another way to make it work could be by adding onchange, onclick, etc, events to every element. Which won't give me the oldValue either but that's okay since I only need to know which value has been changed and what the new value is, it does seem like rather repetitive when having a ton of elements:
Does anyone know a way to make this work best as possible?
Beta Was this translation helpful? Give feedback.
All reactions