New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

react-redux-websocket

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-redux-websocket

redux-middleware send actions through a websocket and dispatch received messages

latest
Source
npmnpm
Version
1.0.3
Version published
Maintainers
1
Created
Source

React-Redux-Websocket

A websocket Middleware

What it does?

This middleware send and receive actions from a server, dispatching as needed

const FOO = 'FOO';

function Bar() {
    return {
        type: FOO,
        payload: "Receive this"
        socket: {
            send: true
        }
    };
}

Installation and Usage

Installing

npm install react-redux-websocket

Then you create the socket and use ApplyMiddleware

import {createStore, applyMiddleware} from 'redux';
import reduxWebsocket from 'react-redux-websocket';

const socket = new WebSocket('ws://localhost:3030');
const store = createStore(rootReducer, applyMiddleware(reduxWebsocket(socket)));

Receiving actions

Any action received through the websocket will be dispatched and handled normally, so your reducers should handle them.

Dispatching actions

To send actions through the socket you need the special object socket with the key send set to true

const FOO = 'FOO';

function Bar() {
    return {
        type: FOO,
        payload: "Receive this"
        socket: {
            send: true
        }
    };
}

Configuration

The socket object has some properties that you can use, currently those properties are: send, keepSocket and silent.

const FOO = 'FOO';

function Bar() {
    return {
        type: FOO,
        socket: {
            send: true, // The action will be send through the socket, default: false
            keepSocket: false, // If false, the socket object will be removed after send, default: false
            silent: false // If true, it will not raise erros if fail to send, default: false
        }
    };
}

Test

run

npm test

License

react-redux-websocket is free and unencumbered software released into the public domain. See UNLICENSE for details.

Keywords

redux

FAQs

Package last updated on 31 Jan 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts