@elastik/reduce-reducers
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

@elastik/reduce-reducers

Build Status npm Version npm Downloads Monthly

Reduce multiple reducers into a single reducer from left to right

NOTE

This is a fork of reduce-reducers, simply with the dependabot updates merged, and republished as @elastik/reduce-reducers

Install

npm install @elastik/reduce-reducers

Usage

import reduceReducers from '@elastik/reduce-reducers';

const initialState = { A: 0, B: 0 };

const addReducer = (state, payload) => ({ ...state, A: state.A + payload });
const multReducer = (state, payload) => ({ ...state, B: state.B * payload });

const reducer = reduceReducers(initialState, addReducer, multReducer);

const state = { A: 1, B: 2 };
const payload = 3;

reducer(state, payload); // { A: 4, B: 6 }

FAQ

Why?

Originally created to combine multiple Redux reducers that correspond to different actions (e.g. like this). Technically works with any reducer, not just with Redux, though I don't know of any other use cases.

What is the difference between reduceReducers and combineReducers?

This StackOverflow post explains it very well: https://stackoverflow.com/a/44371190/5741172

Readme

Keywords

Package Sidebar

Install

npm i @elastik/reduce-reducers

Weekly Downloads

0

Version

1.0.5

License

MIT

Unpacked Size

7.38 kB

Total Files

6

Last publish

Collaborators

  • diego.loaiza
  • cunneen