[RxJS] AsyncSubject: representing a computation that yields a final value
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的更多相关文章
- [RxJS] AsyncSubject
AsyncSubject emit the last value of a sequence only if the sequence completed. This value is then ca ...
- [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 ...
- [RxJS] BehaviorSubject: representing a value over time
When an Observer subscribe to a BehaviorSubject. It receivces the last emitted value and then all th ...
- RxJS之AsyncSubject
AsyncSubject 是另一个 Subject 变体,只有当 Observable 执行完成时(执行 complete()),它才会将执行的最后一个值发送给观察者. import { Compon ...
- httpcomponents-client-4.4.x
Chapter 1. Fundamentals Prev Next Chapter 1. Fundamentals 1.1. Request execution The most essent ...
- httpcomponents-client-ga(4.5)
http://hc.apache.org/httpcomponents-client-ga/tutorial/html/ Chapter 1. Fundamentals Prev Next ...
- httpcomponents-client-4.3.x DOC
Chapter 1. Fundamentals Prev Next Chapter 1. Fundamentals 1.1. Request execution The most essent ...
- 沉淀再出发:java中的equals()辨析
沉淀再出发:java中的equals()辨析 一.前言 关于java中的equals,我们可能非常奇怪,在Object中定义了这个函数,其他的很多类中都重载了它,导致了我们对于辨析其中的内涵有了混淆, ...
- 使用Boost.Python构建混合系统(译)
目录 Building Hybrid Systems with Boost.Python 摘要(Abstract) 介绍(Introduction) 设计目标 (Boost.Python Design ...
随机推荐
- 《iOS Human Interface Guidelines》——Container View Controller
容器视图控制器 容器视图控制器管理和展示它的子视图集合--或者子控制器集合--以一种自己定义的方式. 系统定义的容器视图控制器的样例有标签栏视图控制器.导航栏视图控制器和分栏视图控制器(查看Tab B ...
- WinRAR 5.40无弹窗广告注册版下载
WinRAR 5.40无弹窗广告注册版下载 资料来源 http://www.heminjie.com/network/6366.html WinRAR 5.40 下载安装后,打开压缩包文件会弹出广 ...
- js32---CommonUtil.js
// BH 命名空间 namespace var BH = {} ; BH.Interface = function(name,methods){ //Interface是类.方法的名字,以后用BH. ...
- javafx image button
public class EffectTest extends Application { public static void main(String[] args) { launch(args); ...
- chocolatey 的安装与安装过程中的注意事项
安装的windows需求 Windows 7+ / Windows Server 2003+ PowerShell v2+ .NET Framework 4+ 注意:chocolatey的网站可能 ...
- Scala——构造函数
Scala的构造函数分为主构造函数和辅助构造函数. 辅助构造函数 辅助构造函数比较容易理解,它们同C++和Java的构造函数十分类似,只有两处不同: 1.辅助构造函数的名称为this,这主要是考虑到在 ...
- win7打不开chm格式文件
近期在开发的过程中,发现重装的系统Wind7 打不开java帮助文档.搜索了半天才找到. 在这里分享一下. 一.假设不能打开,可这样恢复文件关联: 1.開始执行,输入:regsvr32 ...
- Hibernate之API初识及增删改查实现
声明:关于hibernate的学习.非常大一部分东西都是概念性的. 大家最好手里都有一份学习资料,在我的博文中.我不会把书本上的概念一类的东西搬过来.那没有不论什么意义.关于hibernate的学习, ...
- item-设置可见性
如果我们想要设置menu中item的可见行,有两种方式: 1.直接在menu的xml代码中设置 <menu> <item android:id="@+id/action_h ...
- 一些常用JS函数和技巧总结
1.JS原生函数parseInt(),返回字符串的第一个数字,默认是十进制. 2.!!data.success //强制转换成布尔类型