Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

redux-websocket-action

1.0.5 • Public • Published

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: }

Install

npm i redux-websocket-action

DownloadsWeekly Downloads

3

Version

1.0.5

License

ISC

Last publish

Collaborators

  • avatar