This repository has been 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 pathskiplast.js
52 lines (44 loc) · 1.73 KB
/
skiplast.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
47
48
49
50
51
52
var SkipLastObservable = (function (__super__) {
inherits(SkipLastObservable, __super__);
function SkipLastObservable(source, c) {
this.source = source;
this._c = c;
__super__.call(this);
}
SkipLastObservable.prototype.subscribeCore = function (o) {
return this.source.subscribe(new SkipLastObserver(o, this._c));
};
return SkipLastObservable;
}(ObservableBase));
var SkipLastObserver = (function (__super__) {
inherits(SkipLastObserver, __super__);
function SkipLastObserver(o, c) {
this._o = o;
this._c = c;
this._q = [];
__super__.call(this);
}
SkipLastObserver.prototype.next = function (x) {
this._q.push(x);
this._q.length > this._c && this._o.onNext(this._q.shift());
};
SkipLastObserver.prototype.error = function (e) {
this._o.onError(e);
};
SkipLastObserver.prototype.completed = function () {
this._o.onCompleted();
};
return SkipLastObserver;
}(AbstractObserver));
/**
* Bypasses a specified number of elements at the end of an observable sequence.
* @description
* This operator accumulates a queue with a length enough to store the first `count` elements. As more elements are
* received, elements are taken from the front of the queue and produced on the result sequence. This causes elements to be delayed.
* @param count Number of elements to bypass at the end of the source sequence.
* @returns {Observable} An observable sequence containing the source sequence elements except for the bypassed ones at the end.
*/
observableProto.skipLast = function (count) {
if (count < 0) { throw new ArgumentOutOfRangeError(); }
return new SkipLastObservable(this, count);
};