redux-generic
Dumb, hence generic, action creators and reducers. You provide them with a payload, they update the state accordingly without additional thoughts. This makes sense assuming that the business intelligence is implemented in middlewares, e.g. thunks.
redux-generic
provides you with utilities for updating three kinds of states: states made of one single value, states made of one single object and states made of a collection of objects (more specifically a set of objects indexed by an identifier).
Installation
npm i -S redux-generic
Usage: single value
The basic approach with Redux would be to implement the business logic in the reducer. Here, we'll assume it is implemented elsewhere, so that the updated value is provided as an argument of the action creator:
;; const counterDomain = ;const store = ;const incrementCounter = counterDomain;store;
Usage: single object
Same thing, but the state is now an object, and the reducers knows how to update it partially.
;; const counterDomain = ;const store = ;const updateFirstName = counterDomainactionCreators;store;
Usage: collections
Managing collections is a major concern when working with a normalized state. This approach is very well described in the following articles:
- https://redux.js.org/recipes/structuring-reducers/normalizing-state-shape
- https://hackernoon.com/shape-your-redux-store-like-your-database-98faa4754fd5
;; const userDomain = ;const store = ;const insertUserAction = userDomainactionCreators;store;
redux-crud
is an interesting concurrent implementation, though redux-generic
probably covers a wider range of use cases. redux-generic
is an implementation of dumb reducers, while redux-crud
is a solution for the sub-problem of state normalization.