Skip to content

🥓 Functor based redux side effects

License

Notifications You must be signed in to change notification settings

rametta/prosciutto

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

🥓 Functor based redux side effects

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •