redux-fx
v1.0.12
Published
A library for managing side effect for Redux, inspired by the Elm Architecture.
Downloads
8
Maintainers
Readme
redux-fx
Install
npm install redux-fx
Usage
import {enhanceStoreWithEffects, fx} from "redux-fx"
...
// Decorate createStore with enhanceStoreWithEffects to enable support for effects
// NOTE: the enhancer HAS to come last in order for other enhancers to work
const createStoreWithMiddleware = compose(
applyMiddleware(someMiddleware),
devTools(),
enhanceStoreWithEffects()
)(createStore);
...
// Create effects of signature (any) => (dispatch, getState) => (any)
const incrementWithDelay = seconds => dispatch => setTimeout(() => dispatch({type: "INCREMENT"}), seconds * 1000);
...
// Return a [state,effect] tuple to create effect descriptors that are fully testable.
const reducer = (state, action) => {
switch (action.type) {
case "INCREMENT":
return [{count: state.count + 1}, fx(incrementWithDelay, 1)];
case "DECREMENT":
return {count: state.count - 1};
default:
return state;
}
};
License
MIT © doodledood