Send previous state as the 3rd argument to store subscriptions
See original GitHub issueWhat 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
onStoreStateChange (mutation, state, prevState) {
}
more like watches.
or at least allow us to do
store.$subscribe (onStoreStateChange, 'countables.inner.count')
which targets an inner prop of a state
Describe alternatives you’ve considered
usage of watch on the state data
Issue Analytics
- State:
- Created a year ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
subscribe API with state as an argument #303 - reduxjs/redux
Please pass both current and previous state to listeners. I really don't want to have to keep a reference to the previous state...
Read more >Subscriptions - Apollo GraphQL Docs
Subscriptions are intended to be used to subscribe to external data changes, and have those received changes be stored in the cache. You...
Read more >Accessing previous props or state with React Hooks
Leverage the useRef, useState, usePrevious, and useEffect React Hooks to access previous props and states from within functional components.
Read more >Subscribe · Pullstate
Subscriptions are client-side only listeners to changes in your store's state. ... The third argument is the last watched value, passed as a...
Read more >How to stop a subscription after the response to a service ...
To get the actual value that caused takeWhile to end the subscription, pass true as a second parameter to takeWhile ( inclusive ):...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Note
events
is dev only and comes from VueYou could not send events key together to the events path callback Otherwise, you have to write an extra field in the repository in order to understand what caused the change
state: () => ({ size: { path: 'size', width: 1800, height: 2500, depth: 600, cover: { path: 'size.cover', //i want to remove this field state: false, value: 100, },
events.key -> ‘state’, events.path -> ‘size.cover’ I would like to see the full path to the parameter inside the object so that I can work with this path later