[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 ...
随机推荐
- 使用Visual Studio Code + Node.js搭建TypeScript开发环境
Visual Studio Code搭建Typescript开发环境 —— 相关文章: http://www.cnblogs.com/sunjie9606/p/5945540.html [注意:这里仅 ...
- 上传Android代码到gerrit服务器
1. 配置default.xml default.xml是跟Android代码配套的,可参考google Android源码下的default.xml(.repo/manifests/default. ...
- [转]mysql的约束
转自:http://blog.csdn.net/kqygww/article/details/8882990 MySQL中约束保存在information_schema数据库的table_constr ...
- MVC系列学习(四)-初识Asp.NetMVC框架
注:本文章从伯乐那盗了两张图,和一些文字: 1.MVC设计模式 与 Asp.Net Mvc框架 a.MVC设计模式 MVC设计模式 是一种 软件设计模式,将业务逻辑 与 界面显示 分离,并通过某种方式 ...
- 6.11---swagger文件上传的写法【照着写就行了,主要是需要声明contentType未mutilpart---如果不设置这个,就无法识别文件的】
MultipartFile 是直接接收前台传过来的文件,File是抽象出来的文件对象,用来表示文件,一般操作都是操作的File,所以需要将MultipartFile转为File controller写 ...
- xampp中localhost与DreamWaver站点设置问题
作为一个初学者,在DreamWaver中配置web服务器用于本地测试,中间碰到了好多问题,百度答案模糊不清,自己摸索出来,把自己碰到的,易错的地方做个总结. step1 : 安装xampp(安装位置记 ...
- HashMap , TreeMap , TreeMap 默认排序
Java代码 import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; import java. ...
- utf-8与unicode是什么关系
简单来说: Unicode is a charset. ------Unicode 他就是一个字符集 UTF-8 is encoding style. --------UTF-8他就是一种编码方式, ...
- Centos 编译安装Haproxy
一.环境介绍 1.Centos6 2. haproxy-1.4.25.tar.gz 二.安装 $ curl -O http://haproxy.1wt.eu/download/1.4/src/hapr ...
- (转)分布式文件存储FastDFS(四)配置fastdfs-apache-module
http://blog.csdn.net/xingjiarong/article/details/50560605 在前边我们已经配置好了FastDFS的环境,但是此时的FastDFS还不能通过htt ...