audit.js
1.89 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { SimpleOuterSubscriber, innerSubscribe, SimpleInnerSubscriber } from '../innerSubscribe';
export function audit(durationSelector) {
return function auditOperatorFunction(source) {
return source.lift(new AuditOperator(durationSelector));
};
}
class AuditOperator {
constructor(durationSelector) {
this.durationSelector = durationSelector;
}
call(subscriber, source) {
return source.subscribe(new AuditSubscriber(subscriber, this.durationSelector));
}
}
class AuditSubscriber extends SimpleOuterSubscriber {
constructor(destination, durationSelector) {
super(destination);
this.durationSelector = durationSelector;
this.hasValue = false;
}
_next(value) {
this.value = value;
this.hasValue = true;
if (!this.throttled) {
let duration;
try {
const { durationSelector } = this;
duration = durationSelector(value);
}
catch (err) {
return this.destination.error(err);
}
const innerSubscription = innerSubscribe(duration, new SimpleInnerSubscriber(this));
if (!innerSubscription || innerSubscription.closed) {
this.clearThrottle();
}
else {
this.add(this.throttled = innerSubscription);
}
}
}
clearThrottle() {
const { value, hasValue, throttled } = this;
if (throttled) {
this.remove(throttled);
this.throttled = undefined;
throttled.unsubscribe();
}
if (hasValue) {
this.value = undefined;
this.hasValue = false;
this.destination.next(value);
}
}
notifyNext() {
this.clearThrottle();
}
notifyComplete() {
this.clearThrottle();
}
}
//# sourceMappingURL=audit.js.map