4 ms·
Controversial opinion: Redux (and the Elm architecture behind it) only works with a typed language like TypeScript (or Elm) which takes away the error-prone par
by elbear 3y ago
Controversial opinion: Redux (and the Elm architecture behind it) only works with a typed language like TypeScript (or Elm) which takes away the error-prone part. With good type completion, some of the "pretty tedious" part goes away as well.
- agos 3y agoeven with completion it's a lot of busywork: define actions, reducers, etc for every state change
- pseudocomposer 3y agoIf you use TypeScript and Thunk, it’s no more work than writing your own state management code on plain JS/TS objects. But you get all the advantages of Redux (dev tools, introspection, replayability, easy persistence and tab sync, etc).
- cageface 3y agoYeah strong typing is essential. Redux is overkill for small or even medium apps but it's the best tool I've found for dealing with the complexity of larger apps. Having a very clear, inspectable sequence of mutations to all your data becomes very valuable.
- deleted 3y ago[deleted]
- hombre_fatal 3y agoYou're probably right about Elm which is basically one big reducer, but Redux adds a whole lot more indirection on top of that which makes it much more complicated. Even small Redux apps can start off with a lot of indirection as soon as they extract logic into selectors. This is probably the first area where Redux becomes more complex that what you were doing before: https://redux.js.org/usage/deriving-data-selectors https://redux.js.org/usage/deriving-data-selectors It reminds me of reading a bunch of parser combinators: it feels like you're reading code that builds something that does what you want instead of the code that just does what you want. const makeSelectItemsByCategory = () => { const selectItemsByCategory = createSelector( [state => state.items, (state, category) => category], (items, category) => items.filter(item => item.category === category) ) return selectItemsByCategory }
- elbear 3y agoYeah, with Elm, when you handle an event, you either update the model (state) or you generate new events. You don't have this selector thing.