如何比较 Observable 流中的动作数据? [英] How to compare actions data in Observable stream?

查看:56
本文介绍了如何比较 Observable 流中的动作数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Redux,但在使用 RxJs 时遇到问题.

I'm using Redux and have problem with RxJs.

假设一个动作在 2 秒内触发了 3 次(类型:'OPEN').Action 正在向 Redux 状态发送一些数据.第一次和第三次被解雇带来了相同的数据,但第二次没有.都是有延迟才来的,带来一些影响.

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.

我想让 Observable 注意到,动作 1 和动作 3 具有相同的数据并更改输出顺序.从 1, 2, 3 => 2, 3. 第一个应该被删除,因为动作 nr 3.

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)
    )
);

问题:如何比较 Observable 中的活动流?

QUESTION: How to compare an active streams in Observable?

推荐答案

在 redux-observable 中不可能阻止/删除已分派的动作或修改它们的顺序,因为当它们到达你的史诗时,它们已经运行了您的减速器和任何其他中间件.这是有意为之,使史诗本身是唯一应该发生非确定性的地方;这也意味着当你在你的史诗中收到它们时,你可以确定地知道 redux 商店的状态已经更新.

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.

这篇关于如何比较 Observable 流中的动作数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