Helper function to create Redux modules using the ducks-modular-redux proposal.
npm i -S redux-duck
import { createDuck } from 'redux-duck';
const myDuck = createDuck('duck-name', 'application-name');
createDuck
receive 2 arguments, the second argument is optional.const ACTION_TYPE = myDuck.defineType('ACTION_TYPE');
defineType
receive just one argument.application-name/duck-name/ACTION_TYPE
or duck-name/ACTION_TYPE
if the application or module name was not defined.const actionType = myDuck.createAction(ACTION_TYPE);
createAction
receive just one argument.const initialState = {
list: Immutable.List(),
data: Immutable.Map(),
};
const reducer = myDuck.createReducer({
[ACTION_TYPE]: (state, action) => ({
...state,
list: state.list.push(action.payload.id),
data: state.map.set(action.payload.id+'', action.payload),
}),
}, initialState);
createReducer
receive two arguments, both required.