redux-reducer-async
Create redux reducers for async behaviors of multiple actions.
Be DRY & reduce boilerplate. Standardize state schema with managed properties for loading, success, and error cases.
Think of it as redux-actions
for asynchronous reducers.
Works with Flux Standard Actions (FSA).
By default, supports the action type conventions of redux-promise-middleware
,
but see Custom Action Types below for configuration to support redux-promise
.
Install
Use
const myActionReducer =
results in a reducer like this:
{ }
You can then mount it with combineReducers
:
const rootReducer =
Or even call it manually within another reducer (useful with custom properties or reducers):
const myActionReducer = const reducer = { state = // ... return state}
Custom Properties
You can provide custom property names (all optional) for each case to be used on the state:
Custom Reducers
You can also provide custom reducer functions (again all optional, but be careful to define all cases if you use non-standard property names in one):
And you can even mix these with custom properties:
Custom Action Types
You can provide custom action types.
For example, to support redux-promise
, which uses same the action type for success and error cases (though it does not provide a loading action),
you can use finalActionType
:
which is effectively like providing custom action types:
Or similarly by passing suffixes to the actionTypes
helper,
which is normally used to explicitly define all types:
But can also be used to suppress suffixes (here undefined means use default):
Transforms
As a shortcut to defining custom reducers, you can provide transform functions to manipulate only the payload, optionally in success and/or error cases: