This repository was archived by the owner on Apr 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathpairwise.js
46 lines (40 loc) · 1.55 KB
/
pairwise.js
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
var PairwiseObservable = (function (__super__) {
inherits(PairwiseObservable, __super__);
function PairwiseObservable(source) {
this.source = source;
__super__.call(this);
}
PairwiseObservable.prototype.subscribeCore = function (o) {
return this.source.subscribe(new PairwiseObserver(o));
};
return PairwiseObservable;
}(ObservableBase));
var PairwiseObserver = (function(__super__) {
inherits(PairwiseObserver, __super__);
function PairwiseObserver(o) {
this._o = o;
this._p = null;
this._hp = false;
__super__.call(this);
}
PairwiseObserver.prototype.next = function (x) {
if (this._hp) {
this._o.onNext([this._p, x]);
} else {
this._hp = true;
}
this._p = x;
};
PairwiseObserver.prototype.error = function (err) { this._o.onError(err); };
PairwiseObserver.prototype.completed = function () { this._o.onCompleted(); };
return PairwiseObserver;
}(AbstractObserver));
/**
* Returns a new observable that triggers on the second and subsequent triggerings of the input observable.
* The Nth triggering of the input observable passes the arguments from the N-1th and Nth triggering as a pair.
* The argument passed to the N-1th triggering is held in hidden internal state until the Nth triggering occurs.
* @returns {Observable} An observable that triggers on successive pairs of observations from the input observable as an array.
*/
observableProto.pairwise = function () {
return new PairwiseObservable(this);
};