[RxJS] Updating Data with Scan
You often need to update the data flowing through the stream with custom logic based on what you need to output. This lesson covers how to use scan
for collecting and updating the outputs as your stream progresses.
const Observable = Rx.Observable; const startButton = document.querySelector('#start');
const stopButton = document.querySelector('#stop'); const start$ = Observable.fromEvent(startButton, 'click');
const interval$ = Observable.interval(1000);
const stop$ = Observable.fromEvent(stopButton, 'click'); const intervalThatStop$ = interval$.takeUntil(stop$); start$.switchMapTo(intervalThatStop$)
.subscribe( (x) => {
console.log(x);
})
What we want is it should remeber the current state, so that, next time when we start again, it can use our current state:
const Observable = Rx.Observable; const startButton = document.querySelector('#start');
const stopButton = document.querySelector('#stop'); const start$ = Observable.fromEvent(startButton, 'click');
const interval$ = Observable.interval(1000);
const stop$ = Observable.fromEvent(stopButton, 'click'); const intervalThatStops$ = interval$
.takeUntil(stop$); start$
.switchMapTo(intervalThatStops$)
.scan( (acc) => {
return Object.assign(acc, {count: acc.count + 1})
}, {
count: 0
})
.subscribe((x)=> console.log(x));
[RxJS] Updating Data with Scan的更多相关文章
- [Angular 2] Managing State in RxJS with StartWith and Scan
The scan operator in RxJS is the main key to managing values and states in your stream. Scan behaves ...
- MySQL Crash Course #11# Chapter 20. Updating and Deleting Data
INDEX Updating Data The IGNORE Keyword Deleting Data Faster Deletes Guidelines for Updating and Dele ...
- RxJS v6 学习指南
为什么要使用 RxJS RxJS 是一套处理异步编程的 API,那么我将从异步讲起. 前端编程中的异步有:事件(event).AJAX.动画(animation).定时器(timer). 异步常见的问 ...
- rxjs与vue
原创文章,转载请注明出处 使用vue-rx插件将vue和rxjs联系起来 在main.js中将vue-rx注入vue中 import Vue from 'vue' import App from '. ...
- [Angular] Upgrading to RxJS v6
This is just a learning blog post, check out the talk. 1. Custom pipeable operators: Custom pipeable ...
- Create the Data Access Layer
https://docs.microsoft.com/en-us/aspnet/web-forms/overview/getting-started/getting-started-with-aspn ...
- 响应式js库——rxjs
原文地址:https://rxjs.dev/guide/overview 简介 RxJS 是组合异步以及基于事件的使用可观察者序列的程序类库.它提供一个核心类型,Observable,附属类型(Obs ...
- Data Management and Data Management Tools
Data Management ObjectivesBy the end o this module, you should understand the fundamentals of data m ...
- Building Applications with Force.com and VisualForce(Dev401)(十五):Data Management: Data management Overview
Dev401-016:Data Management: Data management Overview Course Objectives1.List typical data management ...
随机推荐
- Codeforces 328A-IQ Test(数列)
A. IQ Test time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
- Java基础知识强化37:StringBuffer类之StringBuffer的构造方法
1. StringBuffer的构造方法: (1)StringBuffer(): (2)StringBuffer(CharSequence seq): (3)StringBuffer(int capa ...
- overcast
关于一个利用relative的简单布局,firefox上出现一点问题,暂且不明原因 firefox的 chrome的 代码记录 <!DOCTYPE html> <html lang= ...
- java 位运算权限管控(转载)
这里笔者介绍一种很常用,也比较专业的权限控制思路.这里用java语言描述,其实都差不多的.要换成其他的语言主,自己转一下就可以了.为了方便起见,我们这里定义a^b为:a的b次方.这里,我们为每一个操作 ...
- hihoCoder挑战赛14 A,B,C题解
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud 题目1 : 不等式 时间限制:10000ms 单点时限:1000ms 内存限制:2 ...
- window下Slik SVN的安装配置
我相信各位都应该对SVN不会陌生吧,我相信绝大多数人都使用过,但是并不是人人都自己配置过SVN服务器.下面就是我配置SVN服务器的步骤,以及在配置过程中碰见的一些问题,在此记录,希望对你有所帮助. 安 ...
- Mysql 卡死的处理办理
使用用show processlist 命令进去数据库查 或者用phpMyAdmin查也可以 .
- 10 条建议让你创建更好的 jQuery 插件
在开发过很多 jQuery 插件以后,我慢慢的摸索出了一套开发jQuery插件比较标准的结构和模式.这样我就可以 copy & paste 大部分的代码结构,只要专注最主要的逻辑代码就行了. ...
- 使用PHP解压文件Unzip
这是一个非常方便的PHP函数从.zip文件解压缩文件.它有两个参数:第一个是压缩文件的路径和第二 function unzip_file($file, $destination) { // creat ...
- jave script 经典排序 - -冒泡排序
有 5个数字,2:3:1:0:4,按大小顺序排列 <script type="text/javascript"> var arr =new Array(); arr . ...