Skip to content

Zalastax/redux-typescript-module

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published