Why I Like redux-observable

Petr Lzicar
2 min readJan 14, 2022

--

I would like to share my experience with redux-observable in a few points.

Logic separation

Epics is nice place for your business logic. Doesn’t matter which functionality you need handle. Epics can contains almost everything — Api calls, Navigation handling, or other side-effects.

Easy invocation

Epics react on redux actions, so everywhere you can invoke it, epics listen.

Declarative style

Declarative style of writing is good readable and clean. On first view you know what code really do and don’t have guess in most cases :).

Promise cancelation

Redux-observable can cancel promise if there is newer version of same call. It’s very handy for suggestion lists via API for example.

DEMO time

redux-observable epic example from app Prace za Rohem

As you can see on image above, we have epic for events logging. Everytime when LOG_EVENT action is triggered this epic react on it. In short do this: skipe execution when logging is disabled, create a buffer if there is more events, because want to save some network resources and want to send more data at once. After buffer time exceed, will send to our API all captured events and fail silently when needed.

Cons

  • Easy to break — if you forgot close stream for example
  • Lots of extra code writing — need epic, connect epic, epic middleware, need redux-action, need connect redux to Components…
  • Project is now in maintanance mode :/

Resources

Thanks for reading!

--

--