[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 ...
随机推荐
- 一个小的程序--实现中英文切换(纯css)
<!doctype html><html lang="en"> <head> <meta charset="UTF-8" ...
- java开发的web下载大数据时的异常处理
同事用java开发了一个系统,其中有一个功能是下载大约10万笔数据到Excel中.当上线后,很多用户反映下载数据量大的时候就不能成功,但有时可以,所以结论就是系统不稳定,这个问题拖了很久没有解决. 在 ...
- python 下的数据结构与算法---4:线形数据结构,栈,队列,双端队列,列表
目录: 前言 1:栈 1.1:栈的实现 1.2:栈的应用: 1.2.1:检验数学表达式的括号匹配 1.2.2:将十进制数转化为任意进制 1.2.3:后置表达式的生成及其计算 2:队列 2.1:队列的实 ...
- 关于html控件和服务器控件摁回车后提交按钮的问题
今天做项目用到,项目是一个洗车系统,刷卡后在焦点出自动触发回车键事件,如,一个文本框,把焦点放入,刷一下卡,文本框自动获取卡号,同时触发回车事件,(就像银行办卡一样),发现刷卡后页面刷新后并没有执行按 ...
- Jenkins学习之——(1)Jenkins的安装与配置
1.最近公司要求做自动化部署,于是自学了jenkins.这个参考书很少,网上的文章也讲得很模糊,于是打算把自己学习东西记下来,希望对大家有所帮助. 一.jenkins的安装 到jenkins官网(ht ...
- Xcode itunes完美打包api方法
转:http://bbs.csdn.net/topics/390948190 Xcode6 itunes完美打包api 方法! 特点轻盈小巧,方便快捷!
- java下properties属性文件操作
package cn.stat.p1.file; import java.io.File; import java.io.FileInputStream; import java.io.FileNot ...
- [Leetcode][016] 3Sum Closest (Java)
题目: https://leetcode.com/problems/3sum-closest/ [标签]Array; Two Pointers [个人分析] 这道题和它的姊妹题 3Sum 非常类似, ...
- javascript改变背景/字体颜色(Through the javascript to change the background and font color)
鼠标移动到.移出DIV时修改DIV的颜色: 1.Change the font and Div background color--function <div style="width ...
- Flask学习记录之Flask-Admin
相信用过Django框架的都不会忘记它强大的Admin功能,Flask-admin是一款能够与Django Admin所媲美的扩展,能够快速创建Web管理界面,实现了用户.文件增删改查等常用功能:也可 ...