JSPM

redux-either

0.1.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q26854F
  • License MIT

FSA-compliant either monad middleware for redux

Package Exports

  • redux-either

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (redux-either) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

redux-either

build status npm version

FSA-compliant either monad middleware for Redux.

This is based on redux-future.

npm install --save redux-either

Usage

import eitherMiddleware from 'redux-either';
import { Either } from 'ramda-fantasy';
const createStoreWithMiddleware = applyMiddleware(
  eitherMiddleware( Either // the Either instance
                  , Either.either // function to get the value from the Either
)(createStore)

// with data.either from folktale
import eitherMiddleware from 'redux-either';
import { Either } from 'ramda-fantasy';
const createStoreWithMiddleware = applyMiddleware(
  eitherMiddleware( Either
                  , (l, r, e) => e.fold(l, r)
                  )
)(createStore)

Example

import Either from 'data.either';

store.dispatch({
  type: 'ADD'
, either: Either.Right(2) // <= none FSA needs the either keyword
});

Using in combination with redux-actions

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

Example: Action creators

const action = createAction('FSA_ACTION');
store.dispatch(action(R.map(R.toUpper, Either.Right('test'))));
// => payload will be 'TEST'

store.dispatch(action(R.map(R.toUpper, Either.Left('error'))));
// => error will be 'error'

Example: Future(Either)

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

// futureEither :: Future(Either(String))
const futureEither = new Future((reject, resolve) => {
  fetch('users', (err, res) =>
    err
      ? reject(err)
      : res.length <= 0
        ? resolve(Either.Left('no users found'))
        : resolve(Either.Right(res)));
});

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

What's an Either?

Libraries