1.0.4 • Published 5 years ago

reduce-reducers v1.0.4

Weekly downloads
351,110
License
MIT
Repository
github
Last release
5 years ago

reduce-reducers

Build Status npm Version npm Downloads Monthly

Reduce multiple reducers into a single reducer from left to right

Install

npm install reduce-reducers

Usage

import reduceReducers from '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

betslip@grough/set-reduxer-prism-webinsync-stageplayermarin-stageplayernicholas-newman-redux-firestoreskill-f3@infinitebrahmanuniverse/nolb-reduc@everything-registry/sub-chunk-2636angular-reusable-components@arielapaula/components@arielapaula/test@types/reduce-reducers@tappleby/redux-actions@ajp/utils-tsaf-reduxaerial-plagroundaerial-playground@canonical/maas-uibillogram-foundationmanifold.mldatatools-managerlearning_locker@carnesen/redux-sliced@bibletags/bibletags-react-native-appmon-entreprisemodules-packxm-redux-actionswrasse-duck-extendyojji-core-draft@yojji/core@uxland/uxl-redux@signavio/kraken@visma-digital-commerce/pwa-klarnablondie-redux-firestore@dimavedenyapin/redux-firestoreelectron-redux-multi-window-commrrc-loader-helperrnl-vendor-mfernl-vendor-uiredux-firestoreredux-firestore-forkedredux-fetch-helpersredux-restify@gigwalk/backbone-redux@dmartss/actionscrawler.plugins.admincrowdsorcerershimo-sos@insync-stageplayer/annotations@insync-stageplayer/notification@insync-stageplayer/plotly-chartshift-admin-ui-kitshift_commerce-ui-kitshasta@foxcommerce/wingsreact-serverless-auth@flecks/reduxredux-remodelredux-reducer-delegatorredux-changesredux-actionsredux-actions-immutableredux-agentredux-frrredux-fsarealtredux-data-collectionsredux-delegatorredux-forceredux-o-actionsredux-namespacesdwpr-react-scriptsdwprreactscripts2rebuxrabjsoverviewer@kleros/fairdex@jeffbski/redux-utilslim-redux@irvingjs/coretorii-store@near-wallet/frontend@nas-user/tango@nas-user/rumba@lab009/erebus@lab009/teidegatsby-theme-shopify-redux@letapp/redux-actionssyso@meniga/reduxtandemapptandemcode@mouldjs/mould@mlvis/jupyter-manifold@mlvis/manifoldhive-ui@nodata/slideshow-state@nodata/witchart@nodata/witchart-state
1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.4.3

6 years ago

0.4.2

6 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.0

6 years ago

0.2.0

6 years ago

0.1.5

6 years ago

0.1.2

8 years ago

0.1.1

9 years ago

0.1.0

9 years ago