Reputation: 37268
I don't understand why I need to use redux-observable? Can't I just create my own middleware to listen and emit to a subject on actions to redux. And then create pipelines (in place of epics) that use store.dispatch()
and store.getState()
?
Upvotes: 0
Views: 346
Reputation: 7307
Yes, you can write your own Redux-Observable style middleware.
Someone else I know has to do that because her company hasn't adopted RxJS, but then she loses out on a lot of the tooling you get from both Redux and RxJS pipeline operators.
Doing it yourself isn't always the best way though. Redux-Observable handles a lot of tough pieces behind the scenes. I've written my own for specific scenarios where I don't have Redux, but if I do, I go with Redux-Observable.
A different way to describe it, you could create a middleware function for every epic, or you could create a single middleware that puts together a bunch of epics and creates a single parent pipeline.
In the same way, you could have a single reducer that combines a bunch of smaller reducers together. combineReducers
lets you do this in a hierarchy, but each reducer doesn't know about the state of the others.
combineEpics
does this same thing. While you can add them hierarchically, technically that doesn't matter. To be clear, hierarchy does matter if you pipe off combineEpics
anywhere in your codebase. Probably not advised.
Your question could also be rephrased to "why should I use Redux if I could write my own object with getState
, dispatch
, and subscribe
methods? The only reason you'd write your own Redux is if you're in a situation where you don't want to use reducers for state management or have a custom scenario where you want Redux-like behavior, but not actually Redux the library.
Upvotes: 2