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的更多相关文章

  1. import { Subject } from 'rxjs/Subject';

    shared-service.ts import { Observable } from 'rxjs/Observable'; import { Injectable } from '@angular ...

  2. RxJS - Subject(转)

    Observer Pattern 观察者模式定义 观察者模式又叫发布订阅模式(Publish/Subscribe),它定义了一种一对多的关系,让多个观察者对象同时监听某一个主题对象,这个主题对象的状态 ...

  3. [RxJS] Subject basic

    A Subject is a type that implements both Observer and Observable types. As an Observer, it can subsc ...

  4. [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 ...

  5. [RxJS] Add debug method to Observable in TypeScript

    Observable.prototype.debug = function(message: any) { return this.do( (next) => { if(!environment ...

  6. rxjs——subject和Observable的区别

    原创文章,转载请注明出处 理解 observable的每个订阅者之间,是独立的,完整的享受observable流动下来的数据的. subject的订阅者之间,是共享一个留下来的数据的 举例 这里的cl ...

  7. RxJS之Subject主题 ( Angular环境 )

    一 Subject主题 Subject是Observable的子类.- Subject是多播的,允许将值多播给多个观察者.普通的 Observable 是单播的. 在 Subject 的内部,subs ...

  8. [RxJS] Reusable multicasting with Subject factories

    The way we use publish() (or multicast with an RxJS Subject) makes the shared Observable not reusabl ...

  9. 【Rxjs】 - 解析四种主题Subject

    原文地址: https://segmentfault.com/a/1190000012669794 引言 开发ngx(angular 2+)应用时,基本上到处都会用到rxjs来处理异步请求,事件调用等 ...

随机推荐

  1. Centos7下nginx的安装与配置

    说明:软件安装的基础目录路径:/usr/local 所以下载软件的时候切换到此目录下下载直接解压即可 1.安装gcc gcc-c++依赖包 yum install -y gcc gcc-c++ 2.下 ...

  2. 二、SpringBoot基础配置

    目录 2.1 @SpringBootApplication 2.3 服务器配置 2.4 修改启动banner 小结 2.1 @SpringBootApplication 从上篇文章中知道@Spring ...

  3. python实战项目 — 爬取 校花网图片

    重点: 1.  指定路径创建文件夹,判断是否存在 2. 保存图片文件 # 获得校花网的地址,图片的链接 import re import requests import time import os ...

  4. python基础_mysql建表、编辑、删除、查询、更新

    1.建一张学生表 包含(id,name,age,sex)2.增加四条数据3.查询表中sex为男的数据4.删除id =3的数据,5.将sex为女的,修改为男 create: CREATE TABLE d ...

  5. [CodeChef-ANUDTQ] Dynamic Trees and Queries

    类似维护括号序列,给每个点建两个点,然后所有操作都能轻松支持了.注意sum和lastans是long long. #include<cstdio> #include<algorith ...

  6. Centos 7 添加开机启动

    1.添加启动服务 添加docker开机启动服务 [root@localhost ~]# systemctl enable docker.serviceCreated symlink from /etc ...

  7. C#解压、压缩高级用法

    压缩:(可以吧要排除的文件去掉) /// <summary> /// 压缩文件夹 /// </summary> /// <param name="folder& ...

  8. python3--说简单也不简单的排序算法

    在刚开始接触算法时,我们可能一脸懵,不知从何处下手,尤其是现在使用的语言五花八门,各种语言的实现又不尽相同,所以,在这种情况下,千万不能迷失了自己,掌握了算法的原理,就像解数学公式一样,定理给你了,仔 ...

  9. 11.15java实习生面试总结

    坐了两个小时的车,到了面试地点面了十五分钟左右就结束了,心里有一点难受,不过这也是刚开始,后面的路还长着呢,所以先把面试官问的题目记录下来. 1.C语言能否跨平台? 虽然我面的是java实习生,但是因 ...

  10. Steam之两个list间交集、并集、差集

    public static void main(String[] args) { List<String> list1 = new ArrayList(); list1.add(" ...