0.0.1-security.4 • Published 1 year ago

redux-typescript-module v0.0.1-security.4

Weekly downloads
4
License
-
Repository
-
Last release
1 year ago

Specify reducer and action creators in one swoop. A single function that returns a reducer and action creators. Based on redux-create-module.

Installation

npm install --save redux-typescript-module or yarn add redux-typescript-module

API

There's just one function: createModule(initalState, handler) -> {reducer, actions}

Parameters

initialState is the initial state for the module.

handler is an object where the keys are action names and the values are action handlers. For example:

const counter = createModule(0, {
  increment: (state: number, action: Action<number>) => state + action.payload,
  decrement: (state: number, action: Action<number>) => state - action.payload
})

Returns

createModule returns an object with two things:

actions is an object with action creators. for example: counter.actions.increment(5) will return { type: 'increment', payload: 5 }

reducer is regular reducer that you can pass to the redux store or to combineReducers