Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 02:14
    morsmodr commented #412
  • 02:14
    morsmodr commented #412
  • 01:48
    morsmodr commented #412
  • 01:47
    morsmodr commented #412
  • 01:46
    morsmodr commented #412
  • 01:28
    morsmodr commented #412
  • 01:27
    morsmodr commented #412
  • 01:25
    morsmodr commented #412
  • Oct 24 09:25
    floroz edited #757
  • Oct 24 09:25
    floroz edited #757
  • Oct 24 09:25
    floroz opened #757
  • 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
Kevin Ghadyani
@Sawtaytoes
@d4nielhdz What's collectionData? An observable right?

@fisherspy It shouldn't matter about the payload. If both observables fire once, then it outputs values in your pipe. That's how combineLatest works. It waits for observables to output something once. After that happens, then you start receiving values in the combineLatest().pipe.

If you want something to emit when either observable emits, use merge instead of combineLatest.

>°))))彡
@fisherspy
But If I dispach{type: 'FOCUS_PAGE_FETCH' } instead of {type: 'Focus_PAGE_FETCH', payload: {}} with combineLatest. it only outputs value in my pipe the first time both observables fire once, after that if I fire one of them, it will not output values in my pipe, unless you fire both of them. with payload: {}, even just {}, combineLatest will work alright. I dont know whether it's a bug.
Pervez Alam
@pervezalam777
Can anyone share some complex Redux-Observable test-cases sample. I need to study how to write test cases which is close to real project code scenario.
Kevin Ghadyani
@Sawtaytoes
@pervezalam777
import { ActionsObservable } from 'redux-observable'

// ...

export const mockAjaxResponse = (
    mockedResponse,
) => ({
    ajax: () => (
        ActionsObservable
        .of({
            response: mockedResponse,
        })
    ),
})

// ...

fetchUserEpic(
    // action$
    ActionsObservable
    .of(
        fetchUser({ // this is a Redux action creator
            username: 'test@test.com',
            password: 'test',
        })
    ),

    // state$
    new BehaviorSubject({
        user: null,
    }),

    // Dependency injection
    mockAjaxResponse(),
)
@fisherspy I don't think it's a bug, but it might be something wonky in your setup. If it works for you, keep it that way. But what you're seeing sounds half-correct meaning there might be something else happening.
Alessandro Savino
@xavier7179
hi there. I already asked a portion of what I'm trying to do but I got stucked in expanding it (or better, make it "customisable"), so here I come again. The idea is: let's say that I want several epics working on ajax calls (one per epic on different urls), dealing with everythiyg (ok results, errors in calling, taking only one call and discarding duplications, taking care of canceling). Then, let's say that, for some reason, I need to concatenate them too, in order to call only one epic, and chain the aforementioned single epics (only on success, of course), keeping their code sepate not to duplicate them for the case when I need them alone, but also keeping working cancellations, error dealing and so on. Is there a way to approach the problem in a systematic way? Thank you so much!
Kevin Ghadyani
@Sawtaytoes

@xavier7179 I'd need a bit of code to work with. Can't visualize what you mean.

You can always do something like dispatching an action from those epics making API calls and then have a single epic do something like:

combineLatest(
  action$.pipe(ofType('FIRST_API_RESPONSE')),
  action$.pipe(ofType('SECOND_API_RESPONSE')),
)
Alessandro Savino
@xavier7179

@Sawtaytoes sure!
The schema I'm depicting in my mind is something like (avoiding parallelism and keeping the order):

  • call doAllEpics
    • call epic1 (global_parameters)
    • if (epic1 succeed)
      • call epic2 (global_parameters)
        • if (epic2 succeed)
          • call epic3 (global_parameters)
            • ... same structure if a 4th one is needed an so on
        • else
          • do something
    • else // cancellation, errors
      • do something

So far, based on your previous suggestion, I did something like this (which it is not fully including all scenarios but epic error):

export function fetchEpics(action$) {
    return action$.pipe(
        ofType(FETCH_EPIC1),
        take(1),
        mergeMap(
            (original_action) =>
                concat(
                    of(fetchEPIC1(original_action.payload)),
                    action$.ofType(FETCH_EPIC2).pipe(
                        take(1),
                        map(() => fetchEPIC2(original_action.payload)
                        )
                ),
            ),
        )
    );
}

But as soon as I try a third one, I got stuck.

Julian Geppert
@Spacetoaster
Hi, jsbin live examples seem to be broken in the docs. Not sure if this has been reported already, just thought i'd post it here
Kevin Ghadyani
@Sawtaytoes
@xavier7179 What's "a third one"?
Alessandro Savino
@xavier7179
@Sawtaytoes I cannot add a third epic (like in the above schema) to the two epics code example.
Kevin Ghadyani
@Sawtaytoes

@xavier7179 Is there any reason you can't move this code to another epic?

