Home

Awesome

redux-duck

Helper function to create Redux modules using the ducks-modular-redux proposal.

Installation

npm i -S redux-duck

API

Create duck

import { createDuck } from 'redux-duck';

const myDuck = createDuck('duck-name', 'application-name');

Define action types

const ACTION_TYPE = myDuck.defineType('ACTION_TYPE');

Create action creators

const actionType = myDuck.createAction(ACTION_TYPE);

Create reducer

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);