redux-fun 🔧
Redux functional programming utilities
Install
$ npm install --save redux-fun
Documentation
Reducers
Compose reducers
const composeReducers pipeReducers = ; const reducer_1 = ; const reducer_2 = ;
Convert updaters
const toReducer = ;const updater = state;const reducer = ;
Updaters
updater with initial state
const withDefaultState = ; // normalconst updater_1 = ; // curriedconst updater_2 = state;
Middlewares
Compose middlewares
const composeMiddlewares pipeMiddlewares = ; const middleware_1 = ; const middleware_2 = ;
Preserve async flow (deprecated)
Use preserveAsyncSeries instead
Preserve async series
Respect the dispatch order with async middleware
const preserveAsyncSeries = ; const middleware_1 = const middleware_2 =
Handlers
A Handler from the handle-io library can be tranformed into redux middleware using createHandleIOMiddleware function.
Redux Handlers
A redux handler
run every time an action was dispatched.
It takes two arguments:
- action
- reduxHandleIOApi
The reduxHandleIOApi object provides 3 IOs functions :
- getState
- dispatch
- next
Please see handle-io documentation for more details.
e.g.
const io handler = ; const sleep = ; // delayed action exampleconst myHandler1 = ; // preserve dispatch orderconst myHandler2 = ; // print stateconst log = ;const myHandler3 =
Note: A redux handler
acts as an async middleware.
testReduxHandler
testReduxHandler
is an extension of handle-io#testHandler
it adds 3 match*() methods:
- .matchNext() - 2 arguments:
- next argument (assert)
- next return (mock)
- .matchDispatch() - 2 arguments:
- dispatch argument (assert)
- dispatch return (mock)
- .matchGetState() - 1 argument:
- getState return (mock)
e.g.
const handler = ;const testReduxHandler = ; const createDummyAction = { type: 'DUMMY_ACTION' payload }const myAction = type: 'MY_ACTION' payload: {} ; const myHandler4 =
createHandleIOMiddleware
usage:
const createHandleIOMiddleware = ;const handleIOMiddleware =
Selectors
Bind selectors
const bindSelectors = ; const selectors = stateusers stateusersid const boundSelectors = ; const user = boundSelectors;
getOwnProp
getOwnProp
is very useful to use with createSelector from reselect
const createSelector = ;const getOwnProp = ; const getUsers = stateusers || {} const getUserByName = ; // => true