0.4.4 • Published 6 years ago

redux-socket-dispatch v0.4.4

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

redux-socket-dispatch

The goal of this package is to:

  1. send dispatched actions through a websocket so that they can be handled on a server;
  2. locally dispatch remotely emitted actions.

how to install

$ npm install --save redux-socket-dispatch

how to use it

In order to dispatch an action through a websocket, pass the instance to the store enhancer provided by the library.

// ON THE CLIENT

import socketDispatchEnhancer from "redux-socket-dispatch"
// or const socketDispatchEnhancer = require("redux-socket-dispatch")

import openSocket from 'socket-io.client'
const socket = openSocket(process.env.ENDPOINT)

const store = createStore(
  reducers,
  compose(
    applyMiddleware(...middlewares),
    socketDispatchEnhancer(socket, 'REMOTELY_EMITTED_EVENT')
  )
)

To dispatch through redux, actions sent via the websocket by the server, you have to give the socket event name as the second argument of the store enhancer.

// ON THE SERVER

const socket = require('socket.io').listen(process.env.PORT)

socket.on('connection', client => {
  const action = { type: 'CONNECTED' }
  client.emit('REMOTELY_EMITTED_EVENT', action)
})
0.4.4

6 years ago

0.4.3

6 years ago

0.4.2

6 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.4

6 years ago

0.3.3

6 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago