[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来处理异步请求,事件调用等 ...
随机推荐
- watchdog监控文件变化使用总结——转载
原文链接地址:https://blog.csdn.net/xufive/article/details/93847372 概述 首先声明,本文讨论的 watchdog,不是单片机里的 watchdog ...
- 【转】用chrome滚动截屏
用开发者常用的网站chrome,打开需要截屏的网页 使用快捷键组合:Alt + Command + I (Mac) || Ctrl + Shift + I (Windows) 使用快捷键组合来打开命令 ...
- tkinter学习笔记_04
8.勾选项 checkbutton import tkinter as tk root = tk.Tk() root.title("xxx") root.geometry('200 ...
- 二进制方式安装Kubernetes 1.14.2高可用详细步骤
00.组件版本和配置策略 组件版本 Kubernetes 1.14.2 Docker 18.09.6-ce Etcd 3.3.13 Flanneld 0.11.0 插件: Coredns Dashbo ...
- python 直角图标生成圆角图标
参考链接:https://stackoverflow.com/questions/11287402/how-to-round-corner-a-logo-without-white-backgroun ...
- 【面试突击】- SpringMVC那些事(一)
1.什么是Spring MVC ?简单介绍下你对springMVC的理解? Spring MVC是一个基于MVC架构的用来简化web应用程序开发的应用开发框架,它是Spring的一个模块,无需中间整合 ...
- ZK中使用JS读取客户端txt文件内容问题
最近写一个需求时遇到一个问题,用户需要通过点击一个按钮直接读取他自己电脑上D盘的一个txt文件内容显示到页面,因为项目现在是用ZK写的.我对于ZK也是刚刚了解不就,很多都还不是很熟.起初我是想用io流 ...
- Jmeter学习笔记(九)——响应断言
Jmeter中又一个元件叫断言,用于检查测试中得到的响应数据等是否符合预期.断言又13种,目前在使用过程中使用到的是响应断言. 有时候请求成功了并不代表测试通过,还要看影响返回的内容是否符合预期的结果 ...
- elementUI——主题定制
需求: 设计三套主题色+部分图标更换: 实现方式汇总: 1.传统做法,生成多套css主题包,切换link引入路径切换href实现,参考网站:http://jui.org/: <link id=& ...
- linux下安装grpc插件 (c++和go语言)
在debian/ubuntu系统下,需要做如下准备操作: $ [sudo] apt-get install build-essential autoconf libtool pkg-config 如果 ...