0.0.1 • Published 6 years ago

@malfaitrobin/redux-one-of-types v0.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

oneOfType npm version npm downloads

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
);