redux-effects-nes
v1.0.0
Published
Redux effects middleware for Nes
Downloads
4
Maintainers
Readme
Redux Effects Nes
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 socketdisconnect
: (name = 'default') Used to disconnect from the socketof
: (path, name = 'default') Used to create a path event groupon
: (path, eventName, callback, name = 'default') Used to add a event handleremit
: (eventName, dataToSend, callback, name = 'default') Used to send a event back to the serverrequest
: (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.