4 ms·
> 4) "You might not need Redux"[3] For some older projects I found a hand-built flux helper[0] of ~220 lines worked great and didn't require any toolchain modi
by guscost 10y ago
> 4) "You might not need Redux"[3]
For some older projects I found a hand-built flux helper[0] of ~220 lines worked great and didn't require any toolchain modifications. The switching costs to some of the ES6 stuff was too high in that case, but it's also a potentially leaner app if you don't need the advanced features of Redux and ES6.
The Redux architecture is so nice though.
[0] https://github.com/guscost/simple-flux https://github.com/guscost/simple-flux
- Etheryte 10y agoRedux is just a fancy pubsub.
- chrislloyd 10y agoOr less fancy depending on how you look at it.
- cel1ne 10y agoI think redux got 50% right and 50% wrong. 1. good: having a sideeffect-free, serializable application state. That concept can also be used in mobile apps for easy pause/resume. 2. good: being able to render that state from one parent, because you don't need to manage two separate statemachines (the UI and the business logic) anymore. 3. bad: shoe-horning all state-transition into functions/reducers. Fp is awesome, but sometimes imperative constructs are more appropriate, especially in a mostly imperative language. Use fp where it feels natural, not everywhere. 4. bad: shoe-horning everything into immutable data-structures. Seriously, when did newName => { this.name = newName } become (state, newName) => { return state.set("name", newName) } ? Just change the state. If you want to prevent errors, freeze and seal your state. If you want time-travelling debugging, copy it via serialization. No need to slow down production code by copying and throwing away data all the time. 5. bad: using Immutable.js, thereby slowing your code down by two or three orders of magnitude. And I guess losing many GC and JIT optimizations by throwing out different types of objects and pressing everything into the generic map-structures, that immutable.js uses internally) I wrote multiple sites/apps using immutable and redux, but i'm back to pure react and lodash. Code is more concise, simpler and way faster, even though componentDidUpdate has to use lodash's _.isEqual instead of a simple comparison.
- talldan 10y agoUnless something has changed very recently, you don't have to use Immutable.js and redux together. Redux advises against mutating your state, but doesn't prescribe a way to do that.
- cel1ne 10y agoTrue, I did applications with redux and without immutable too, even wrote my own syntax magic for that: https://www.npmjs.com/package/babel-plugin-check-data-access https://www.npmjs.com/package/babel-plugin-check-data-access What redux misses as well are derived/computed properties, I think mobX has them: https://mobxjs.github.io/mobx/ https://mobxjs.github.io/mobx/
- acemarke 10y agoThe standard approach is to store the minimal amount of data directly in the state, and derive data as needed externally to the store. This is usually done with "selector functions". See http://redux.js.org/docs/recipes/ComputingDerivedData.html http://redux.js.org/docs/recipes/ComputingDerivedData.html , https://medium.com/@adamrackis/querying-a-redux-store-37db8c7f3b0f https://medium.com/@adamrackis/querying-a-redux-store-37db8c... , and http://redux.js.org/docs/faq/CodeStructure.html#structure-file-structure http://redux.js.org/docs/faq/CodeStructure.html#structure-fi... for more information.
- danabramov 10y agoUm, no, you don't need to use Immutable with Redux. And regarding syntax, with object rest/spread (stage 3): (state, newName) => ({ ...state, name: newName }) It's not that verbose.
- cageface 10y agoMy main hesitation with Redux is how awkward it is to insert async calls in the chain of events. Things like redux-thunk and redux-saga are impressive hacks but feel like a lot of gymnastics to do something that pretty much every React app needs to do.
- danabramov 10y agoRedux is about 100 lines if you remove some development warnings. ;-)