1.0.0 • Published 8 years ago
redux-effects-nes v1.0.0
Redux Effects Nes
Redux effects Nes Middleware
Install
npm i -S redux-effects-nesyarn add redux-effects-nesUsage
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.
1.0.0
8 years ago