0.1.3 • Published 4 years ago
yarbr v0.1.3
Yarbr
Yet another Redux boilerplate reducer.
A tiny library to reduce boilerplate when writing redux reducers, actions, action creators.
Yarbr provides a base module class, and a set of decorator functions.
Install in your project:
npm install yarbr
Use in your app:
- Example, see how class and helpers are used
- Example, see how it's used with react
Example, if you don't like clicking links, see below:
import {ActionCreator} from 'redux'; import {YarbrModule, actionReducer} from 'yarbr'; const initialState = {}; class MyModule extends YarbrModule { public get namespace(): { return 'myReduxStateNamespace'; } @actionReducer public myCustomFunction(state, action) {...} } type MyModuleType = { actionCreators: { myCustomFunction: ActionCreator; }; reducer(state, action): Exclude<any, undefined>; namespace: string; types: { myCustomFunction: string; }; } const myModule: MyModuleType = new MyModule(initialState);
- The
myModule
class instance has this interface:myModule.actionCreators.myCustomFunction
- an action creator function that creates a FSA (Flus Standard Action)myModule.reducer
- a reducer function that integrates the original function defined bymyCustomFunction
myModule.namespace
- a namespace to use when using redux'scombineReducers
myModule.types.myCustomFunction
- a type string used by the corresponding action creator, useful for tests or advanced usage.- (advanced usage)
myModule.reducerMap
- add your own reducer to this object to allow the module's reducer to handle a one-off action from somewhere else.
- The
Develop this project
- install npm https://nodejs.org/en/
- install npx
npm install -g npx
Run tests
npm test
Build
npm run build