duck-magic
Utilities for Ducks - Modular Redux
The library is a small set of utilities for managing ducks written to the Ducks Modular Redux design. However, to reduce the boilerplate, the interface for a "duck" when using this library is:
Install
With yarn
:
yarn add duck-magic
With npm
:
npm install --save duck-magic
Example
// ducks/math.jsconst ADD = 'ADD';const SUB = 'SUB'; const reducer = { }; const actions = type: ADD payload: value type: SUB payload: value ; const selectors = state % 2 === 0 state;
Then in your index file:
// ducks/index.js; ; const ducks = math // the rest of your ducks...; const rootReducer = ;const actions = ;const selectors = ;
And finally, in your component:
;; { // ...} const mapState = { value: selectorsmath};const mapDispatch = onAdd: actionsmathadd onSubtract: actionsmathsubtract; mapState mapDispatchCounter;
API
composeActionCreators(ducks, [extraActionCreators])
Given an object containing ducks as values, returns another object whose values are the actions
property of each duck.
composeSelectors(ducks, [extraSelectors])
Given an object containing ducks as values, returns another object whose values are the selectors
property of each duck. The portion of state under the duck's key will be passed to the underlying selector.
createRootReducer(ducks, [extraReducers])
Given an object containing ducks as values, returns a function that is the result of calling Redux's combineReducers
on all the reducer
s.