mirror of
https://github.com/status-im/subspace-docs.git
synced 2025-02-12 12:37:39 +00:00
1.0 KiB
1.0 KiB
redux-observables
Phoenix can be configured in epics created with redux-observables. It's recommended to compose these epics by using mergeMap or switchMap operators
import {mergeMap, map} from 'rxjs/operators';
const rootEpic = action$ =>
action$.pipe(
ofType("INIT"), // Execute when the action type is 'INIT'
mergeMap(action =>
eventSyncer
.trackEvent(MyContract, "MyEventName", { filter: {}, fromBlock: 1})
.pipe(
map(eventData => myAction(eventData)) // Trigger redux action: MY_ACTION
)
)
);
// Read more about epics here: https://redux-observable.js.org/docs/basics/Epics.html
const rootReducer = (state = {}, action) => { /* TODO */ };
const epicMiddleware = createEpicMiddleware();
const store = createStore(rootReducer, applyMiddleware(epicMiddleware));
epicMiddleware.run(rootEpic);