Redux Observable Util is a helper library for using Redux and Redux Observable in TypeScript. It contains some helper functions and a simplified Epic setup.
Module | Version |
---|---|
redux | ^4.0.0 |
redux-observable | ^1.0.0 |
rxjs | ^6.0.0 |
Redux Observable Util simplifies the setup for defining an epic, cleaning up the code for readability.
somethingEpic = (action$, state$) =>
action$.pipe(
ofType('SOMETHING'),
switchMap(() =>
// Add logic
return { type: 'SUCCESS', something: 'something' };
)
);
@Epic('SOMETHING')
somethingEpic(action: AnyAction, state$: any) {
// Add logic
return { type: 'SUCCESS', something: 'something' };
}
Configuration of the epics is also simplified compared to the standard setup of Redux Observable. You call the generateEpics instead of combineEpics, and pass the services that contain @Epic decorators.
const epicMiddleware = createEpicMiddleware();
export const store = createStore(rootReducer, applyMiddleware(epicMiddleware));
epicMiddleware.run(combineEpics(Service.epic1, Service.epic2));
const epicMiddleware = createEpicMiddleware();
export const store = createStore(rootReducer, applyMiddleware(epicMiddleware));
epicMiddleware.run(generateEpics(Service));