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:

  1. var foo = Rx.Observable.interval(100).take(5);
  2.  
  3. /*
  4. --0--1--2--3--4|
  5. debounceTime(1000) // delay
  6. ------------------------4|
  7. */
  8.  
  9. var result = foo.debounceTime(1000);
  10.  
  11. result.subscribe(
  12. function (x) { console.log('next ' + x); },
  13. function (err) { console.log('error ' + err); },
  14. function () { console.log('done'); },
  15. );
  16.  
  17. /*
  18. "next 4"
  19. "done"
  20. */
  1. var foo = Rx.Observable.interval(100).take(5);
  2.  
  3. /*
  4. --0--1--2--3--4|
  5. debounceTime(50) // delay
  6. ----0--1--2--3--4|
  7. */
  8.  
  9. var result = foo.debounceTime(50);
  10.  
  11. result.subscribe(
  12. function (x) { console.log('next ' + x); },
  13. function (err) { console.log('error ' + err); },
  14. function () { console.log('done'); },
  15. );
  16.  
  17. /*
  18. "next 0"
  19. "next 1"
  20. "next 2"
  21. "next 3"
  22. "next 4"
  23. "done"
  24. */

debounce( () => Observable):

  1. var foo = Rx.Observable.interval(100).take(5);
  2.  
  3. /*
  4. --0--1--2--3--4|
  5. debounceTime(1000) // delay
  6. ------------------------4|
  7. */
  8.  
  9. var result = foo.debounce(() =>
  10. Rx.Observable.interval(1000).take(1)
  11. );
  12.  
  13. result.subscribe(
  14. function (x) { console.log('next ' + x); },
  15. function (err) { console.log('error ' + err); },
  16. function () { console.log('done'); },
  17. );
  18.  
  19. /*
  20. "next 4"
  21. "done"
  22. */

[RxJS] Transformation operators: debounce and debounceTime的更多相关文章

  1. [RxJS] Transformation operators: delay and delayWhen

    This lessons teaches about delay and delayWhen: simple operators that time shift. delay(number | dat ...

  2. [RxJS] Filtering operators: throttle and throttleTime

    Debounce is known to be a rate-limiting operator, but it's not the only one. This lessons introduces ...

  3. [RxJS] Transformation operator: repeat

    Operator repeat() is somewhat similar to retry(), but is not for handling operators. In this lesson ...

  4. [RxJS] Transformation operator: scan

    All of the combination operators take two or more observables as input. These operators may also be ...

  5. [RxJS] Filtering operators: takeLast, last

    Operators take(), skip(), and first() all refer to values emitted in the beginning of an Observable ...

  6. [RxJS] Filtering operators: take, first, skip

    There are more operators in the filtering category besides filter(). This lesson will teach how take ...

  7. [RxJS] Creation operators: interval and timer

    It is quite common to need an Observable that ticks periodically, for instance every second or every ...

  8. [RxJS] Creation operators: empty, never, throw

    This lesson introduces operators empty(), never(), and throw(), which despite being plain and void o ...

  9. Rxjs常用operators

    本文使用的是angular6内置的rxjs,版本号为6.3.3 concat 通过顺序地发出多个 Observables 的值将它们连接起来,一个接一个的. 参数: 名称 类型 属性 描述 other ...

随机推荐

  1. React 学习资源分享 菜鸟刚学5天 博客写的不多 不懂写博客的套路

    http://www.ruanyifeng.com/blog/2015/03/react.html 首先个人强烈推荐 阮一峰的React基础 细细过一遍,看得出大师的用心良苦 然后就开始看书般的过ht ...

  2. DEDECMS 猜你喜欢

      dede升级了5.7后,有个地方要求调用相关文章,于是写下  dede:likeart  标签却无法实现关联,显示的则是所有文章. 发现原来从5.5版开始已经替换了该标签,把模板中 likeart ...

  3. coder

    #include <iostream>#include <GL/glut.h>using std::cout;using std::endl;float windowWidth ...

  4. Python 学习笔记(3) - 控制流、函数

    控制流语句if.while.for.break.continue以上从最终作用效果来讲,同学过的其他语言没有什么不同.需要注意的只是语法,而Python 在语法上是如此让人赞叹和喜欢啊. 控制流语句的 ...

  5. PDF转图片 C# with Adobe API

    PDF转图片大概有十几种方式,褒贬不一,我就详细给大家说一下我认为效率最高的方式,使用Adobe官方的SDK 安装acrobat reader 9.0以上即可,勾选如下组件.

  6. 2016022602 - redis安装和启动

    redis安装 我使用的是ubuntu15.1,打开终端,输入命令:sudo apt-get install redis-server 将会在本机安装上redis. 启动redis 启动redis命令 ...

  7. decimall类型数据

    同样是decimal(18,5)   和 decimal(18,4)  在VB中经过几次转化过后,数据就有可能改变. 遇到的情况 decimal(18,5)到  decimal(18,4)转换过程中数 ...

  8. 自动生成makefile的脚本

    如果需要测试某一个特性,写了一个test.cpp 某天又增加了一个utils.cpp,依此类推,测试文件越来越多 每次测试时都要手动维护一个makefile实在是不明智的 于是萌生了用脚本自动维护的念 ...

  9. redis问题解决

    一, redis的奇葩问题:我使用命令 redis-cli shutdown 关闭redis之后就再也灭洋启动了! 尝试1: 使用命令 sudo /etc/init.d/redis-server st ...

  10. JQuery的二维码插件

    jquery.qrcode.js 只有能重新生成的二维码才是安全的,大牛做了插件,满足我们吃糖的需求: 用法(除了翻译git上的readme我一下子想不到还能写点什么) 引用 <script t ...