Immediate debounce in Rx

后端 未结 4 1621
南笙
南笙 2021-02-02 11:59

I am looking an operator to debounce a series of event, let us say user\'s click. The input and output should be like this:

interval :      ->            


        
4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-02 12:29

    According to documentation there are two debounce operators in RxJS. You might be interested in debounceTime in particular.

    debounceTime

    From documentation

    Emits a value from the source Observable only after a particular time span has passed without another source emission.

    Example:

    Rx.Observable
        .fromEvent(document.querySelector('button'), 'click')
        .debounceTime(200)
        .mapTo(() => 'clicked!')
        .subscribe(v => console.log(v));
    

    It will emit one clicked! if button was clicked in given timespan (200ms in this example).

    debounce

    From documentation

    Emits a value from the source Observable only after a particular time span determined by another Observable has passed without another source emission.

提交回复
热议问题