npm.io
1.0.12 • Published 10 years ago

redux-fx

Licence
MIT
Version
1.0.12
Deps
2
Vulns
0
Weekly
0
Stars
4

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

Keywords