sequenceEqual.js
2.73 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import { Subscriber } from '../Subscriber';
export function sequenceEqual(compareTo, comparator) {
return (source) => source.lift(new SequenceEqualOperator(compareTo, comparator));
}
export class SequenceEqualOperator {
constructor(compareTo, comparator) {
this.compareTo = compareTo;
this.comparator = comparator;
}
call(subscriber, source) {
return source.subscribe(new SequenceEqualSubscriber(subscriber, this.compareTo, this.comparator));
}
}
export class SequenceEqualSubscriber extends Subscriber {
constructor(destination, compareTo, comparator) {
super(destination);
this.compareTo = compareTo;
this.comparator = comparator;
this._a = [];
this._b = [];
this._oneComplete = false;
this.destination.add(compareTo.subscribe(new SequenceEqualCompareToSubscriber(destination, this)));
}
_next(value) {
if (this._oneComplete && this._b.length === 0) {
this.emit(false);
}
else {
this._a.push(value);
this.checkValues();
}
}
_complete() {
if (this._oneComplete) {
this.emit(this._a.length === 0 && this._b.length === 0);
}
else {
this._oneComplete = true;
}
this.unsubscribe();
}
checkValues() {
const { _a, _b, comparator } = this;
while (_a.length > 0 && _b.length > 0) {
let a = _a.shift();
let b = _b.shift();
let areEqual = false;
try {
areEqual = comparator ? comparator(a, b) : a === b;
}
catch (e) {
this.destination.error(e);
}
if (!areEqual) {
this.emit(false);
}
}
}
emit(value) {
const { destination } = this;
destination.next(value);
destination.complete();
}
nextB(value) {
if (this._oneComplete && this._a.length === 0) {
this.emit(false);
}
else {
this._b.push(value);
this.checkValues();
}
}
completeB() {
if (this._oneComplete) {
this.emit(this._a.length === 0 && this._b.length === 0);
}
else {
this._oneComplete = true;
}
}
}
class SequenceEqualCompareToSubscriber extends Subscriber {
constructor(destination, parent) {
super(destination);
this.parent = parent;
}
_next(value) {
this.parent.nextB(value);
}
_error(err) {
this.parent.error(err);
this.unsubscribe();
}
_complete() {
this.parent.completeB();
this.unsubscribe();
}
}
//# sourceMappingURL=sequenceEqual.js.map