[RxJS] Transformation operator: bufferToggle, bufferWhen
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"
...
*/
[RxJS] Transformation operator: bufferToggle, bufferWhen的更多相关文章
- [RxJS] Transformation operator: repeat
Operator repeat() is somewhat similar to retry(), but is not for handling operators. In this lesson ...
- [RxJS] Transformation operator: buffer, bufferCount, bufferTime
This lesson will teach you about another horizontal combination operator: buffer and its variants. B ...
- [RxJS] Transformation operator: scan
All of the combination operators take two or more observables as input. These operators may also be ...
- [RxJS] Transformation operator: map and mapTo
We made our first operator called multiplyBy, which looks a bit useful, but in practice we don't nee ...
- [RxJS] Utility operator: do
We just saw map which is a transformation operator. There are a couple of categories of operators, s ...
- rxjs自定义operator
rxjs自定义operator
- [RxJS] Creation operator: of()
RxJS is a lot about the so-called "operators". We will learn most of the important operato ...
- [RxJS] Connection operator: multicast and connect
We have seen how Subjects are useful for sharing an execution of an RxJS observable to multiple obse ...
- [RxJS] Combination operator: withLatestFrom
Operator combineLatest is not the only AND-style combinator. In this lesson we will explore withLate ...
随机推荐
- 主流的phpcms分析
小型网站适合wordpress,onethink,joomla(囧啦) wordpress(免费开源) 优点:1.样式丰富,模板重多 2. 安全性 3. 对搜索引擎友好,收录快. ...
- str、__str__ 、repr、 __repr__、``
内建函数str()和repr() 或反引号操作符(``)可以方便地以字符串的方式获取对象的内容.类型.数值属性等信息. str()函数得到的字符串可读性好(故被print调用),而结果通常无法用eva ...
- Python 手册——调用解释器
通常Python的解释器被安装在目标机器的 /usr/local/bin/python 目录下:把 /usr/local/bin 目录放进你的UNIX Shell 的搜索路径里,确保它可以通过输入py ...
- 练习2 I题 - 水仙花数
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Description 春天是 ...
- SpringSecurity数据库中存储用户、角色、资源
这几天项目中用到了SpringSecurity做登陆安全.所以在这写一下也许可以帮助一下其他人,自己也熟悉一下 SpringSecurity配置文件如下: <beans:beans xmlns= ...
- 怎么跳出MySQL的10个大坑
淘宝自从2010开始规模使用MySQL,替换了之前商品.交易.用户等原基于IOE方案的核心数据库,目前已部署数千台规模.同时和Oracle, Percona, Mariadb等上游厂商有良好合作,共向 ...
- BZOJ 3122 随机数生成器
http://www.lydsy.com/JudgeOnline/problem.php?id=3122 题意:给出p,a,b,x1,t 已知xn=a*xn-1+b%p,求最小的n令xn=t 首先,若 ...
- 深入Spring之web.xml
针对web.xml我打算从以下几点进行解析: 1.ContextLoaderListener: 启动Web容器时,自动装配ApplicationContext的配置信息. 2.RequestConte ...
- 14.5.4 Phantom Rows 幻影行
14.5.4 Phantom Rows 幻影行 所谓的幻读问题发生在一个事务 当相同的查询产生不同的结果集在不同的时间. 例如,如果一个SELECT 是执行2次,但是第2次返回的时间不第一次返回不同, ...
- wpf 动画
1动画实现 通过控件的属性 RenderTransform 设置 (1)设置控件的变化类型,如平移变化,旋转变化等,变化起点. (2)根据属性值链接相应的动画类型,如简单动画,关键帧,路径动画以及故事 ...