sample.js
1.08 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
import { SimpleOuterSubscriber, innerSubscribe, SimpleInnerSubscriber } from '../innerSubscribe';
export function sample(notifier) {
return (source) => source.lift(new SampleOperator(notifier));
}
class SampleOperator {
constructor(notifier) {
this.notifier = notifier;
}
call(subscriber, source) {
const sampleSubscriber = new SampleSubscriber(subscriber);
const subscription = source.subscribe(sampleSubscriber);
subscription.add(innerSubscribe(this.notifier, new SimpleInnerSubscriber(sampleSubscriber)));
return subscription;
}
}
class SampleSubscriber extends SimpleOuterSubscriber {
constructor() {
super(...arguments);
this.hasValue = false;
}
_next(value) {
this.value = value;
this.hasValue = true;
}
notifyNext() {
this.emitValue();
}
notifyComplete() {
this.emitValue();
}
emitValue() {
if (this.hasValue) {
this.hasValue = false;
this.destination.next(this.value);
}
}
}
//# sourceMappingURL=sample.js.map