我的“zipLatest"运营商已经存在? [英] Does my "zipLatest" operator already exist?

查看:59
本文介绍了我的“zipLatest"运营商已经存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于我为自己编写的运算符的快速问题.

请原谅我可怜的大理石图:

zipaa--bb--cc--dd--ee--ff--------gg--11----22--33--------44--55----================================--a1----b2--c3--------d4--e5----结合最新aa--bb--cc--dd--ee--ff--------gg--11----22--33--------44--55----================================--a1b1--c2--d3--e3--f3f4--f5--g5zip最新aa--bb--cc--dd--ee--ff--------gg--11----22--33--------44--55----================================--a1----c2--d3--------f4------g5

zipLatest(我写的那个)与 zip 几乎在同一时间触发,但没有排队 zip 包含.

我已经实现了它,我只是想知道它是否已经存在.我知道我过去写过一个类似的方法,偶然发现我在不知情的情况下编写了 sample 运算符.

那么,这是否已经存在于框架中,还是作为我没有想到的元素的简单组合而存在?

注意:我不想依赖于输入的相等性来进行重复数据删除(a la distinctUntilChanged).它应该与一个只在一个时间间隔内输出 "a" 的信号一起工作.

解决方案

提供有关此问题的更新:RxJS 6 中仍然没有包含此要求的运算符,并且似乎没有计划用于未来版本.也没有提出此运算符的公开拉取请求.

按照此处的建议,combineLatest的组合code>、firstrepeat 将产生预期的行为:

combineLatest(obs1, obs2).pipe(first()).pipe(repeat());

combineLatest 将等待两个 Observables 的发射 - 除了每个 Observable 的最新发射之外,所有发射都扔掉.first 将在发射后完成 Observable 并且 repeatcombineLatest 上重新订阅,导致它再次等待两个 observable 的最新值.

repeat 的重新订阅行为没有完全记录,但可以在 GitHub 源代码:

<块引用>

source.subscribe(this._unsubscribeAndRecycle());

quick question about an operator I've written for myself.

Please excuse my poor-man's marble diagrams:

zip
aa--bb--cc--dd--ee--ff--------gg
--11----22--33--------44--55----
================================
--a1----b2--c3--------d4--e5----

combineLatest
aa--bb--cc--dd--ee--ff--------gg
--11----22--33--------44--55----
================================
--a1b1--c2--d3--e3--f3f4--f5--g5

zipLatest
aa--bb--cc--dd--ee--ff--------gg
--11----22--33--------44--55----
================================
--a1----c2--d3--------f4------g5

zipLatest (the one I wrote) fires at almost the same times as zip, but without the queueing zip includes.

I've already implemented it, I'm just wondering if this already exists. I know I wrote a similar method in the past, to discover by random chance that I'd written the sample operator without knowing it.

So, does this already exist in the framework, or exist as a trivial composition of elements I haven't thought of?

Note: I don't want to rely on equality of my inputs to deduplicate (a la distinctUntilChanged). It should work with a signal that only outputs "a" on an interval.

解决方案

To give an update on the issue: There is still no operator for this requirement included in RxJS 6 and none seems to be planned for future releases. There are also no open pull requests that propose this operator.

As suggested here, a combination of combineLatest, first and repeat will produce the expected behaviour:

combineLatest(obs1, obs2).pipe(first()).pipe(repeat());

combineLatest will wait for the emission of both Observables - throwing away all emissions apart from the latest of each. first will complete the Observable after the emission and repeat resubscribes on combineLatest, causing it to wait again for the latest values of both observables.

The resubscription behaviour of repeat is not fully documented, but can be found in the GitHub source:

source.subscribe(this._unsubscribeAndRecycle());

这篇关于我的“zipLatest"运营商已经存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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