redux-callback-reducer
redux-callback-reducer allows any function or class method to make a reducer for your state, without adding any additional actions.
Installation
npm install --save redux-callback-reducer
Tutorial
To use redux-callback-reducer
you need to configure your state using generateReducers
or createCallbackReducer
, prepare a decorator or wrapper function, and make your functions as state reducer.
To use the decorator you need to configure babel-plugin-transform-decorators-legacy
Configure state
You can use generateReducers
to generate a nested state or generate your state using combineReducers
from redux
and createCallbackReducer
from redux-callback-reducer
- Using
generateReducers
:
; const rootReducer = ;
- Using
combineReducers
andcreateCallbackReducer
:
; const rootReducer = ;
- You can create a flat state using
createCallbackReducer
:
; const rootReducer = ;
Creating a wrapper or decorator
You need to create a wrapper for functions or decorator for methods.
- Wrapper:
;; const wrapper = ;
- Decorator:
;; const reducer = ;
Using wrapper or decorator:
- Wrapper:
; const setAdmins = ; const getAdmins = ;
- Decorator:
; static { return ; } @ static { return users; }
- If you do not create nested state, you can write a reducer as follows:
; static { return ; } @ static { return ...state items ; }
Example
- example - basic reference implementation