prosciutto

Functor based redux side effects

Usage no npm install needed!

<script type="module">
  import prosciutto from 'https://cdn.skypack.dev/prosciutto';
</script>

README

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))
)