prosciutto

2.1.1 • Public • Published

npm PRs Welcome Open Source Love License

🥓 Prosciutto

Functor based redux side effects

Alternative to rxjs and redux-observable, or meaball

Install

yarn add prosciutto

Usage examples

Listen to any redux action, perform side effect, dispatch new redux actions

// epics.js
import { searchResponse, seachError, clearSidebar } from './reducer'

// Simple example
const simpleEpic = is => is('SUBMIT_SEARCH')
  .map(({payload, store, dispatch}) => fetch(payload)
    .then(res => res.json())
    .then(json => dispatch(searchResponse(json)))
    .catch(e => dispatch(seachError(e))))

// Dispatch multiple actions with an array
const multipleEpic = is => is('SUBMIT_SEARCH')
  .map(({payload, store, dispatch}) => fetch(payload)
    .then(res => res.json())
    .then(json => dispatch([searchResponse(json), clearSidebar()]))
    .catch(e => dispatch(seachError(e)))
  )

export default [simpleEpic, multipleEpic]

// index.js
import prosciutto from 'prosciutto'
import epics from './epics'

const store = createStore(
  reducers,
  applyMiddleware(prosciutto(epics))
)

Dependencies (0)

    Dev Dependencies (4)

    Package Sidebar

    Install

    npm i prosciutto

    Weekly Downloads

    2

    Version

    2.1.1

    License

    Apache-2.0

    Unpacked Size

    17 kB

    Total Files

    8

    Last publish

    Collaborators

    • rametta