reducer-sandbox
reducer-sandbox
helps you to reuse your redux
reducers in different place without conflict them.
Getting started
Install reducer-sandbox
using npm:
npm install reducer-sandbox --save
Then using ES6
;; const sandbox = ;
Using ES5
var counterReducer = ;var reducerSandbox = ; var sandbox = ;
Usage
Take this piece of code:
;; const reducers = redux;const store = reducer;
This will increment both counter from statsCounter
and itemsCounter
:
store;store; //=> {statsCounter: {counter: 1}, itemsCounter: {counter: 1}}
If you want to only increment statsCounter
, then you can reducer-sandbox
.
Let's do it:
;;; const statsCounter = ;const itemsCounter = ; const reducers = redux;const store = reducer; store; //=> {statsCounter: {counter: 0}, itemsCounter: {counter: 0}}
Now if you want to only increment statsCounter
, you have 4 choices.
- First is using
bindToAction
helper:
store;store; //=> {statsCounter: {counter: 1}, itemsCounter: {counter: 0}}
- Second is using
dispatcher
helper:
const dispatchStatsCounter = statsCounter; ;store; //=> {statsCounter: {counter: 2}, itemsCounter: {counter: 0}}
- Third is using
bindToActionCreator
helper:
const increment = {type: 'INCREMENT'};const statsIncrement = statsCounter; store;store; //=> {statsCounter: {counter: 3}, itemsCounter: {counter: 0}}
- Fourth is using
bindToActionCreators
helper:
const actions = {type: 'INCREMENT'} {type: 'DECREMENT'};const statsActions = statsCounter; store;store; //=> {statsCounter: {counter: 4}, itemsCounter: {counter: 0}}
Examples
Links
renum
is a small library to create enum using frozen objects in javascript from multiple sources.reducer-chain
helps you to chainredux
reducers with given state and action, then keep last updated state.reducer-pipe
helps you to piperedux
reducers with given state and action, passing previously returned state to next reducer, then keep last updated state.