博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[RxJS] Transformation operator: bufferToggle, bufferWhen
阅读量:6920 次
发布时间:2019-06-27

本文共 1504 字,大约阅读时间需要 5 分钟。

bufferToggle(open: Observable, () => close: Observalbe : Observalbe<T[]>)

bufferToggle take two args, first is opening observable, seconde is a function which return an observable for closing.

The closeing observalbe only execute after opening emit value.

const source$ = Rx.Observable.interval(500);const open$ = Rx.Observable.interval(1500);const close$ = Rx.Observable.interval(1000);/**---0---1---2---3---4---5---6---7---8---9----....    (source)-----------1-----------2-----------3--------...      (open)           --- ---x    --- ---x    --- ---x...      (close)        bufferToggle(open$, () => close$)        ------------------([2,3])-----([5.6])-----([8,9])--...*/const foo$ = source$.bufferToggle(open$, () => {  return close$;});foo$.subscribe(  (x) => console.debug("Next: " + x),  (err) => console.error(err),  () => console.info("DONE"))/*"Next: 2,3""Next: 5,6""Next: 8,9""Next: 11,12"...*/

 

bufferWhen( () => Observable):

bufferWhen takes a function which return observable.

const source$ = Rx.Observable.interval(500);const close$ = Rx.Observable.interval(1000);/**---0---1---2---3---4---5---6---7---8---9----....    (source)-------0-------1-------2-------3-------4---....     (close)        bufferWhen(()=>close$)        -------(0)-----([1,2])-([3,4])-([5,6])--......  */const foo$ = source$.bufferWhen(() => close$);foo$.subscribe(  (x) => console.debug("Next: " + x),  (err) => console.error(err),  () => console.info("DONE"))/*"Next: 0""Next: 1,2""Next: 3,4""Next: 5,6""Next: 7,8"...*/

 

转载地址:http://uyecl.baihongyu.com/

你可能感兴趣的文章
Validating Common Form Input - Part 2 Validating a username
查看>>
OpenStack参考架构的搭建经验
查看>>
webService——wsimport命令建立webService本地客户端
查看>>
另眼看SAP应用
查看>>
走近复杂数据库计算型软件的设计与制作(5)—存储过程的设计
查看>>
随机密码生成器
查看>>
用Python开发主机批量管理工具
查看>>
Oracle备份恢复五(数据泵)
查看>>
excel将宏保存到个人工作簿
查看>>
Mono 1.2.5 发布,提供对IronPython和DLR的支持
查看>>
Docker 镜像的推送(六)
查看>>
【.Net Micro Framework PortingKit – 09】串口驱动
查看>>
SQL Server中的CLR编程——用.NET为SQL Server编写存储过程和函数
查看>>
一次支付平台紧急故障处理备忘
查看>>
幸福,就要爱得‘直接、实干’
查看>>
[零基础学JAVA]Java SE基础部分-03. 运算符和表达式
查看>>
Oculus之外,那些高大上的虚拟现实(VR)装备
查看>>
XenApp_XenDesktop_7.6实战篇之二:基础架构准备
查看>>
使用React、Node.js、MongoDB、Socket.IO开发一个角色投票应用的学习过程(二)
查看>>
升级XCode7后,Qt编译无法找到SDK的问题
查看>>