redux-subs
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

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

(:

Package Sidebar

Install

npm i redux-subs

Weekly Downloads

1

Version

0.1.1

License

ISC

Last publish

Collaborators

  • lsunsi