redux-websocket-action
v1.0.5
Published
Call action via websocket<br> based on <a href="https://www.npmjs.com/package/ws-reconnect" target="_blank">ws-recconect</a>
Downloads
7
Maintainers
Readme
redux-websocket-action
Call action via websocket based on ws-recconect
Introduction
Execute a Action that returned from ws. This package will give you the way to dispatch actions with redux via frpm server websocket to ll the users.
Quick start
install
$ npm install --save redux-websocket-action
Start websocket actions on your index.js right before rendering the react DOM
...
import WSAction from 'redux-websocket-action';
/* -------- create the store with middleware ---------- */
const createStoreWithMiddleware = applyMiddleware()(createStore);
const store = createStoreWithMiddleware(reducers);
/* -------- !!!! turn on WS Actions !!!! ---------- */
const wsAction = new WSAction(store, 'ws://localhost:3030', {
retryCount:3,
reconnectInterval: 3
});
wsAction.start();
/* -------- render application ---------- */
ReactDOM.render(
<Provider store={store}>
<Router history={browserHistory} >
{routes}
</Router>
</Provider>
, document.querySelector('.container'));
Call to your actions from you server. you need to send to clients via the ws the following json:
{
"WS_ACTION": true,
"action": action
}
WS_ACTION - indicate to the package to try to fire the action. action - a redux action object ( type and payload ) for example: { type: "UPDATE_POSTS", payload: }