Replies: 5 comments
-
Unfortunately this is not possible because of how the state can be changed from anywhere.
Another important question is what makes this crucial (rather than just conveniently) |
Beta Was this translation helpful? Give feedback.
-
I see, so I guess watches will serve that purpose for now. I think the crucial reason was to be able to actually see where the change happened on the whole store directly without using watches. The receiving code can then even mutate the store based on the information received. Without knowing what changed and thereby deciding what to do intelligently, we can end up creating an infinite loop if we mutate the state for some reason since it will call the sub again. A way to compare new and previous can allow us to decide on things. The probable way of doing this would be to keep a clone of the current state in the store, whenever it changes, then emit that as the previous and pass that along with the new state to subs. Not too sure whether that should work at the low level of subs or not, but it seems dirty enough to work. If not this can be implemented at plugin level where the plugin simply takes care of this, by storing the clone in a $prevState prop in the store and then override $subscribe CB to achieve this. |
Beta Was this translation helpful? Give feedback.
-
Do you have a concrete example?
For performance reasons, yes, a plugin should be the one doing a deep copy. |
Beta Was this translation helpful? Give feedback.
-
You could not send events key together to the events path callback |
Beta Was this translation helpful? Give feedback.
-
Note |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
What problem is this solving
I think the subscription feature is awesome, however it can be more versatile if it were targeted or at least revel what has changed. At least certain logic can behave differently or just sort of react to particular piece of the state.
This has always been a pain with Vuex subscriptions.
Proposed solution
more like watches.
or at least allow us to do
which targets an inner prop of a state
Describe alternatives you've considered
usage of watch on the state data
Beta Was this translation helpful? Give feedback.
All reactions