0.2.1 • Published 9 years ago
redux-middlewares v0.2.1
redux-middlewares
A library to create middlewares.
It fits to prototyping or small projects.
Install
$ npm install -S redux-middlewaresLinks and recipes
API
- composeMiddleware(...middlewares)
- createMiddleware(...matchers, callback)
- createAsyncHook(...matchers, callback)
- createFilter(...matchers, filter)
- createTransformer(...matchers, transformer)
- createReplacer(...matchers, replacer)
composeMiddleware(...middlewares)
It works like Redux's applyMiddleware but returns a middleware instead of a store enhancer.
createMiddleware(...matchers, callback)
Calls the given callback only an action is matched to all matchers.
By caching, it does not call store.getState more than once at matching.
All other create* functions use this function internally.
matcherstring | array | ({action, getState}) => boolean- string An action type to match
- array An array of action types to match
- ({action, getState}) => boolean A function returns true if matched
callback({getState, dispatch, nextDispatch, action}) => any
createAsyncHook(...matchers, callback)
Calls the given callback asynchronously.
Asynchronous version of createMiddleware.
It calls nextDispatch immediately.
matcherstring | array | ({action, getState}) => boolean- string An action type to match
- array An array of action types to match
- ({action, getState}) => boolean A function returns true if matched
callback({getState, dispatch, action}) => any
createFilter(...matchers, filter)
Filters actions.
It calls nextDispatch if the filter returns true.
filter({action, getState}) => boolean
createTransformer(...matchers, transformer)
Transforms an action in the middleware layer.
transformer({action, getState}) => action
createReplacer(...matchers, replacer)
Discards an action and dispatch a new one.
replacer({action, getState}) => action