1.0.4 • Published 6 years ago

reduce-reducers v1.0.4

Weekly downloads
351,110
License
MIT
Repository
github
Last release
6 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-2636tandemapptandemcodesysowrasse-duck-extendxm-redux-actions@dimavedenyapin/redux-firestore@dmartss/actions@canonical/maas-ui@rtobon/rumba@rtobon/tangoiqvia-sharedirvingui-modules-packtorii-store@arielapaula/components@arielapaula/test@ajp/utils-ts@bibletags/bibletags-react-native-app@carnesen/redux-slicedyojji-core-draft@flecks/redux@foxcommerce/wings@gigwalk/backbone-redux@lab009/erebus@lab009/teide@letapp/redux-actions@insync-stageplayer/annotations@insync-stageplayer/notification@insync-stageplayer/plotly-chart@irvingjs/core@mouldjs/mould@near-wallet/frontend@nas-user/rumba@nas-user/tango@nodata/slideshow-state@nodata/witchart@nodata/witchart-state@nodata/descriptor@nodata/reactive-widget-state@nodata/redux-utils@metabase/embedding-sdk-react@meniga/redux@mlvis/jupyter-manifold@mlvis/manifold@kleros/fairdex@jeffbski/redux-util@quoine/core@recital/recital@ricardo-tobon/rumba@ricardo-tobon/tangomon-entreprisemodules-packoverviewerrrc-loader-helperredux-changesredux-frrredux-fsaredux-restifyredux-delegatorredux-o-actionsredux-actions-immutableredux-actionsredux-data-collectionsredux-namespacesredux-agentredux-firestoreredux-firestore-forkedredux-fetch-helpersredux-forceredux-reducer-delegatorredux-remodelrabjsrebuxrealtrnl-vendor-mfernl-vendor-uireact-serverless-authshift_commerce-ui-kitshift-admin-ui-kitshimo-sosshastaslim-reduxhive-uilearning_lockermanifold.ml@types/reduce-reducers@thiva/admin.api-resources.v1@thiva/admin.api-resources.v2@thiva/admin.application-roles.v1@thiva/admin.applications.v1@thiva/admin.authentication-flow-builder.v1
1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.4.3

7 years ago

0.4.2

7 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.0

7 years ago

0.2.0

7 years ago

0.1.5

7 years ago

0.1.2

9 years ago

0.1.1

10 years ago

0.1.0

10 years ago