[RxJS] Split an RxJS observable conditionally with windowToggle

发布时间:2017-2-25 10:29:01 编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"[RxJS] Split an RxJS observable conditionally with windowToggle ",主要涉及到[RxJS] Split an RxJS observable conditionally with windowToggle 方面的内容,对于[RxJS] Split an RxJS observable conditionally with windowToggle 感兴趣的同学可以参考一下。

[RxJS] Split an RxJS observable conditionally with windowToggle

There are variants of the window operator that allow you to split RxJS observables in different ways. In this lesson we will explore the windowToggle variant and see one of its use cases in user interfaces.

Let's say we want to build a new functionality, it only receive the source when mousedown and stop receiving data when mouse up.

To do that we can use 'windowToggle':

const clockObs = Rx.Observable.interval(1000);
const downObs = Rx.Observable.fromEvent(document, 'mousedown');
const upObs = Rx.Observable.fromEvent(document, 'mouseup');

const source = clockObs
  .windowToggle(downObs, () => upObs)
  .switch()
  .subscribe(console.log);

/*
--0--1--2--3--4--5--6--7--8--9--
          windowToggle
----------D--------U-------------
          \
          -3--4--5-|
          
          switch / mergeAll
          
-----------3--4--5---------------          
*/

上一篇:WebGL入门教程(四)-webgl颜色
下一篇:Linux_arm驱动之按键模拟脉冲实现定时器的精确计时

相关文章

相关评论

本站评论功能暂时取消,后续此功能例行通知。

一、不得利用本站危害国家安全、泄露国家秘密,不得侵犯国家社会集体的和公民的合法权益,不得利用本站制作、复制和传播不法有害信息!

二、互相尊重,对自己的言论和行为负责。