码迷,mamicode.com
首页 > Windows程序 > 详细

[RxJS] Split an RxJS observable conditionally with windowToggle

时间:2016-12-22 22:36:52      阅读:251      评论:0      收藏:0      [点我收藏+]

标签:sed   condition   ble   class   diff   its   build   blog   cti   

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---------------          
*/

 

[RxJS] Split an RxJS observable conditionally with windowToggle

标签:sed   condition   ble   class   diff   its   build   blog   cti   

原文地址:http://www.cnblogs.com/Answer1215/p/6212974.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!