Home

Awesome

redux-io

build status npm version

FSA-compliant io monad middleware for Redux.

This is based on redux-future.

npm install --save redux-io

Usage

import ioMiddleware from 'redux-io';
const createStoreWithMiddleware = applyMiddleware(
  ioMiddleware('runIO') // <- function name of the function to run the IO.
)(createStore)

Example

import { IO } from 'ramda-fantasy';

const io = IO(() => {
  document.title = "Goodbye World!";
  return { type: 'INCREMENT' };
});
store.dispatch(io);

Using in combination with redux-actions

Because it supports FSA actions, you can use redux-io in combination with redux-actions.

Example: Action creators

const io = IO(() => location.href);

const action = createAction('FSA_ACTION');
store.dispatch(action(R.map(R.toUpper, io)));

Example: Future(IO)

You can use redux-io together with redux-future.

// futureIo :: Future(IO(String))
const futureIo = new Future((rej, res) => {
  const io = IO(() => location.href);

  setTimeout(() => res(io), 2000);
});

const action = createAction('FSA_ACTION');
store.dispatch(action(futureIo));

Related

What's an IO?

Libraries