@dabapps/redux-create-reducer
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

redux-create-reducer

A utility to create redux reducers from a set of handlers

About

This is a fork of @jakesidsmith/redux-create-reducer.

This utility removes the need for switch statements (which can easily result in errors), and instead allows you to create a redux reducer from a set of handler functions - no more need to handle a default case, no more boilerplate.

This library is written in TypeScript and due to how the handlers are typed, allows you to limit which actions they handle, and also define different action types for different handlers without casting their types.

Install

npm i @dabapps/redux-create-reducer -S

Usage

import { createReducer } from '@dabapps/redux-create-reducer';
import { ADD, SUBTRACT, RESET } from './action-types';

interface NumberAction {
  type: string;
  payload: number;
}

export const count = createReducer(
  {
    [ADD]: (state: number, action: NumberAction) => state + action.payload,
    [SUBTRACT]: (state: number, action: NumberAction) => state - action.payload,
    [RESET]: () => 0,
  },
  0 // Initial state (required)
);

Updating this fork from upstream

Ensure you have added a remote upstream in git e.g.

git remote add upstream git@github.com:JakeSidSmith/redux-create-reducer.git

Create a new branch (from master) and run the following to pull changes from upstream:

git fetch upstream
git pull upstream master

Package Sidebar

Install

npm i @dabapps/redux-create-reducer

Weekly Downloads

13

Version

1.1.0

License

MIT

Unpacked Size

12.3 kB

Total Files

18

Last publish

Collaborators

  • dabapps