action$.ofType(FETCH_EPIC2).pipe(
   take(1),
   map(() => fetchEPIC2(original_action.payload))

I know you need original_action.payload. When your action completes, can you add originalActionPayload: original_action.payload to the action?

Alessandro Savino
@xavier7179

@xavier7179 Is there any reason you can't move this code to another epic?

Sorry, I'm not sure I got the question...

I know you need original_action.payload. When your action completes, can you add originalActionPayload: original_action.payload to the action?

I can certainly add it. Is it the issue I'm facing figuring out how to chain several epics in sequence, avoiding parallelism?

Kevin Ghadyani
@Sawtaytoes
@xavier7179 Correct. You're wanting orchestration where you want one action to occur which affects another. You could simply just make a huge epic. You don't have to dispatch actions.
@xavier7179 You only need to dispatch actions when certain things happen like if other parts of your app need to know what's happening.
Alessandro Savino
@xavier7179
But what I do not get is: I need actions to start epics, and if I want to keep each single epic apart in order to avoid duplicating the code when I need them alone, how can I implement the "once one epic end without error, start the next one" protocol?
Evert Bouw
@evertbouw
I'm not sure if nesting is the right approach. what about putting all the epics at the top level? Start the second epic with the success action of the first. Have a separate epic to further process the errors or combine the logic into a custom operator
Alessandro Savino
@xavier7179

I'm not sure if nesting is the right approach. what about putting all the epics at the top level? Start the second epic with the success action of the first. Have a separate epic to further process the errors or combine the logic into a custom operator

But this way I cannot call epics alone... am I right?

Alessandro Savino
@xavier7179
For the application I'm working on, having them separate (to call alone) and find out a way to concatenate them makes totally sense... this is why I'm trying to improve the two epcs code in order to have no more boundaries.
Evert Bouw
@evertbouw
you could have the epic listen for two actions, the result action of the previous or its own start
Ahmad R
@harvester-klirk
hey guys i need help setting up "redux-persist " in a react js
Ahmad R
@harvester-klirk
i'm trying to setup redux-persist here's my code , all the tutorials on the redux-persist have a different setup approach
`const createStoreWithMiddleware = applyMiddleware('
  `promiseMiddleware,`
  `ReduxThunk`
`)(createStore);`

 `ReactDOM.render(`
  `<Provider`
   ` store={createStoreWithMiddleware(`
     ` Reducer,`
    `  window.__REDUX_DEVTOOLS_EXTENSION__ &&`
    `  window.__REDUX_DEVTOOLS_EXTENSION__()`
     `  )}`
   ` >`
     ` <BrowserRouter>`
      ` <App />`
    ` </BrowserRouter>`
   `</Provider>,` 
Alessandro Savino
@xavier7179

@evertbouw @Sawtaytoes I actualy solved 90% of the issue with the following two epics:

export function fetchAllEpics(action$) {
    return action$.pipe(
        ofType(FETCH_ALL_EPICS),
        take(1),
        mergeMap((original_action) =>
            concat(
                of(fetchFirstEpicAction(original_action.payload)),
                action$.ofType(EPIC1_FETCHED).pipe(
                    take(1),
                    mergeMap(() =>
                        concat(
                            of(fetchSecondEpicAction(original_action.payload)),
                            action$.ofType(EPIC2_FETCHED).pipe(
                                take(1),
                                map(() => fetchThirdEpicAction(original_action.payload))
                                )
                            ),
                        )
                    )
                )
            )
    );
}

export function collectEpicResults(action$) {
    return action$.pipe(
        ofType(FETCH_ALL_EPICS),
        mergeMap((action) =>
                combineLatest([
                    action$.ofType(EPCI1_FETCHED),
                    action$.ofType(EPIC2_FETCHED),
                    action$.ofType(EPIC3_FETCHED)
                ]).pipe(
                    map(([e1, e2, e3]) =>
                        fetchAllEpicsFullfilled({ e1: e1.payload, e2: e2.payload, e3: e3.payload })
                    ),
                    catchError(([error_e1, error_e2, error_e3]) => of(fetchAllEpicsFailed([error_e1, error_e2, error_e3])))
                )
            )
    );
}

where the composition can be done by replacing the map with a mergeMap + concat block. Everything works fine in the serialization, while the second epic is perfect when everything works without errors. When in the chain some epic fails (notice that each EPIC has its own piping of map and catchError) then, the first epic is stuck. I figure out that maybe the issue is not having two epics but putting all in one epic but... I did not work out how, in order to keep the correct path still fully working.

André Vitor de Lima Matos
@andrevmatos
Did anyone here experience redux-observable getting slow at processing actions on some conditions? I noticed registering to some events on an EventEmitter 3rd-party lib did slow the overall state machine a lot. I'm not sure what's causing it, if it's something with schedulers. Profiling the app has shown CPU not going up, but the actions still get increasingly slow to go through certain epics
Kevin Ghadyani
@Sawtaytoes

@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
@andrevmatos
@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
@Sawtaytoes

@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
@zgavin1
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
@Sawtaytoes
@zgavin1 Where is this linked?
Evert Bouw
@evertbouw
that will appear in your browser console
Jesus The Hun
@JesusTheHun
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
@Sawtaytoes

@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
@JesusTheHun

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 ?

xieshuhong
@xieshuhong
image.png
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)
@saharrachamimfg
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
@MaximeBernard
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
@elstr
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
@JesusTheHun
@elstr show me what you got I'll help you do that
Kevin Ghadyani
@Sawtaytoes
@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.
mwalkerr
@mwalkerr
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
@Sawtaytoes
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.
PogoniiA
@PogoniiA
Hey guys