Home

Awesome

redux-duck

CI Status Publish Status Dependabot Status Maintainability Test Coverage license releases npm version dependencies

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

Installation

yarn add 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, false);

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