How to compare actions data in Observable stream?

只谈情不闲聊 提交于 2019-12-11 15:08:59

问题


I'm using Redux and have problem with RxJs.

Let's say that one action was fired 3 times (type: 'OPEN') during 2 secs. Action is sending some data to Redux state. First and third fired are bringing the same data, but second not. All of them have delays before coming to bring some effects.

I want Observable to notice, that action 1 and action 3 have the same data and change the order of output. From 1, 2, 3 => 2, 3. The first one should be deleted because of action nr 3.

 const closeNotificationAuto = action$ =>
    action$
       .ofType(OPEN)
       .mergeMap(action =>
            Observable.of(action)
              .delay(5000)
              .map(() => closeAuto())
              .takeUntil(
      action$.ofType(CLOSE).filter(a => a.something === action.something)
    )
);

QUESTION: How to compare an active streams in Observable?


回答1:


It's not possible in redux-observable to prevent/delete dispatched actions or modify the order of them because by the time they reach your epics they have already been run through your reducers and any other middleware. This is by design to make it so that epics themselves are the only place that nondeterminism should happen; it also means that you can know for certain that the redux store's state has been updated when you receive them in your epics.

If you can elaborate a bit on the use case I may be able to recommend alternative approaches.



来源:https://stackoverflow.com/questions/48750383/how-to-compare-actions-data-in-observable-stream

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!