A ReplaySubject caches its values and re-emits them to any Observer that subscrubes late to it. Unlike with AsyncSubject, the sequence doesn't need to be completed for this to happen.

The normal subject won't emit the value before subscribe.

var subject = new Rx.Subject();

subject.onNext();

subject.subscribe(
(x)=>{
console.log("Receive the value: " + x);
}
) subject.onNext();
subject.onNext(); /*
"Receive the value: 2"
"Receive the value: 3"
*/

The ReplaySubject will cache the values:

var subject = new Rx.ReplaySubject();

subject.onNext();

subject.subscribe(
(x)=>{
console.log("Receive the value: " + x);
}
) subject.onNext();
subject.onNext(); /*
"Receive the value: 1"
"Receive the value: 2"
"Receive the value: 3"
*/

[RxJS] ReplaySubject的更多相关文章

  1. [RxJS] ReplaySubject with buffer

    A BehaviorSubject can remember the latest value emitted, but what if we wanted Observer B to see all ...

  2. RxJS核心概念之Subjet在angular2+上的应用

    Subject,在RxJS中是一类特殊的Observable(可观察对象),它可像多个Observer(观察者)推送值.每一个Subject也可以作为Observer(观察者) Subject同样也是 ...

  3. Angular全局数据管理与同步更新

    自定义实现angular中数据的状态管理,如有不妥请指正 一.先介绍一下rxjs中subject: Import {subject}from’rxjs’ Subject 数据的订阅与分发,结合报刊的发 ...

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

  5. [译]RxJS 5.X基础篇

    欢迎指错与讨论 : ) 当前RxJS版本:5.0.0-beta.10.更详细的内容尽在RxJS官网http://reactivex.io/rxjs/manual/overview.html.文章比较长 ...

  6. angular2 学习笔记 ( rxjs 流 )

    RxJS 博大精深,看了好几篇文章都没有明白. 范围牵扯到了函数响应式开发去了... 我对函数式一知半解, 响应式更是第一次听到... 唉...不过日子还是得过...混着过先呗 我目前所理解的很浅,  ...

  7. RXJS Observable的冷,热和Subject

    一.Observable的冷和热 Observable 热:直播.所有的观察者,无论进来的早还是晚,看到的是同样内容的同样进度,订阅的时候得到的都是最新时刻发送的值. Observable 冷:点播. ...

  8. RxJS v6 学习指南

    为什么要使用 RxJS RxJS 是一套处理异步编程的 API,那么我将从异步讲起. 前端编程中的异步有:事件(event).AJAX.动画(animation).定时器(timer). 异步常见的问 ...

  9. RxJS - Subject(转)

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

随机推荐

  1. [转] web.xml文件详解

    转自:http://www.cnblogs.com/hellojava/archive/2012/12/28/2835730.html 前言:一般的web工程中都会用到web.xml,web.xml主 ...

  2. StrutsPrepareAndExecuteFilter的作用

    FilterDispatcher是早期struts2的过滤器,后期的都用StrutsPrepareAndExecuteFilter了,如 2.1.6.2.1.8.StrutsPrepareAndExe ...

  3. JS中图片的放大缩小没反应

    这段代码无反应: 代码如下: <script type="text/javascript"> onload = function () { document.getEl ...

  4. Delphi word

    [转载]在Delphi中使用CreateOleObject方法 (2011-08-24 14:20:47) 转载▼ 标签: 转载   原文地址:在Delphi中使用CreateOleObject方法作 ...

  5. java语言实现简单接口工具--粗简版

    2016注定是变化的一年,忙碌.网红.项目融资失败,现在有点时间整整帖子~~ 目标: 提高工作效率与质量,能支持平台全量接口回归测试与迭代测试也要满足单一接口联调测试. 使用人员: 测试,开发 工具包 ...

  6. WebService的发布及客户端的调用

    一.目录 1.JAX-WS发布WebService 1.1 创建一个简单的WS 1.2 打包部署和发布 2.CXF+Spring发布WebService 3.客户端的调用方式 二.正文 1. JAX- ...

  7. 二维坐标的平移,旋转,缩放及matlab实现

    本文结合matlab 软件解释二维坐标系下的平移,旋转,缩放 首先确定点在二维坐标系下的表达方法,使用一个1*3矩阵: Pt = [x,y,1] 其中x,y 分别为点的X,Y坐标,1为对二维坐标的三维 ...

  8. MFC 文件操作

    MFC中文件的建立 在操作系统中,文件是放在一定的目录下,在创建以及操作文件以前,我们要查看文件要保存的目录有没有存在,如果不存在要创建.这就要用到GetFileAttributes()和Create ...

  9. 6.2 CUDA streams

    stream是什么 nivdia给出的解释是:A sequence of operations that execute in issue-order on the GPU.  可以理解成在GPU上执 ...

  10. Spark环境的搭建与运行

    Spark本地安装与配置 下载spark后解压,并cd到解压目录下 运行实例程序测试是否一切正常 ./bin/run-example org.apache.spark.examples.SparkPi ...