vutran / redux-ipc

Log your Redux state and actions to a node backend via WebSockets.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

redux-ipc

MIT licensed

Log your Redux state and actions to a node backend via WebSockets.

Install

$ npm install --save redux-ipc

Demo

Usage

Apply the middleware when creating your Redux store.

const reduxIpcMiddleware = require('redux-ipc');

const state = {
  todos: [],
};

// apply the middleware
const store = createStore(state, {}, applyMiddleware(reduxIpcMiddleware));

// dispatch actions
// store.dispatch(...);
// store.dispatch(...);
// store.dispatch(...);

Create the server to listen for messages.

const Server = require('redux-ipc').Server;

const PORT = process.env.REDUX_IPC_PORT || 8080;
const PROTOCOL = process.env.REDUX_IPC_PROTOCOL || 'redux-ipc';

// create a new redux ipc server
const wss = new Server({ port: PORT, socketName: PROTOCOL });

// listen to messages
wss.on('message', message => {
  console.log(message);
});

Examples

Run npm install and npm start for each directory in /examples.

Note: Examples are based on the official Redux examples with slight modifications to showcase the IPC functionality.

License

MIT © Vu Tran

About

Log your Redux state and actions to a node backend via WebSockets.

License:MIT License


Languages

Language:JavaScript 100.0%