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
/
includes.js
60 lines (51 loc) · 1.99 KB
/
includes.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
53
54
55
56
57
58
59
60
var IncludesObservable = (function (__super__) {
inherits(IncludesObservable, __super__);
function IncludesObservable(source, elem, idx) {
var n = +idx || 0;
Math.abs(n) === Infinity && (n = 0);
this.source = source;
this._elem = elem;
this._n = n;
__super__.call(this);
}
IncludesObservable.prototype.subscribeCore = function (o) {
if (this._n < 0) {
o.onNext(false);
o.onCompleted();
return disposableEmpty;
}
return this.source.subscribe(new IncludesObserver(o, this._elem, this._n));
};
return IncludesObservable;
}(ObservableBase));
var IncludesObserver = (function (__super__) {
inherits(IncludesObserver, __super__);
function IncludesObserver(o, elem, n) {
this._o = o;
this._elem = elem;
this._n = n;
this._i = 0;
__super__.call(this);
}
function comparer(a, b) {
return (a === 0 && b === 0) || (a === b || (isNaN(a) && isNaN(b)));
}
IncludesObserver.prototype.next = function (x) {
if (this._i++ >= this._n && comparer(x, this._elem)) {
this._o.onNext(true);
this._o.onCompleted();
}
};
IncludesObserver.prototype.error = function (e) { this._o.onError(e); };
IncludesObserver.prototype.completed = function () { this._o.onNext(false); this._o.onCompleted(); };
return IncludesObserver;
}(AbstractObserver));
/**
* Determines whether an observable sequence includes a specified element with an optional equality comparer.
* @param searchElement The value to locate in the source sequence.
* @param {Number} [fromIndex] An equality comparer to compare elements.
* @returns {Observable} An observable sequence containing a single element determining whether the source sequence includes an element that has the specified value from the given index.
*/
observableProto.includes = function (searchElement, fromIndex) {
return new IncludesObservable(this, searchElement, fromIndex);
};