Prerequisite Reducer Concepts
- Should have a signature of , similar to the type of function you would pass to
Array.prototype.reduce(reducer, ?initialValue)
- Should be "pure", which means the reducer:
- Does not perform side effects (such as calling API's or modifying non-local objects or variables).
- Does not call non-pure functions (like
Date.now
or ). - Does not mutate its arguments. If the reducer updates state, it should not modify the existing state object in-place. Instead, it should generate a new object containing the necessary changes. The same approach should be used for any sub-objects within state that the reducer updates.
Because of these rules, it's important that the following core concepts are fully understood before moving on to other specific techniques for organizing Redux reducers:
Redux Reducer Basics
Key concepts:
- Thinking in terms of state and state shape
- Delegating update responsibility by slice of state (reducer composition)
- Higher order reducers
- Redux Docs:
combineReducers
- Stack Overflow: Store initial state and
Pure Functions and Side Effects
Key Concepts:
- Side effects
- Pure functions
How to think in terms of combining functions
Reading List:- Understanding Programmatic Side-Effects
- An Introduction to Reasonably Pure Functional Programming
Immutable Data Management
- Mutability vs immutability
- Immutably updating objects and arrays safely
Avoiding functions and statements that mutate state
Reading List:- Redux Docs: Using the Object Spread Operator
Normalizing Data
Key Concepts:
- Database structure and organization
- Splitting relational/nested data up into separate tables
- Storing a single definition for a given item
- Referring to items by IDs
- Using objects keyed by item IDs as lookup tables, and arrays of IDs to track ordering
Associating items in relationships
Reading List:- Idiomatic Redux: Normalizing the State Shape
- Redux Without Profanity: Normalizr
- Wikipedia: Associative Entity
- Avoiding Accidental Complexity When Structuring Your App State