Install the package with npm
npm i @trixta/phoenix-to-redux
or yarn - whichever you prefer
yarn add @trixta/phoenix-to-redux
/**
* Combine all reducers in this file and export the combined reducers.
*/
import { combineReducers } from 'redux';
import { phoenixReducer } from '@trixta/phoenix-to-redux';
export default function createReducer() {
const rootReducer = combineReducers({
phoenix: phoenixReducer,
});
return rootReducer;
}
See example to setup middleware
import { configureStore, getDefaultMiddleware } from '@reduxjs/toolkit';
import { createPhoenixChannelMiddleware } from '@trixta/phoenix-to-redux';
import createSagaMiddleware from 'redux-saga';
import rootSaga from './rootSaga';
import createReducer from './reducers';
export default function configureStore(initialState = {}) {
const reduxSagaMonitorOptions = {};
// Makes redux connected to phoenix channels
const phoenixChannelMiddleWare = createPhoenixChannelMiddleware();
const sagaMiddleware = createSagaMiddleware(reduxSagaMonitorOptions);
const middlewares = [sagaMiddleware,phoenixChannelMiddleWare];
const enhancers = [];
const store = configureStore({
reducer: createReducer(),
middleware: [
...getDefaultMiddleware({
thunk: false,
immutableCheck: {
ignore: ['socket', 'channel', 'trixta', 'phoenix', 'router'],
},
serializableCheck: false,
}),
...middlewares,
],
devTools:
/* istanbul ignore next line */
process.env.NODE_ENV !== 'production' ||
process.env.PUBLIC_URL.length > 0,
enhancers,
});
sagaMiddleware.run(rootSaga);
return store;
}
import { put } from 'redux-saga/effects';
import { connectPhoenix } from '@trixta/phoenix-to-redux';
// update login details
yield put(connectPhoenix({ domainUrl: 'localhost:4000', params : { token:'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmF6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c',agentId: '[email protected]'} }));
To communicate with phoenix socket you can make use of the following dispatch methods
This project is licensed under the MIT license, Copyright (c) 2020 Trixta Inc. For more information see LICENSE.md
.