0.0.9 • Published 3 years ago

@something.technology/redux-connector v0.0.9

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

Redux Connector

Redux connector takes redux actions and transforms it to socket.io messages when criterias (can be passed in SocketConnection constructor) are met. Default is to redirect messages where type starts with @@socket/.

This library is inspired by https://github.com/itaylor/redux-socket.io but is adding also strong TypeScript support.

Setup

Example Setup with Redux Sagas:

configureStore.ts

const socketConnection = new SocketConnection('http://localhost:3000', '/socket');

const configureStore = (): Store<ApplicationState> => {
  const sagaMiddleware = createSagaMiddleware();

  const middlewareToApply: Middleware[] = [
    sagaMiddleware,
    createSocketMiddleware(socketConnection),
  ];

  const store = createStore(rootReducer, applyMiddleware(...middlewareToApply));
  sagaMiddleware.run(rootSaga);
  return store;
};

export default configureStore;

store/socketConnection/sagas.ts

import { put, StrictEffect } from 'redux-saga/effects';
import { actions } from '@something.technology/redux-connector';

export function* initConnection(): Generator<StrictEffect, void, undefined> {
  yield put(actions.openSocketConnection());
}

rootSaga.ts

import { fork, all, StrictEffect } from 'redux-saga/effects';
import * as socketConnectionSagas from './socketConnection/sagas';

export default function* rootSaga(): Generator<StrictEffect, void, undefined> {
  yield all([
    fork(socketConnectionSagas.initConnection),
    // Add additional sagas here
  ]);
}
0.0.9

3 years ago

0.0.8

3 years ago

0.0.7-beta.0

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.1

3 years ago