@malfaitrobin/redux-one-of-types
v0.0.1
Published
Redux utilities
Downloads
2
Readme
oneOfType
Handle multiple types with the same reducer function.
Installation
With yarn
:
yarn install @malfaitrobin/redux-one-of-types
With npm
:
npm install --save @malfaitrobin/redux-one-of-types
Usage
import { createReducerCreator } from "@malfaitrobin/redux";
import { oneOfTypesMiddleware, oneOf } from "@malfaitrobin/redux-one-of-types";
const createReducer = createReducerCreator(
oneOfTypesMiddleware /* ...other middleware */
);
const defaultState = {
value: 0
};
const reducer = createReducer(
{
// This method will be executed whenever an action with { type: 'FOO' } or { type: 'BAR' } is dispatched.
[oneOf("FOO", "BAR")]: (state, action) => {
return state;
}
},
defaultState
);