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. js闭包注意事项

    /关于闭包使用应该注意的 // 1 闭包在父函数每次调用都会产生不同的闭包 // 2 闭包中子函数使用父函数变量的变量不是复制 是引用 // 3 闭包在循环中使用

  2. nodejs学习(三)--express连接mysql数据库,mysql查询封装

    一.说一下 连接不同的数据库需要安装相应的插件,此demo使用mysql数据库,需自行安装mysql数据库软件. 新建数据库webapp, 新建表users: 二.直接开码 npm install m ...

  3. fg、bg、jobs、&、 ctrl+z---系统任务

    系统任务有关的命令   一.& 这个用在一个命令的最后,可以把这个命令放到后台执行   二.ctrl + z 可以将一个正在前台执行的命令放到后台,并且暂停   一和二的区别(&放入后 ...

  4. dp水题

    hdu 2084: #include <stdio.h> #include <iostream> #include <string.h> using namespa ...

  5. Asp中JSON的使用

    我对asp全然不懂,因为须要使用json的结构,就研究了一下asp的json的使用,拼接一个json的字符串. 測试用例中使用到了一个lib文件: Json_2.0.3.asp <% ' ' V ...

  6. div的标准盒模型和怪异盒模型

    (1)标准盒模型 标准盒模型宽高不会被padding和margin撑开 (2)怪异盒模型 怪异盒模型宽高会被padding和margin撑开

  7. Python之字符串切片

    切片操作(slice)可以从一个字符串中获取子字符串(字符串的一部分).我们使用一对方括号.起始偏移量start.终止偏移量end 以及可选的步长step 来定义一个分片. 格式: [start:en ...

  8. 微信小程序实现tab页面切换功能

    wxml <scroll-view scroll-x="true" class="ip_tab_comtainer"> <view class ...

  9. [React] Render Text Only Components in React 16

    In this session we create a comment component to explore how to create components that only render t ...

  10. 【MySQL集群】——Java程序连接MySQL集群

    上篇简介了怎样在Windows环境下建立配置MySQL集群,这里用一个实现注冊功能的小Demo通过jdbc的方式连接到MySQL集群中. 外部程序想要远程连接到mysql集群,还须要做的一个操作就是设 ...