sampleTime() operator

The sampleTime() operator is used to only emit values after the sample period has passed. A good use case for this is when you want to have a cooldown functionality. Imagine you have users that press a Save button way too often. It might be that saving takes a few seconds to complete. A way to approach this is to disable the Save button while saving. Another valid approach is to simply ignore any presses of the button until the operation has had the chance to complete. The following code does just that:

// time/sampleTime.js

let elem = document.getElementById("btn");
let stream$ = Rx.Observable
.fromEvent(elem, "click")
.sampleTime(8000);

// emits values every 8th second
stream$.subscribe(data => console.log("mouse clicks",data));
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.193.108