[RxJS] Subject asObservable() method
You can create your own state store, not using any state management libraray.
You might have seen the partten: People create a Subject, then use abObservable() method.
export class State {
private prevState: INEO[];
private neoStoreSubject: BehaviorSubject<INEO[]>;
neoStore$: Observable<INEO[]>; protected constructor() {
this.neoStoreSubject = new BehaviorSubject([]);
this.neoStore$ = this.neoStoreSubject.asObservable();
} ...
}
Main reason for that is, we want to keep:
this.neoStoreSubject = new BehaviorSubject([]);
as private, we don't want any component can call .next() method to update store. The job for updating store should only happen in 'State' class.
// State class
setNeoStore(neoList: INEO[]) {
this.setPrevState();
this.neoStoreSubject.next(neoList);
this.dismissError();
}
For component, we can subscribe this.neoStore$. it can only receive the data, but not update the store directly.
// From Component biggerFasterNeo$ = this.data.neoStore$.pipe(
filter(neoList => !!neoList === true),
map(neoList => neoList.filter(neo => {
if (neo.estimated_diameter > 0.5 || neo.relative_velocity > ) {
return neo;
}
}))
);
For component
[RxJS] Subject asObservable() method的更多相关文章
- import { Subject } from 'rxjs/Subject';
shared-service.ts import { Observable } from 'rxjs/Observable'; import { Injectable } from '@angular ...
- RxJS - Subject(转)
Observer Pattern 观察者模式定义 观察者模式又叫发布订阅模式(Publish/Subscribe),它定义了一种一对多的关系,让多个观察者对象同时监听某一个主题对象,这个主题对象的状态 ...
- [RxJS] Subject basic
A Subject is a type that implements both Observer and Observable types. As an Observer, it can subsc ...
- [RxJS] Subject: an Observable and Observer hybrid
This lesson teaches you how a Subject is simply a hybrid of Observable and Observer which can act as ...
- [RxJS] Add debug method to Observable in TypeScript
Observable.prototype.debug = function(message: any) { return this.do( (next) => { if(!environment ...
- rxjs——subject和Observable的区别
原创文章,转载请注明出处 理解 observable的每个订阅者之间,是独立的,完整的享受observable流动下来的数据的. subject的订阅者之间,是共享一个留下来的数据的 举例 这里的cl ...
- RxJS之Subject主题 ( Angular环境 )
一 Subject主题 Subject是Observable的子类.- Subject是多播的,允许将值多播给多个观察者.普通的 Observable 是单播的. 在 Subject 的内部,subs ...
- [RxJS] Reusable multicasting with Subject factories
The way we use publish() (or multicast with an RxJS Subject) makes the shared Observable not reusabl ...
- 【Rxjs】 - 解析四种主题Subject
原文地址: https://segmentfault.com/a/1190000012669794 引言 开发ngx(angular 2+)应用时,基本上到处都会用到rxjs来处理异步请求,事件调用等 ...
随机推荐
- A Simple Question of Chemistry
#include<stdio.h> int main() { int i, l; ]; ]; l = ; ) { l++; } ; a[i]!= && i<l; i+ ...
- tkinter学习笔记_04
8.勾选项 checkbutton import tkinter as tk root = tk.Tk() root.title("xxx") root.geometry('200 ...
- [LOJ2065] [SDOI2016]模式字符串
题目链接 洛谷:https://www.luogu.org/problemnew/show/P4075 LOJ:https://loj.ac/problem/2065 Solution 这种题看起来就 ...
- Different Subsets For All Tuples CodeForces - 660E (组合计数)
大意: 定义$f(a)$表示序列$a$本质不同子序列个数. 给定$n,m$, 求所有长$n$元素范围$[1,m]$的序列的$f$值之和. 显然长度相同的子序列贡献是相同的. 不考虑空串, 假设长$x$ ...
- 转:深入浅出Java垃圾回收机制
原文链接:http://www.importnew.com/1993.html 对于Java开发人员来说,了解垃圾回收机制(GC)有哪些好处呢?首先可以满足作为一名软件工程师的求知欲,其次,深入了解G ...
- docker的学习总结
一 docker的8个使用场景1.简化配置虚拟机的最大好处是能在你的硬件设施上运行各种配置不一样的平台(软件, 系统), Docker在降低额外开销的情况下提供了同样的功能. 它能让你将运行环境和配置 ...
- IdentityServer4使用OpenIdConnect实现单点登录
接上一篇:IdentityServer4实现OAuth2.0四种模式之授权码模式 前面写的四种OAuth2.0实现模式只涉及到IdentityServer4的OAuth2.0特性,并没有涉及到OenI ...
- Java内存模型JMM简单分析
参考博文:http://blog.csdn.net/suifeng3051/article/details/52611310 http://www.cnblogs.com/nexiyi/p/java_ ...
- robot framework笔记(二):在RF中自定义chrome启动参数
(一)在RF中自定义chrome启动参数 这里主要是实现下面2个功能 1.禁用chrome正受自动测试软件控制的提示 2.设置默认的下载路径(一些导出.下载类的功能,将文件下载到指定路径下) 自定义一 ...
- spark 机器学习 决策树 原理(一)
1.什么是决策树 决策树(decision tree)是一个树结构(可以是二叉树或者非二叉树).决策树分为分类树和回归树两种,分类树对离散变量做决策树,回归树对连续变量做决策树. 其中每个非叶节点表示 ...