-
-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Closed
Labels
Description
We really, really need a page talking about approaches, guidelines, and suggestions for organizing reducer logic. I've been saying I want to write this for a while, but have been too busy so far. I'm still up for it, but further suggestions and/or offers of help would be appreciated.
Initial sketch of possible topics:
- Understanding that you really only have one reducer function, which is just subdivided for maintainability and simplicity
- Understanding "reducer composition" and that you can break things down using plain ol' functions
- The basic rules of reducers:
(state, action) -> newState
, immutable updates, and one other item I've said before but I'm not remembering at the moment - Emphasis that
combineReducers
is simply a utility function for the common use case of delegating update logic based on state domain organization, and not a requirement - That defining object keys when using
createReducers
is, effectively, defining the name/shape of your state (not always clear when using ES6 object literal shorthand - naming of imported reducer functions matters!) - That "actions are passed to all reducers" only if you're using
combineReducers
- Passing different chunks or all of the state to a sub-reducer based on need for that action
- Initializing state
- Normalizing data
- Updating normalized data
- Updating data immutably in general, particularly nested data and arrays, and how just using a variable assignment doesn't mean you've "made a copy"
- Reusing logic and creating reducers that can be "targeted"
- A whole bunch of other stuff that has crossed my mind at various points and that I'm not thinking of right now, but hopefully will remember later
Random related links:
- A concern on combineReducer, when an action is related to multiple reducers #601
- Stopping state from growing forever (or: limiting displayed state) #644
- Best practice for updating dependent state across different branches of the state tree? #749
- How to create a generic list as a reducer and component enhancer? #822
- Document Redux Antipatterns #857
- A call for quality articles, examples, and resources #1014
- Add “Combining reducers” recipe #1018
- Recommendations for best practices regarding action-creators, reducers, and selectors #1171
- Document required default state in reducer #1617
- Same action for different state parts #1628
- Make dependent reducer explanation more prominent #1653
- mapStateToProps() not being called #1726
- Everything seems to need a UUID #1602 (comment)
- Normalising state and garbage collection #1824
More on reusability for custom components. #1850 - https://gist.github.com/deanius/f380994d117dffb5b625a7871a4fa893
- http://bbarr.github.io/code/2015/12/23/redux-with-pattern-matching.html
- https://www.reddit.com/r/javascript/comments/42ey9e/redux_reducer_composition_without_slicing_state/
- http://www.code-experience.com/problems-with-flux/
- https://twitter.com/dan_abramov/status/745248569599397888
- http://stackoverflow.com/questions/38012852/users-sees-one-part-of-deeply-nested-state-should-visible-properties-be-at-top/38017227#38017227
- http://stackoverflow.com/questions/33749759/read-stores-initial-state-in-redux-reducer/33791942
- [discussion] how can we improve state management? choojs/choo#252
Some overlap with the performance/optimization discussions in #1783 , the store organization mention in http://redux.js.org/docs/FAQ.html#organizing-state-nested-data , and the concepts in http://redux.js.org/docs/recipes/ComputingDerivedData.html .
sacho, mewdriller, ANich, sullenel, jiayihu and 15 more