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 pathevery.js
53 lines (46 loc) · 1.73 KB
/
every.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
var EveryObservable = (function (__super__) {
inherits(EveryObservable, __super__);
function EveryObservable(source, fn) {
this.source = source;
this._fn = fn;
__super__.call(this);
}
EveryObservable.prototype.subscribeCore = function (o) {
return this.source.subscribe(new EveryObserver(o, this._fn, this.source));
};
return EveryObservable;
}(ObservableBase));
var EveryObserver = (function (__super__) {
inherits(EveryObserver, __super__);
function EveryObserver(o, fn, s) {
this._o = o;
this._fn = fn;
this._s = s;
this._i = 0;
__super__.call(this);
}
EveryObserver.prototype.next = function (x) {
var result = tryCatch(this._fn)(x, this._i++, this._s);
if (result === errorObj) { return this._o.onError(result.e); }
if (!Boolean(result)) {
this._o.onNext(false);
this._o.onCompleted();
}
};
EveryObserver.prototype.error = function (e) { this._o.onError(e); };
EveryObserver.prototype.completed = function () {
this._o.onNext(true);
this._o.onCompleted();
};
return EveryObserver;
}(AbstractObserver));
/**
* Determines whether all elements of an observable sequence satisfy a condition.
* @param {Function} [predicate] A function to test each element for a condition.
* @param {Any} [thisArg] Object to use as this when executing callback.
* @returns {Observable} An observable sequence containing a single element determining whether all elements in the source sequence pass the test in the specified predicate.
*/
observableProto.every = function (predicate, thisArg) {
var fn = bindCallback(predicate, thisArg, 3);
return new EveryObservable(this, fn);
};