redux-less
write a redux reducer with less code, inspired by mirror
install
npm install redux-less
online
example;const store = // ...// you can use "store.replaceReducer" and "combineReducers" to apply this reducerconst reducer = // for react-redux, binding to container todoList: statereducerkey // reducer.key == "todo" reduceractions { // reducer.actions is an actionCreators map return <div> /* ... */ <button onClick= props>add</button> </div> }
API
// or using an umd version with global namespace: `ReduxLess`const getReducer = ReduxLessgetReducer
-
getReducer(model: object): function
get the reducer function, you can see the example above, it is quite clear
the model containskey
as the reducer key andinitialState
as thestate[key]
initial value
other properties in model must be reducer function -
reduxLessMiddleware
you must apply "reduxLessMiddleware" to your store
-
reduxLessMiddlewareWithListener(listener: function)
if you want to listen any action, you can call this api
listener is a function with the action as param
if listener returns false, then the action will not be dispatched
-
getActionType(reducerKey: string, reducerName: string): string
get the action.type by reducer key and reducer function name
license
MIT