Subscribe on dispatch after store changed
See original GitHub issueHello.
I trying implement keypress form validation.
When user typed one symbol in input, I want to validate this value.
How can i do it?
store.on(SET_NAME, (state: any, name: string) => {
const data: IState = state[SECTION];
return {
...state,
[SECTION]: {
...data,
name
}
}
})
store.on('@dispatch', (state, [event]) => {
console.log(state);// This state show me moment BEFORE any changes created by event
})
store.on('@changed', () => {
// I can not know what event create state changes
})
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Subscribe to single property change in store in Redux
There is no way to subscribe to part of the store when using subscribe directly, but as the creator of Redux says himself...
Read more >Store - Redux
In Redux, subscriptions are called after the root reducer has returned the new state, so you may dispatch in the subscription listeners. You...
Read more >Dispatch Actions and Subscribe to State | Simple Store
Dispatch Actions and Subscribe to State. Open the src/app/app.component.ts file. Import store. First, import the store instance and create a new private ...
Read more >Actions and reducers: updating state - Human Redux
So store.subscribe() is simply a way to be notified that an action was dispatched, and therefore, something may have changed. You may be...
Read more >The Redux Store - LearnHowToProgram.com
Our store changes as actions are dispatched to it! Finally, we can call unsubscribe() to end our subscription. In the magazine metaphor, this...
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 Free
Top 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
@omcg33
The sage or redux-observables are able to achieve such requirement just because they modify the storage behavior, Redux has middlewares and enhancers to achieve that, but you have to do that in the place where you are creating the store, you can’t enhance the store behavior after it is created. It is declarative approach.
On the other hand Storeon doesn’t have middlewares and enhancers, by default you can’t modify the store behavior, but you can in imperative way enhance it just by the event handlers as I showed in the previous comment. The other good example of tjis difference is the storeon-observables vs redux-observables.
vs
But if you want, there is no problem to enhance the Storeon store behavior during the store creation, like in Redux, example:
Look for redux-saga. They did it. Any action that you got by take() will return you actual state yield take(SET_NAME, () => { const state = yield select(); // state has changes of SET_NAME })