react-redux-stream
Streams a singleton redux state selector to one or more contexts (components or objects) within a react-redux application.
Install
npm install -S react-redux-stream
Usage
lib/redux/streams/api.js - Create a singleton streaming api context containing all react-redux bindings.
import Stream from 'react-redux-stream'import createAction from 'redux-actions'import createSelector from 'reselect' const fetchAction = /** Creates singleton streaming api context that houses all react-redux interaction (getState / dispatch) */ 'api'
lib/redux/store/subscribe.js - Attach streams to store (observes and publishes redux state changes)
import api from '../streams/api' = { const detach = api }
lib/components/Users.js - Opt-in a component to stream api context
import React Component from 'react'import api from '../redux/streams/api' { api } { /** Dispatch action to fetch users */ thisapiusers } { return <div> <h2>Users</h2> <ul> /** Map users from redux to api */ thisapi </ul> </div> }
with react-stamp
lib/components/Users.js - Works very well with react-stamp
import React from 'react'import reactStamp from 'react-stamp'import api from '../redux/streams/api' const compose = /** Centralize as component mix-in */const desc = api: descapi displayName: 'Users' { /** Dispatch action to fetch users */ thisapiusers } { return <div> <h2>Users</h2> <ul> /** Map users from redux to api */ thisapi </ul> </div> }