3 ms·
A dispatch is not really equivalent to a method call. A reducer can't have side effects, and must be synchronous. So you can be certain that the state is consis
by underwater 9y ago
A dispatch is not really equivalent to a method call. A reducer can't have side effects, and must be synchronous. So you can be certain that the state is consistent immediately after the dispatch returns.
If you have complex action dispatchers the asynchronous logic is still contained in a single function. This is easier to test than a set of loosely coupled data objects that are firing of async events and calling each other through multiple levels of indirection.
- kevincennis 9y agoNot to nitpick, because I believe I understand what you mean – but one of the things that bugs me about Redux is that a reducer absolutely CAN have side-effects. They're just "not supposed to". So all it takes is one mistake or one new developer or whatever and suddenly all your assumptions break.
- doque 9y agoIt's one of the essentials principles of redux [1] that reducers must be pure functions without side effects. If you violate that principle, then yes, your assumptions break. That's why you should keep it in mind. You can't really blame the framework if you purposely go against its basic rules. [1] http://redux.js.org/docs/introduction/ThreePrinciples.html#changes-are-made-with-pure-functions http://redux.js.org/docs/introduction/ThreePrinciples.html#c...
- kevincennis 9y agoI get it. I really do. I just wish they had a reasonable way to _enforce_ those rules (though I understand it's not really possible) – or at least make people really go out of their way to break convention.
- acemarke 9y agoYep - I pointed this out in my post "The Tao of Redux, Part 1 - Implementation and Intent": http://blog.isquaredsoftware.com/2017/05/idiomatic-redux-tao-of-redux-part-1/ http://blog.isquaredsoftware.com/2017/05/idiomatic-redux-tao.... Those "Three Principles" are statements of intent, but not literal technical limitations.