I use a stream that is throttled when I view the window.
When throttling (before scrolling), it issues values ββto the console.
However, when the stream is inactive (the user does not scroll the window) - I want the timer to set. However - if the user starts scrolling again - I do not want this timer to display values.
I am currently doing this:
const observable = Rx.Observable.fromEvent(window, 'scroll'); const subscriber = observable .throttleTime(300 ) .map(() => 'throttle') .merge(Rx.Observable.interval(1000).map(() => 'tick') ) .subscribe( (x) => { console.log('Next: event!', x); }, (err) => { console.log('Error: %s', err); }, () => { console.log('Completed'); });
The problem is that when scrolling - I see as "throttle" AND "tick" (I should see only the "throttle")
Think about it from another POV. Work must always be done. If I scroll - this throttle scroll - should trigger a job. If I do not scroll, the timer should begin work and begin work. (and stops if the user starts scrolling again).
Question:
How to start the timer after idle without scrolling?
Plnkr
source share