reducer-generator-wildcard
v1.1.0
Published
A redux reducer-generator which builds a redux-reducer which matches against wildcards.
Downloads
7
Maintainers
Readme
reducer-generator-wildcard
A reducer-generator
which builds a redux-reducer which matches against wildcard types.
Under the hood this utilizes our package wildcard-utils which allows us to match strings against objects of wildcards.
Installation
yarn add reducer-generator-wildcard
or
npm install --save reducer-generator-wildcard
Simple Example
import createWildcardReducer from 'reducer-generator-wildcard'
// match any types that start with SYSTEM
const system = createWildcardReducer(
{ /* initial state */ },
{
// match any types that begin with SYSTEM
'SYSTEM*': (state, { type, ...action }) => ({
...state,
isOnline: action.isOnline !== undefined
? action.isOnline
: state.isOnline,
}),
},
/* You may pass extra args that will be passed to the reducer(s) */
)