[RxJS] AsyncSubject and ReplaySubject - Learn the Differences
We can use Subject as Observable and Observer:
// Subject should be only used to emit value for private
// Using subject as an Observer
const subject = new Subject(); subject.next(1);
subject.next(2);
subject.next(3); // Using subject as an Observable
const source$ = subject.asObservable(); source$.subscribe(console.log);
AsyncSubject:
AsyncSubject only subscribe the latest value before subject complete.
const as = new AsyncSubject(); as.next(1);
as.next(2);
as.next(3);
as.complete(); // it is necessary to complete it in order to get last value const source$ = as.asObservable(); source$.subscribe(console.log); //
If we don't call 'as.complete()', we won't get any value in the console.
Different from AsyncSubject, we have ReplySubject:
It doesn't need to call complete() in order to emit value. And it emit all the values from every beginning.
const rs = new ReplaySubject(); rs.next(1);
rs.next(2);
rs.next(3); const source$ = as.asObservable(); source$.subscribe(console.log); // 1,2,3
[RxJS] AsyncSubject and ReplaySubject - Learn the Differences的更多相关文章
- [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 ins ...
- [RxJS] AsyncSubject
AsyncSubject emit the last value of a sequence only if the sequence completed. This value is then ca ...
- RxJS之AsyncSubject
AsyncSubject 是另一个 Subject 变体,只有当 Observable 执行完成时(执行 complete()),它才会将执行的最后一个值发送给观察者. import { Compon ...
- What are the differences between struct and class in C++?
Question: This question was already asked in the context of C#/.Net. Now I'd like to learn the diffe ...
- Angular全局数据管理与同步更新
自定义实现angular中数据的状态管理,如有不妥请指正 一.先介绍一下rxjs中subject: Import {subject}from’rxjs’ Subject 数据的订阅与分发,结合报刊的发 ...
- Difference between ref and out parameters
Original link: http://www.dotnet-tricks.com/Tutorial/csharp/K0Hb060414-Difference-between-ref-and-ou ...
- Using FireMonkey Layouts
FireMonkey has many layout controls to choose from. Come learn the differences and how to use them t ...
- OrientDB入门(1)Getting Started
Running OrientDB the First Time First, download and extract OrientDB by selecting the appropriate pa ...
- 学习笔记:Rick's RoTs -- Rules of Thumb for MySQL
Table of Contents SELECTs -- do's and don'tsINDEXingENGINE DifferencesOptimizations, and notPARTITIO ...
随机推荐
- ACM_迟到的祝福(四)
迟到的祝福(四) Time Limit: 2000/1000ms (Java/Others) Problem Description: 据说前几天是雁来师姐的生日,作为一个15级的小鲜肉A,没及时给师 ...
- servlet范围:数据共享
数据共享: 请求转发:request.getDispatcher("相对路径").forward(request,response) 重定向:response.sendRedire ...
- 【LeetCode】 -- 68.Text Justification
题目大意:给定一个数组容器,里面存有很多string: 一个int maxWith.让你均匀安排每一行的字符串,能够尽可能的均匀. 解题思路:字符串+贪心.一开始想复杂了,总觉的题意描述的不是很清楚, ...
- Linq学习(五)-多表连接
本将主要介绍 内连接与 外连接 1.join Linq to sql from a in Blog_Users join b in Blog_UserInfo on a.UserId equals b ...
- Excel文件导入导出
/** * 导入Excel文件数据 * * @param file 将要导入的Excel文件 * @param fileCheckKeyWord 用于判断导入文件是否 ...
- 【转】Java 集合系列01之 总体框架
Java集合是java提供的工具包,包含了常用的数据结构:集合.链表.队列.栈.数组.映射等.Java集合工具包位置是java.util.*Java集合主要可以划分为4个部分:List列表.Set集合 ...
- Manacher 学习笔记
\(\\\) \(Manacher\) 一种常用的字符串算法,用于处理一些回文字符相关的问题. 回文串:从前向后和从后向前输出一致. 回文中心:以这里开始,每次向外左右各扩展一个字符得到的回文串的中心 ...
- Python爬取贴吧中的图片
#看到贴吧大佬在发图,准备盗一下 #只是爬取一个帖子中的图片 1.先新建一个scrapy项目 scrapy startproject TuBaEx 2.新建一个爬虫 scrapy genspider ...
- python 分割文件、组合文件
import glob big_file = open('index.sql', 'rb') bak_file = 'index_bak' i = 1 while True: chunk = big_ ...
- Windows2008 Server 常规设置及基本安全策略
一.系统及程序 1.屏幕保护与电源 桌面右键--〉个性化--〉屏幕保护程序屏幕保护程序 选择无更改电源设置 选择高性能选择关闭显示器的时间 关闭显示器 选 从不 保存修改 2.安装IIS 管理工具-- ...