UNPKG

@reactivex/rxjs

Version:

Reactive Extensions for modern JavaScript

59 lines 1.91 kB
import { Subscriber } from '../Subscriber'; /** * Returns an Observable that emits whether or not every item of the source satisfies the condition specified. * @param {function} predicate a function for determining if an item meets a specified condition. * @param {any} [thisArg] optional object to use for `this` in the callback * @return {Observable} an Observable of booleans that determines if all items of the source Observable meet the condition specified. * @method every * @owner Observable */ export function every(predicate, thisArg) { const source = this; return source.lift(new EveryOperator(predicate, thisArg, source)); } class EveryOperator { constructor(predicate, thisArg, source) { this.predicate = predicate; this.thisArg = thisArg; this.source = source; } call(observer, source) { return source._subscribe(new EverySubscriber(observer, this.predicate, this.thisArg, this.source)); } } /** * We need this JSDoc comment for affecting ESDoc. * @ignore * @extends {Ignored} */ class EverySubscriber extends Subscriber { constructor(destination, predicate, thisArg, source) { super(destination); this.predicate = predicate; this.thisArg = thisArg; this.source = source; this.index = 0; this.thisArg = thisArg || this; } notifyComplete(everyValueMatch) { this.destination.next(everyValueMatch); this.destination.complete(); } _next(value) { let result = false; try { result = this.predicate.call(this.thisArg, value, this.index++, this.source); } catch (err) { this.destination.error(err); return; } if (!result) { this.notifyComplete(false); } } _complete() { this.notifyComplete(true); } } //# sourceMappingURL=every.js.map