You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I came across a strange state behavior using redux 0.12 and I don't know if it's a bug or a misuse. The code above does not reflect my real code but is the best minimal example I could came up with that highlight the "bug".
My understanding of redux was that after having filled the connectStore with {logged: true}, a new action triggered should be applied on this new store value. But unfortunately I get an empty connectStore when calling actionCreators.getProfileData()...
After some console.log in redux I found out that this behavior seems to be due to the state being kept in 2 different places:
in createDispatcher.js via a closure on dispatch
in Redux.js via this.state
so when calling dispatch(action) (in createDispatcher.js), if another action is triggered in a redux listener (in Redux.js), the second action does not benefit from the update that the first action triggered (because it was not written yet in closured state in createDispatcher.js). Here is some redux code above to explain what I mean.
// createDispatcher.jsvarstate=setState(store(initialState,INIT_ACTION));// the closure state variablefunctiondispatch(action){// state = ... is only effective AFTER all listeners in Redux.setState have been calledstate=setState(store(state,action));returnaction;}// REDUX.jsRedux.prototype.setState=functionsetState(nextState){this.state=nextState;// the state property of Reduxthis.listeners.forEach(function(listener){// if another action is called in 'listener', we'll end up with Redux.state != createDispatcher.statereturnlistener();});returnnextState;};
Maybe this is the normal behavior but I don't feel like calling an action from a listener is a wrong since it is pretty common when you realize that the listener may call a React component lifecycle method (thanks to @connect decorator).
Thanks!
The text was updated successfully, but these errors were encountered:
Hi,
I came across a strange state behavior using redux 0.12 and I don't know if it's a bug or a misuse. The code above does not reflect my real code but is the best minimal example I could came up with that highlight the "bug".
Running this script using
babel-node --stage=0 test.js
produce the following output:What I interpret as a bug are the connectStore value being
{}
just after calling actionCreators.getProfileData().My understanding of redux was that after having filled the connectStore with
{logged: true}
, a new action triggered should be applied on this new store value. But unfortunately I get an empty connectStore when callingactionCreators.getProfileData()
...I was expecting to have:
After some console.log in redux I found out that this behavior seems to be due to the state being kept in 2 different places:
createDispatcher.js
via a closure ondispatch
Redux.js
via this.stateso when calling
dispatch(action)
(increateDispatcher.js
), if another action is triggered in a redux listener (inRedux.js
), the second action does not benefit from the update that the first action triggered (because it was not written yet in closuredstate
increateDispatcher.js
). Here is some redux code above to explain what I mean.Maybe this is the normal behavior but I don't feel like calling an action from a listener is a wrong since it is pretty common when you realize that the listener may call a React component lifecycle method (thanks to
@connect
decorator).Thanks!
The text was updated successfully, but these errors were encountered: