Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
  • Oct 10 09:29
    omerts edited #756
  • Oct 10 09:29
    omerts opened #756
  • Oct 10 09:27
    omerts closed #755
  • Oct 10 09:24
    omerts opened #755
  • Oct 09 12:05
    MursalovAltun commented #706
  • Oct 08 12:25
    Whazor commented #706
  • Oct 05 14:56
    evertbouw commented #752
  • Oct 04 13:19
    andrevmatos commented #754
  • Oct 02 17:00
    talhaguy commented #752
  • Oct 02 06:42
    talhaguy commented #752
  • Oct 01 21:57
    andrevmatos closed #754
  • Oct 01 21:57
    andrevmatos commented #754
  • Sep 30 21:45
    andrevmatos edited #754
  • Sep 30 18:54
    andrevmatos edited #754
  • Sep 30 18:53
    andrevmatos opened #754
  • Sep 23 11:43
    innovation-stack opened #753
  • Sep 18 22:15
    D34THWINGS commented #752
  • Sep 18 22:12
    D34THWINGS edited #752
  • Sep 18 22:12
    D34THWINGS opened #752
  • Sep 17 08:54
    nixxquality commented #706
Kevin Ghadyani

@andrevmatos That might be something in your code. I've run really complex Redux-Observable applications and performance tests. It's more-likely something where your pipelines are spawning more observables and not getting rid of past ones. Or that the pipelines are computationally intensive.

Is it possible to post any of that code?

André Vitor de Lima Matos
@Sawtaytoes the weird behavior was seen on https://github.com/raiden-network/light-client on some specific high-load scenarios. I couldn't find a small reproducible example, pretty sure it wasn't on redux-observable side and instead some slowness on the 3rd-party eventemitter lib (matrix-js-sdk). Anyway, replacing some concatMap with mergeMap + waiting observable, and replacing some from with scheduled + asapScheduler on some epics which could dispatch intensive side-effects actions did seem to have fixed or worked around the issue, at least preventing other epics from starving. raiden-network/light-client#2281
Kevin Ghadyani

@andrevmatos Awesome! Glad you were able to fix it! And yes, you are right, using concatMap is running things sequentially rather than async. Same issue people run into using async-await.

Redux-Observable has its own scheduler to allow things to speed up, but I'm assuming you needed something even more than that in your scenario. Personally, I'm curious.

Similar to you, I also wrote my own controller for my LIFX lights all in Redux-Observable :).

Zach Gavin
Hey just a heads up for yall, there's a dynamic URL here: https://github.com/redux-observable/redux-observable/blob/16f083d405ace2039da0836c4a404a85d8052991/src/createEpicMiddleware.ts#L49 that does not work anymore
Kevin Ghadyani
@zgavin1 Where is this linked?
Evert Bouw
that will appear in your browser console
Jesus The Hun
how are you guys handling side effects such as form control ? closing the form modal on sucess, or redirecting on success. Do you create an epic for each form or do you decorate your action payload to add some callbacks ? I feel like callbacks are anti-pattern but it also feel a lot more lightweight
Kevin Ghadyani

@JesusTheHun I don't pass callbacks like that anywhere in Redux-Observable , but sometimes I will pass classes with methods if necessary like a flicClient or eventEmitter depending.

While it's possible to pass React callbacks to Redux-Observable, that's really strange and wouldn't work if you put your Redux store in a Web Worker or a child process.

The way of doing it is creating a generic epic or epics that work with any form. Add some form of id and now you can identify form to close regardless of which epic you're in.

Your Modal component, or whatever you're using to display the form would get hidden because it's listening to the open state of that particular ID.

Does this make sense? If you have code, paste some in, we can help you come up with a plan.

Jesus The Hun

Hi @Sawtaytoes it does make sense, we actually have though about that option and then thought it was a bit overkill. Your worker argument is very good.

The way of doing it is creating a generic epic or epics that work with any form. Add some form of id and now you can identify form to close regardless of which epic you're in.

Why/How a generic epic ? In your business epic you dispatch your success action and in your generic epic you catch all those success/failure and your react to them ?

here it’s a interview question that I ran into , the request for me , is to write code inside the return function, and based on the following info , to print out 1, 2, 3 on the console
can anyone help me with this
Sahar Rachamim (Kishu)
Hey! Do you have good resources for learning how to structure our reducers and epics in a manageable way for a large-s application?
Maxime Bernard
Hi! I asked some questions about redux-observable's roadmap yesterday (redux-observable/redux-observable#738). Maybe some of you here have answers?
Eleonora Lester
hi! is there a way to execute async await using switchMap ?
I need to first execute a fetch, wait for the result, dispatch some actions and then continue with some other stuff
but can't manage to make it work
Jesus The Hun
@elstr show me what you got I'll help you do that
Kevin Ghadyani
@saharrachamimfg No clue. I wrote an article about how you could use it, but each app is different. Just know you can and should dispatch actions from epics that trigger other epics.
@xieshuhong can you paste the code and the issue you can't solve?
@JesusTheHun Correct. I catch those and dispatch different actions based on success or failure.
The JSbin link on https://redux-observable.js.org/docs/basics/Epics.html isn't working because JSbin is asking for a pro account to embed from https
Kevin Ghadyani
I wonder if all of them are like this. @jayphelps Looks like the site might need to use another paste-bin service or a license needs to be paid.
Hey guys
Is there a way in epic to subscribe for continuos data fetching
to listen changes in firebase ?
Pervez Alam
@PogoniiA : Yes, I think so, if you can open a request which keep on sending data then it can be done. Server sent event is the way to handle this please go through https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events Also I have create on sample for the same https://github.com/pervezalam777/server-sent-event (NOTE: Redux-Observable not used in this example)
@pervezalam777 thanks. I found a good example on stackoverflow which covers my whole idea.
So if someone is interested :
Kevin Ghadyani

@PogoniiA The answer in that StackOverflow link is correct.

Because Firebase doesn't have a native RxJS implementation, you need to take their streaming function, wrap it in an RxJS observable, and pipe off that in Redux-Observable.

From there, it just dispatches actions and the rest of your code works as you'd expect.


Hello guys,
I'm trying to test my Epic, I'm quite new with TestScheduler and Marble Diagrams.

I hope someone can help.

this is my Epic:

