[RxJS] Transformation operators: debounce and debounceTime
2024-08-24 07:38:11
Debounce and debounceTime operators are similar to delayWhen and delay, with the difference that they may drop some emissions. This lesson teaches you how debounce works and where is it useful, for instance when building a type-ahead UI.
debounceTime(number): wait for number millionseconds sclience:
var foo = Rx.Observable.interval(100).take(5); /*
--0--1--2--3--4|
debounceTime(1000) // delay
------------------------4|
*/ var result = foo.debounceTime(1000); result.subscribe(
function (x) { console.log('next ' + x); },
function (err) { console.log('error ' + err); },
function () { console.log('done'); },
); /*
"next 4"
"done"
*/
var foo = Rx.Observable.interval(100).take(5); /*
--0--1--2--3--4|
debounceTime(50) // delay
----0--1--2--3--4|
*/ var result = foo.debounceTime(50); result.subscribe(
function (x) { console.log('next ' + x); },
function (err) { console.log('error ' + err); },
function () { console.log('done'); },
); /*
"next 0"
"next 1"
"next 2"
"next 3"
"next 4"
"done"
*/
debounce( () => Observable):
var foo = Rx.Observable.interval(100).take(5); /*
--0--1--2--3--4|
debounceTime(1000) // delay
------------------------4|
*/ var result = foo.debounce(() =>
Rx.Observable.interval(1000).take(1)
); result.subscribe(
function (x) { console.log('next ' + x); },
function (err) { console.log('error ' + err); },
function () { console.log('done'); },
); /*
"next 4"
"done"
*/
最新文章
- C#类和接口、虚方法和抽象方法及值类型和引用类型的区别
- Xcode中iPhone iPad模拟器调整大小的方法
- How to install GSL on linux(ubuntu,centos,redhat)
- html5新特性:利用history的pushState等方法来解决使用ajax导致页面后退和前进的问题
- [POJ 3581]Sequence
- EntityFramework Core 2.0 Explicitly Compiled Query(显式编译查询)
- oracle空间索引
- boost::asio::spawn 将一统C++网络库
- SpriteBuilder中粒子发射器的reset on visibility toggle选项解释
- 监控MySQL或Web服务是否正常
- C++中string跨DLL失败解决途径
- 如何通过 Vue+Webpack 来做通用的前端组件化架构设计
- Hadoop概念学习系列之再谈hadoop集群里的本地模式、伪分布模式和全分布模式(三十七)
- Python入门 ---基础知识
- python3 调用 salt-api
- 冥想_ PHP抽奖程序概率算法
- sqlserver2008debug存储过程
- ADS中编译现存项目时常见错误:无法打开文件\…\…\2440init.o的解决办法
- Java-web-j2e学习建议路线【转】
- Android深入四大组件(六)Service的启动过程