This lesson will teach you about AsyncSubject, another type of Subject with some replaying logic inside. We will also look at some use cases for this peculiar RxJS subject variant.

AsyncSubject:

Emit last value only when sequence completed.

BehaviorSubject:

Replay onces, only before compleation.

ReplaySubject:

Replay many, before of after compleation.

var subject = new Rx.AsyncSubject();

// Subject
// ReplaySubject: replays many, before or after completion
// BehaviorSubject: replays one, only before completion
// AsyncSubject: replays one, only if completed var observerA = {
next: function (x) { console.log('A next ' + x); },
error: function (err) { console.log('A error ' + err); },
complete: function () { console.log('A done'); },
}; subject.subscribe(observerA);
console.log('observerA subscribed'); var observerB = {
next: function (x) { console.log('B next ' + x); },
error: function (err) { console.log('B error ' + err); },
complete: function () { console.log('B done'); },
}; setTimeout(() => subject.next(), );
setTimeout(() => subject.next(), );
setTimeout(() => subject.next(), );
setTimeout(() => subject.complete(), ); /*
----1---2---3--|
.............3|
3|
*/ setTimeout(function () {
subject.subscribe(observerB);
console.log('observerB subscribed');
}, );
/*
"observerA subscribed"
"A next 3"
"A done"
"B next 3"
"B done"
"observerB subscribed"
*/

[RxJS] AsyncSubject: representing a computation that yields a final value的更多相关文章

  1. [RxJS] AsyncSubject

    AsyncSubject emit the last value of a sequence only if the sequence completed. This value is then ca ...

  2. [RxJS] AsyncSubject and ReplaySubject - Learn the Differences

    We can use Subject as Observable and Observer: // Subject should be only used to emit value for priv ...

  3. [RxJS] BehaviorSubject: representing a value over time

    When an Observer subscribe to a BehaviorSubject. It receivces the last emitted value and then all th ...

  4. RxJS之AsyncSubject

    AsyncSubject 是另一个 Subject 变体,只有当 Observable 执行完成时(执行 complete()),它才会将执行的最后一个值发送给观察者. import { Compon ...

  5. httpcomponents-client-4.4.x

    Chapter 1. Fundamentals Prev     Next Chapter 1. Fundamentals 1.1. Request execution The most essent ...

  6. httpcomponents-client-ga(4.5)

    http://hc.apache.org/httpcomponents-client-ga/tutorial/html/   Chapter 1. Fundamentals Prev     Next ...

  7. httpcomponents-client-4.3.x DOC

    Chapter 1. Fundamentals Prev     Next Chapter 1. Fundamentals 1.1. Request execution The most essent ...

  8. 沉淀再出发:java中的equals()辨析

    沉淀再出发:java中的equals()辨析 一.前言 关于java中的equals,我们可能非常奇怪,在Object中定义了这个函数,其他的很多类中都重载了它,导致了我们对于辨析其中的内涵有了混淆, ...

  9. 使用Boost.Python构建混合系统(译)

    目录 Building Hybrid Systems with Boost.Python 摘要(Abstract) 介绍(Introduction) 设计目标 (Boost.Python Design ...

随机推荐

  1. 执行异步UI更新

    异步更新UI的几种方法①.使用Control.Invoke方式来更新数据                     foreach (DataGridViewRow dgvr in this.dgv_s ...

  2. wmic windows

    http://www.ynpxrz.com/n614885c2025.aspx http://www.ynpxrz.com/n614883c2025.aspx http://www.ynpxrz.co ...

  3. ubuntu-虚拟机跟主机资源共享的实现方法

    之前自己的虚拟机跟主机资源共享的时候,使用的是非常笨的方法,就是通过创建两个飞鸽,然后在两个飞鸽之间进行文件的传输,今天工作相对轻松一些,就趁机完善一下自己的工作环境,在网上搜索了关于资源共享的方法, ...

  4. php如何读写excel

    php如何读写excel 一.总结 一句话总结:PHP操作Excel最好的方法是使用PHPExcel类, 可以到官网下载PHPExcel类库 http://phpexcel.codeplex.com ...

  5. vue中判断路由变化

    使用from.path和to.path判断路由跳转 在methods里面写函数: 当然,上边函数里边可以做很多事情.

  6. (F) linux sort,uniq,cut,wc命令详解

    F:http://www.cnblogs.com/ggjucheng/archive/2013/01/13/2858385.html sort sort 命令对 File 参数指定的文件中的行排序,并 ...

  7. Spring学习总结(10)——Spring JMS---三种消息监听器

    消息监听器MessageListener 在spring整合JMS的应用中我们在定义消息监听器的时候一共可以定义三种类型的消息监听器,分别是MessageListener.SessionAwareMe ...

  8. 洛谷 P1208 [USACO1.3]混合牛奶 Mixing Milk

    P1208 [USACO1.3]混合牛奶 Mixing Milk 题目描述 由于乳制品产业利润很低,所以降低原材料(牛奶)价格就变得十分重要.帮助Marry乳业找到最优的牛奶采购方案. Marry乳业 ...

  9. Lightoj 1043 - Triangle Partitioning【二分】

    题目链接:http://lightoj.com/volume_showproblem.php? problem=1043 题意:一个三角形ABC,DE//BC.已知三角形ADE和四边形BDEC的面积的 ...

  10. eclipse中导入zico Maven项目

    zico源代码地址:https://github.com/jitlogic/zico 简单的说,git上同步的源代码需要先进行maven编译,然后导入eclipse. 如果没有配置好maven,请参考 ...