const deleteMediaEpic: Epic = (actions$, state$: StateObservable, { api }: EpicDependencies) =>
    switchMap((action: DeleteMediaAction) => api.deleteMedia(action.payload.operationCode, action.payload.productKey, action.payload.mediaToDelete).pipe(
      switchMap(() => {
        const actionsToDispatch = []
        actionsToDispatch.push(productSelected(action.payload.productKey, action.payload.operationCode))
        return of(...actionsToDispatch)
      catchError(mediaFetchError => of(`Error in deleteMediasEpic: ${mediaFetchError}`))

and this is my test:

it('Delete select Media', () => {
  testScheduler.run(({ hot, cold, expectObservable }) => {
    const action$ = hot('-a', {
      a: { type: 'DELETE_MEDIA', payload: { productKey: 'PRODUCT_KEY1', operationCode: 'VPV_H_SHANAOR1', mediaToDelete: [0] } }

    const state$ = {}

    const dependencies = {
      getJSON: url => cold('--a', {
        a: { url }

    const output$ = deleteMediaEpic(action$, state$, dependencies)

    expectObservable(output$).toBe('---bc', {
      b: {
        type: 'PRODUCT_SELECTED',
        payload: { productKey: 'PRODUCT_KEY1', saleCode: 'VPV_H_SHANAOR1', filtersType: undefined }
      c: {
        type: 'CLEAR_MEDIA_SELECTED',
        payload: {
          defaultValue: []

for me of is a sequence operator and c should be immediately after b.

Hope you can understand something from the code me.

and this is the result of the test:

  expect(received).toEqual(expected) // deep equality

  - Expected
  + Received

  @@ -1,8 +1,8 @@
   Array [
    Object {
  -   "frame": 3,
  +   "frame": 6,
     "notification": Notification {
      "error": undefined,
      "hasValue": true,
      "kind": "N",
      "value": Object {
  @@ -14,11 +14,11 @@
       "type": "PRODUCT_SELECTED",
    Object {
  -   "frame": 4,
  +   "frame": 6,
     "notification": Notification {
      "error": undefined,
      "hasValue": true,
      "kind": "N",
      "value": Object {

     5 | 
     6 | const testScheduler = new TestScheduler(
  > 7 |  (actual, expected) => { expect(actual).toEqual(expected) }
      |                      ^
     8 | )
I found it, I need to group my action like this ------(ab) because I use of or from
Kevin Ghadyani
@amirbr Glad you figured it out. I meant to respond yesterday and got caught up in other things.
Thank you @Sawtaytoes
Tommy Asz
any have an example of redux-observable with typescript? it really complicated when using typescript
Kevin Ghadyani
@ThomasEddie I've personally not used TypeScript with Redux-Observable. What are the issues you're running into.
Alexander Riss
Hi all - very basic question - is it possible for two epics to listen for the same action without conflicting ?
20 replies
André Samuelsson

I've been battling with redux-observable and typescript for a couple of hours now and I'm finally up and running.
I strongly suggest using redux-toolkit if you haven't done so before. https://redux-toolkit.js.org/
They have a very small example here: https://redux-toolkit.js.org/api/createAction#with-redux-observable
This is what worked for me, but I've been using redux-toolkit for a couple of projects now so this step was pretty natural I guess.

Before getting that working I mucked about with typesafe-actions since that was what examples I found was using. It was type-hell. From my short hours of that, I suggest not having typesafe-actions and redux-toolkit in the same project. They want to do the same thing.

I also had a look at this example repo: https://github.com/mitsuruog/react-redux-observable-typescript-sample
which does redux-observable with typesafe-actions. Looks very decent. The import * as actions from '...' thing here https://github.com/mitsuruog/react-redux-observable-typescript-sample/blob/master/src/shared/store/index.ts#L6
forces you to split your actions to its own file with nothing else in them, which is a good habit to have.

Here's my redux store setup for inspiration:

import {combineReducers, configureStore, Action, createAction} from "@reduxjs/toolkit";
import { combineEpics, createEpicMiddleware } from "redux-observable";
import { filter, map } from "rxjs/operators";

import { Observable } from "rxjs";

export const ping = createAction<{ foo: string }>("ping");
export const pong = createAction<{ bar: string }>("pong");

const epicMiddleware = createEpicMiddleware();

const epic1 = (action$: Observable<Action>) =>
    map((a) => pong({ bar: a.payload.foo.toUpperCase() }))

const rootEpic = combineEpics(epic1);

const rootReducer = combineReducers({
  // your reducers

export const store = configureStore({
  reducer: rootReducer,
  middleware: (getDefaultMiddleware) =>


export type RootState = ReturnType<typeof rootReducer>;
Kevin Ghadyani
@Tejpbit Instead of filter(ping.match), why not use ofType(ping.type)?
André Samuelsson
Just tried it.
Looks like the filter with action.match thing makes sure the next operations in the pipe are typed.
With ofType the rest of the types of the members on the action is not deduced.
Most likely because I'm using the redux-toolkit action creators. If I would be using the typesafe-action action creators and then also set the type of the action using the Epic from redux-observable with all its type parameters then the ofType way would work, I think.
Jānis Zaržeckis

Probably this is not the right place to ask such an off-topic question - but I'm wondering is Redux Observable still a popular choice among developers?

I personally like it quite much, but perhaps now there are some better alternatives. I see people keep using redux-sagas - but I personally can't really stand them.
And some avoid redux in the first place, therefore use just hook libraries such as https://www.npmjs.com/package/rxjs-hooks

Just curios to hear some opinions about some popular options post redux-observable

1 reply
Kevin Ghadyani

@jzarzeckis Great question! One I've pondered myself since I started using it. RecoilJS argument at the bottom.

Redux-Observable is very niche in terms of who's using it, but it brings an amazing amount of value to a project. I will absolutely use it on any project I write myself and just got my place of employment to start using it. The biggest complaint is the lack of documentation (for it an RxJS) whereas I've heard how much simpler the epic model has been. We could achieve the same thing writing custom middleware, but it wouldn't be in these slick functional pipelines that RxJS provides.

Redux-Observable is Message-Oriented Programming. This is by-far, one of the best ways to build projects. If you look at engineers that work on backend services, they're going more and more for a distributed model of micro services with an event bus and a standard interface between machines. It's not just machines talking to machines, there's usually a broker somewhere like RabbitMQ, Redis, or Kafka in the middle handling the publishing and subscribing of micro services to the services they care about. Sound familiar? It's the same as ofType in Redux-Observable.

Many developers get bored with old tech (myself included). The reason React is still in vogue happens to be because the component API fundamentally changes ever year. People have to keep making tutorial videos, writing articles, and complaining about it. It sells itself. Svelte would've taken over if not for hooks as it's a lot easier to understand and works on the same observable model as hooks.

Redux has been falling out of favor because React hooks are more convenient the same way imperative code is right there in the language and RxJS is not. Sadly, React hooks are messy, impossible to unit test unless you pull them into a separate hook, and easy to wind up with serious performance problems (one reason why RecoilJS exists). There are other reasons like Redux is falling out of favor, but I attribute it to the fact that nothing really changes; therefore, no one really talks about it. Where I work, we decided to keep using Redux going forward and are even using it more now; although, we don't agree with the single-store model and have changed that methodology too.

The reason RecoilJS isn't a replacement for Redux-Observable is because it doesn't have a single event bus. Every observable or atom is watching other observables for changes. If you've ever written an RxJS application without Redux-Observable, you probably know how complicated this can be. It won't take long for people to have no clue what the business logic is doing. Having a single event bus (Redux) makes everything easier at a small potential cost to performance.

On top of that, RecoilJS is like writing Redux middleware without RxJS. It uses its own observable model and is ultimately just a way around React Context API. Heck, we had the same issue with React's context at work on multiple occasions. We even built our own form library to handle it.

Jānis Zaržeckis
@Sawtaytoes your answer is candy to my ears
I'd like to learn more through community.
Cvetkovic Milos
@Sawtaytoes I do like redux observables, I'm coming from Angular word- there is the same paradigm as ngrx but I'm missing the lazy load store item feature, any advice from you on how I can lazy load them in combination with redux-observable, I've found some Microsoft's library called redux dynamic modules but it's not so popular, I'm asking because in large project initial scripting will be to big, thanks in advanced :)
5 replies
Phudit Chuengjaroen

Hi Everyone, I have a question regarding RXJS and Redux Obs.

I would like to make the epic for fetching data when user comes to /public/:id then if user leave and data comes later for next time user go in the same path(different id) user still see the last then loading
So my questing do I need to use Cancellation on switchmap ? because I have tried and after user go in the same path it’s not fetching anymore.

Alessandro Savino
@nuttikung I could be wrong but you do not need to cancel, otherwise the observable is not "listening" anymore...
Kevin Ghadyani

@nuttikung switchMap has automatic cancelation in some ways. If it receives the command twice, the first one gets canceled. Or do you mean something like take or takeUntil on your data fetch?

I write in cancelation for all my data fetching, but it's different for each based on the needs of the app. For instance, if the user logs in, does it fire the action again? If so, switchMap is enough. If not, you have to write that in yourself.