sampleTime.js
1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { Subscriber } from '../Subscriber';
import { async } from '../scheduler/async';
export function sampleTime(period, scheduler = async) {
return (source) => source.lift(new SampleTimeOperator(period, scheduler));
}
class SampleTimeOperator {
constructor(period, scheduler) {
this.period = period;
this.scheduler = scheduler;
}
call(subscriber, source) {
return source.subscribe(new SampleTimeSubscriber(subscriber, this.period, this.scheduler));
}
}
class SampleTimeSubscriber extends Subscriber {
constructor(destination, period, scheduler) {
super(destination);
this.period = period;
this.scheduler = scheduler;
this.hasValue = false;
this.add(scheduler.schedule(dispatchNotification, period, { subscriber: this, period }));
}
_next(value) {
this.lastValue = value;
this.hasValue = true;
}
notifyNext() {
if (this.hasValue) {
this.hasValue = false;
this.destination.next(this.lastValue);
}
}
}
function dispatchNotification(state) {
let { subscriber, period } = state;
subscriber.notifyNext();
this.schedule(state, period);
}
//# sourceMappingURL=sampleTime.js.map