0.1.0 • Published 6 years ago

redux-observable-util v0.1.0

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

redux-observable-util

npm version CircleCI

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.

Table of Contents

Peer Dependencies

ModuleVersion
redux^4.0.0
redux-observable^1.0.0
rxjs^6.0.0

Defining Redux Observable Epics

Redux Observable Util simplifies the setup for defining an epic, cleaning up the code for readability.

Before

somethingEpic = (action$, state$) =>
  action$.pipe(
    ofType('SOMETHING'),
    switchMap(() =>
      // Add logic

      return { type: 'SUCCESS', something: 'something' };
    )
  );

After

@Epic('SOMETHING')
somethingEpic(action: AnyAction, state$: any) {
  // Add logic

  return { type: 'SUCCESS', something: 'something' };
}

Configuring Epics in Store

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.

Before

const epicMiddleware = createEpicMiddleware();
export const store = createStore(rootReducer, applyMiddleware(epicMiddleware));
epicMiddleware.run(combineEpics(Service.epic1, Service.epic2));

After

const epicMiddleware = createEpicMiddleware();
export const store = createStore(rootReducer, applyMiddleware(epicMiddleware));
epicMiddleware.run(generateEpics(Service));
0.1.0

6 years ago

0.0.1

6 years ago