redux-fx

1.0.12 • Public • Published

redux-fx

NPM Version Coverage Status Build Status Downloads Dependency Status License

A library for managing side effects for Redux, inspired by the Elm Architecture.

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

Package Sidebar

Install

npm i redux-fx

Weekly Downloads

0

Version

1.0.12

License

MIT

Last publish

Collaborators

  • doodledood