redux-effects-nes

1.0.0 • Public • Published

Redux Effects Nes

Downloads Downloads NPM Version Dependencies Dev Dependencies License

Redux effects Nes Middleware

Install

npm i -S redux-effects-nes
yarn add redux-effects-nes

Usage

Setup

This requires a publish on the Hapi side with a object structured like so. { event: 'eventName', data: {} }

import { createStore, combineReducers, applyMiddleware, compose } from 'redux';
import createSocket from 'redux-effects-nes';
import effects from 'redux-effects';

...

const middlewareList = [
  effects,
  createSocket()
];

const enhancer = composeEnhancers(applyMiddleware(...middlewareList));

Dispatch

import { connect, on } from 'redux-effects-nes';

...

dispatch(connect(socketurl, cb, authHeaders, 'wss'));
dispatch(on('/path', 'eventName', (res) => {
  // Get the res data
}));
dispatch(emit('/path', 'eventName', (res) => {
  // Get the res data
}));
dispatch(emit('someEventName', someDataObject, () => {}));
dispatch(connect(socketurl, cb, authHeaders, 'wss'));

Available methods

  • connect : (socketUrl, callback, headerObject, protocal = 'ws', name = 'default') Used to connect to the socket
  • disconnect : (name = 'default') Used to disconnect from the socket
  • of : (path, name = 'default') Used to create a path event group
  • on : (path, eventName, callback, name = 'default') Used to add a event handler
  • emit : (eventName, dataToSend, callback, name = 'default') Used to send a event back to the server
  • request: (path, callback, options, name = 'default') Used to make a nes request

The name used in connect creates a socket connection assigned to that name. This allows you make multiple connections and reference them.

Package Sidebar

Install

npm i redux-effects-nes

Weekly Downloads

3

Version

1.0.0

License

MIT

Last publish

Collaborators

  • jcgertig