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. Python-16-继承、封装、多态

    一.继承 1. 概念 继承是一种创建新类的方式,新建的类可以继承一个或多个父类(python支持多继承),父类又可称为基类或超类,新建的类称为派生类或子类. 子类会“”遗传”父类的属性,从而解决代码重 ...

  2. 12 IO流(九)——装饰流 BufferedInputStream/OutputStream

    我们按功能可以将IO流分为节点流与处理流 节点流:可以直接从数据源或目的地读写数据 处理流(装饰流):不直接连接到数据源或目的地,是其他流(必须包含节点流)进行封装.目的主要是简化操作和提高性能. B ...

  3. 【Linux】Linux目录结构及详细介绍

    00. 目录 01. 常用目录介绍 /:根目录,位于Linux文件系统目录结构的顶层,一般根目录下只存放目录,不要存放文件,/etc./bin./dev./lib./sbin应该和根目录放置在一个分区 ...

  4. OpenJDK自动安装脚本 InstallOpenJDK.vbs

    Oracle JDK 要收费了,Open JDK没有安装包,只有Zip,写了个安装脚本 InstallOpenJDK.vbs Rem ********************************* ...

  5. 使用 Issue 管理软件项目详解

    文章来源:http://www.ruanyifeng.com/blog/2017/08/issue.html 软件开发(尤其是商业软件)离不开项目管理,Issue 是最通用的管理工具之一. 本文介绍 ...

  6. es6新特性-解构表达式、Lambda表达式、局部变量及map/reduce方法

    循环内的变量在循环外可见,不合理: let定义的变量是局部变量: const修饰的是常量,不允许再次修改,类似于java中的static: 解构表达式:

  7. 摘要 - Digest

    首先从md5说起,一般新进入开发行业最先接触的就是md5了,md5本质上是一个hash(谐音:哈希)算法,可以从一个大文件信息中提取出一小段信息,叫提取摘要,有的地方也有提取指纹这种说法,其实指纹这个 ...

  8. go 学习笔记(4) package

    package name 尽量与目录名称一样 package name: 表示代码文件所属的包

  9. Linux守护进程编写指南

    Linux守护进程编写指南 守护进程(Daemon)是运行在后台的一种特殊进程.它独立于控制终端并且周期性地执行某种任务或等待处理某些发生的事件.守护进程是一种很有用的进 程.Linux的大多数服务器 ...

  10. node-red 使用 创建第一个流程

    前言 这只是一个简单的示例,具体详细文档去官网查看 官网指南:https://nodered.org/docs/user-guide/ 打开浏览器,进入编辑器页面:http://localhost:1 ...