0.1.3 • Published 4 years ago

yarbr v0.1.3

Weekly downloads
3
License
ISC
Repository
github
Last release
4 years ago

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 by myCustomFunction
      • myModule.namespace - a namespace to use when using redux's combineReducers
      • 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.

Develop this project

Run tests

npm test

Build

npm run build

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago