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@canonical/maas-uiiqvia-sharedirvinghive-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@thiva/admin.authentication.v1@thiva/admin.authorization.v1@thiva/admin.branding.ai.v1@thiva/admin.certificates.v1@thiva/admin.console-settings.v1@thiva/admin.email-providers.v1@thiva/admin.branding.v1@thiva/admin.claims.v1@thiva/admin.connections.v1@thiva/admin.core.v1@thiva/admin.email-management.v1@thiva/admin.email-templates.v1@thiva/admin.extensions.v1@thiva/admin.extensions.v2@thiva/admin.groups.v1@thiva/admin.identity-providers.v1@thiva/admin.identity-verification-providers.v1@thiva/admin.layouts.v1@thiva/admin.login-flow.ai.v1@thiva/admin.oidc-scopes.v1@thiva/admin.org-insights.v1@thiva/admin.organization-discovery.v1@thiva/admin.organizations.v1@thiva/admin.parent-roles.v1@thiva/admin.private-key-jwt.v1@thiva/admin.provisioning.v1@thiva/admin.remote-repository-configuration.v1@thiva/admin.roles.v1@thiva/admin.roles.v2@thiva/admin.saml2-configuration.v1@thiva/admin.secrets.v1@thiva/admin.server-configurations.v1@thiva/admin.server.v1@thiva/admin.session-management.v1@thiva/admin.sms-providers.v1@thiva/admin.tenants.v1@thiva/admin.userstores.v1@thiva/admin.validation.v1@thiva/admin.views.v1@thiva/admin.workflow-approvals.v1@thiva/admin.wsfed-configuration.v1@thiva/common.ai.v1@thiva/admin.users.v1@uxland/uxl-redux@visma-digital-commerce/pwa-klarna@yojji/coreangular-reusable-componentsaf-reduxaerial-plagroundaerial-playground@ajp/utils-tsui-modules-packtorii-store@bibletags/bibletags-react-native-app@carnesen/redux-slicedyojji-core-draft@gigwalk/backbone-redux@lab009/erebus@lab009/teide@letapp/redux-actions@mouldjs/mould@near-wallet/frontend@nas-user/rumba@nas-user/tangomon-entreprisemodules-packoverviewerrrc-loader-helperredux-changesredux-frrredux-fsaredux-restifyredux-delegatorredux-o-actions
1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

7 years ago

1.0.0

7 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

8 years ago

0.1.5

8 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago