For convenience, calls to setState are automatically batched as they are in React and only one change event will be emitted once the action finishes dispatching".
But from what I've seen, it doesn't seem to behave like that.
As you can see, doSetState does its work. It won't emitChange if it's still dispatching.
However the result of handleDispatch is always true. Then emitChange is called immediately after while it's still dispatching.
As a result of it, we can't dispatch actions within component lifecycle methods like componentDidUpdate. Otherwise, we'll get error "Dispatch.dispatch(...): Cannot dispatch in the middle of a dispatch."
The doc says
But from what I've seen, it doesn't seem to behave like that.
The following is the debug log of one dispatching process of https://github.com/iam4x/isomorphic-flux-boilerplate.
As you can see,
doSetState
does its work. It won'temitChange
if it's still dispatching.However the result of
handleDispatch
is always true. ThenemitChange
is called immediately after while it's still dispatching.As a result of it, we can't dispatch actions within component lifecycle methods like componentDidUpdate. Otherwise, we'll get error "Dispatch.dispatch(...): Cannot dispatch in the middle of a dispatch."