prosciutto
v2.1.1
Published
Functor based redux side effects
Downloads
11
Maintainers
Readme
🥓 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))
)