RxJS之AsyncSubject
AsyncSubject 是另一个 Subject 变体,只有当 Observable 执行完成时(执行 complete()),它才会将执行的最后一个值发送给观察者。
import { Component, OnInit } from '@angular/core';
import { AsyncSubject } from 'rxjs/AsyncSubject';
@Component({
selector: 'app-subject',
templateUrl: './subject.component.html',
styleUrls: ['./subject.component.css']
})
export class SubjectComponent implements OnInit {
constructor() { }
ngOnInit() {
const subject: AsyncSubject<string> = new AsyncSubject<string>();
subject.next('Leo');
subject.subscribe( // 观察者A订阅
(val: string) => {
console.log(`observerA: ${val}`);
}
);
subject.next('Raph');
subject.subscribe( // 观察者B订阅
(val: string) => {
console.log(`observerB: ${val}`);
}
);
subject.next('Mikey');
subject.next('Don');
subject.complete();
}
}

RxJS之AsyncSubject的更多相关文章
- [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 and ReplaySubject - Learn the Differences
We can use Subject as Observable and Observer: // Subject should be only used to emit value for priv ...
- [译]RxJS 5.X基础篇
欢迎指错与讨论 : ) 当前RxJS版本:5.0.0-beta.10.更详细的内容尽在RxJS官网http://reactivex.io/rxjs/manual/overview.html.文章比较长 ...
- RxJS v6 学习指南
为什么要使用 RxJS RxJS 是一套处理异步编程的 API,那么我将从异步讲起. 前端编程中的异步有:事件(event).AJAX.动画(animation).定时器(timer). 异步常见的问 ...
- RxJS - Subject(转)
Observer Pattern 观察者模式定义 观察者模式又叫发布订阅模式(Publish/Subscribe),它定义了一种一对多的关系,让多个观察者对象同时监听某一个主题对象,这个主题对象的状态 ...
- RxJS库
介绍 RxJS是一个异步编程的库,同时它通过observable序列来实现基于事件的编程.它提供了一个核心的类型:Observable,几个辅助类型(Observer,Schedulers,Subje ...
- rxjs的世界
rxjs学习了几个月了,看了大量的东西,在理解Observable的本文借鉴的是渔夫的故事,原文,知识的主线以<深入浅出rxjs>为主,动图借鉴了rxjs中文社区翻译的文章和国外的一个动图 ...
- [RxJS] Multicasting shortcuts: publish() and variants
Because using multicast with a new Subject is such a common pattern, there is a shortcut in RxJS for ...
随机推荐
- FDQuery 怎么能插入NULL参数
[FireDAC][Phys][MSSQL]-335. Parameter [fieldAA] data type is unknown. Hint: specify TFDParam.DataTyp ...
- ActiveMQ 学习
链接: http://www.cnblogs.com/zhuxiaojie/p/5564187.html#autoid-1-0-0
- curl 超时设置<转>
PHP cURL 的超时设置有两个 CURLOPT_CONNECTTIMEOUT 和 CURLOPT_TIMEOUT,他们的区别是: CURLOPT_CONNECTTIMEOUT 用来告诉 PHP 在 ...
- jsp不解析el表达式,不识别jstl标签,找不到http://java.sun.com/jsp/jstl/core
问题描述: jsp页面中el表达式,例如:${pageContext.request.contextPath},原样呈现,未被解析. 解决方案: 为jsp页添加page指令如下: <%@ pag ...
- ORACLE表空间操作实例
本文主要介绍oracle表空间常见的操作实例,包括创建.查询.增加.删除.修改.表空间和数据文件常用的数据字典和动态性能视图包括v$dbfile.v$datafile.v$tempfile.dba_s ...
- 今天学习到的几条shell技巧
1.获取某个进程的进程号 PID=`ps aux | grep 进程名 | grep -v "grep" | awk '{print $2}'` 2.获取某个进程的CPU(同理可获 ...
- 免費查看SQL PLAN的工具 - SQL Sentry Plan Explorer
今天 Terry大 介紹給小弟這個 SQL Sentry Plan Explorer 工具,可以用來看SQL Plan. 什麼? 用SSMS看不就很清楚了嗎? 這個Tool有把SQL Plan幫我們整 ...
- jQuery中事情的动态绑定
在jQuery的开发过程中,我们往往需要处理各种事件,例如click(),hover()等.在jQuery的API中,我们可以使用不同的方法来将这些事件绑定到特定的元素中.今天这篇文章中,我们将要介绍 ...
- week05 05restful api
和第一个项目一样 然后去App.js注册一下 但是呢 新闻是写死在 现在主要输调通前端client和后端server 持续获取新闻 至于真假先不考虑 下面我们回到前端NewsPanel 这个reque ...
- Hibernate 再接触 关系映射 一对一单向外键联合主键关联
例子: Husband.java package com.bjsxt.hibernate; import javax.persistence.Entity; import javax.persiste ...