0.1.1 • Published 6 years ago

redux-subs v0.1.1

Weekly downloads
3
License
ISC
Repository
github
Last release
6 years ago

redux-subs

This package implements the declarative Subscriptions pattern seen in the Elm architecture to be used in Redux.

npm install redux-subs

What is a subscription?

const sub = dispatch => {
  // setup and start
  const socket = new Socket()

  // dispatch at will
  socket.on('message', data =>
    dispatch({type: 'MESSAGE', payload: data})
  )

  // return a way to stop
  return () => socket.close()
}

How to declare them?

// declarative subscriptions
const subs = state =>
  state === 'listening' ?
    {socket: sub} :
    {}

How do I start?

import install from 'redux-subs'
import {createStore, applyMiddleware} from 'redux'

const store = createStore(reducer, install(subs))

(: