+ };
+ DelaySubscriber.prototype._next = function (value) {
+ this.scheduleNotification(Notification_1.Notification.createNext(value));
+ };
+ DelaySubscriber.prototype._error = function (err) {
+ this.errored = true;
+ this.queue = [];
+ this.destination.error(err);
+ };
+ DelaySubscriber.prototype._complete = function () {
+ this.scheduleNotification(Notification_1.Notification.createComplete());
+ };
+ return DelaySubscriber;
+}(Subscriber_1.Subscriber));
+var DelayMessage = (function () {
+ function DelayMessage(time, notification) {
+ this.time = time;
+ this.notification = notification;
+ }
+ return DelayMessage;
+}());
+
+},{"../Notification":28,"../Subscriber":36,"../scheduler/async":213,"../util/isDate":229}],170:[function(require,module,exports){
+"use strict";
+var __extends = (this && this.__extends) || function (d, b) {
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+};
+var OuterSubscriber_1 = require('../OuterSubscriber');
+var subscribeToResult_1 = require('../util/subscribeToResult');
+var Set_1 = require('../util/Set');
+/**
+ * Returns an Observable that emits all items emitted by the source Observable that are distinct by comparison from previous items.
+ *
+ * If a keySelector function is provided, then it will project each value from the source observable into a new value that it will
+ * check for equality with previously projected values. If a keySelector function is not provided, it will use each value from the
+ * source observable directly with an equality check against previous values.
+ *
+ * In JavaScript runtimes that support `Set`, this operator will use a `Set` to improve performance of the distinct value checking.
+ *
+ * In other runtimes, this operator will use a minimal implementation of `Set` that relies on an `Array` and `indexOf` under the
+ * hood, so performance will degrade as more values are checked for distinction. Even in newer browsers, a long-running `distinct`
+ * use might result in memory leaks. To help alleviate this in some scenarios, an optional `flushes` parameter is also provided so
+ * that the internal `Set` can be "flushed", basically clearing it of values.
+ *
+ * @example <caption>A simple example with numbers</caption>
+ * Observable.of(1, 1, 2, 2, 2, 1, 2, 3, 4, 3, 2, 1)
+ * .distinct()
+ * .subscribe(x => console.log(x)); // 1, 2, 3, 4
+ *
+ * @example <caption>An example using a keySelector function</caption>
+ * interface Person {
+ * age: number,
+ * name: string
+ * }
+ *
+ * Observable.of<Person>(
+ * { age: 4, name: 'Foo'},
+ * { age: 7, name: 'Bar'},
+ * { age: 5, name: 'Foo'})
+ * .distinct((p: Person) => p.name)
+ * .subscribe(x => console.log(x));
+ *
+ * // displays:
+ * // { age: 4, name: 'Foo' }
+ * // { age: 7, name: 'Bar' }
+ *
+ * @see {@link distinctUntilChanged}
+ * @see {@link distinctUntilKeyChanged}
+ *
+ * @param {function} [keySelector] Optional function to select which value you want to check as distinct.
+ * @param {Observable} [flushes] Optional Observable for flushing the internal HashSet of the operator.
+ * @return {Observable} An Observable that emits items from the source Observable with distinct values.
+ * @method distinct
+ * @owner Observable
+ */
+function distinct(keySelector, flushes) {
+ return function (source) { return source.lift(new DistinctOperator(keySelector, flushes)); };
+}
+exports.distinct = distinct;
+var DistinctOperator = (function () {
+ function DistinctOperator(keySelector, flushes) {
+ this.keySelector = keySelector;
+ this.flushes = flushes;
+ }
+ DistinctOperator.prototype.call = function (subscriber, source) {
+ return source.subscribe(new DistinctSubscriber(subscriber, this.keySelector, this.flushes));
+ };
+ return DistinctOperator;
+}());
+/**
+ * We need this JSDoc comment for affecting ESDoc.
+ * @ignore
+ * @extends {Ignored}
+ */
+var DistinctSubscriber = (function (_super) {
+ __extends(DistinctSubscriber, _super);
+ function DistinctSubscriber(destination, keySelector, flushes) {
+ _super.call(this, destination);
+ this.keySelector = keySelector;
+ this.values = new Set_1.Set();
+ if (flushes) {
+ this.add(subscribeToResult_1.subscribeToResult(this, flushes));
+ }
+ }
+ DistinctSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
+ this.values.clear();
+ };
+ DistinctSubscriber.prototype.notifyError = function (error, innerSub) {
+ this._error(error);
+ };
+ DistinctSubscriber.prototype._next = function (value) {
+ if (this.keySelector) {
+ this._useKeySelector(value);
+ }
+ else {
+ this._finalizeNext(value, value);
+ }
+ };
+ DistinctSubscriber.prototype._useKeySelector = function (value) {
+ var key;
+ var destination = this.destination;
+ try {
+ key = this.keySelector(value);
+ }
+ catch (err) {
+ destination.error(err);
+ return;
+ }
+ this._finalizeNext(key, value);
+ };
+ DistinctSubscriber.prototype._finalizeNext = function (key, value) {
+ var values = this.values;
+ if (!values.has(key)) {
+ values.add(key);
+ this.destination.next(value);
+ }
+ };
+ return DistinctSubscriber;
+}(OuterSubscriber_1.OuterSubscriber));
+exports.DistinctSubscriber = DistinctSubscriber;
+
+},{"../OuterSubscriber":31,"../util/Set":222,"../util/subscribeToResult":238}],171:[function(require,module,exports){
+"use strict";
+var __extends = (this && this.__extends) || function (d, b) {
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+};
+var Subscriber_1 = require('../Subscriber');
+var tryCatch_1 = require('../util/tryCatch');
+var errorObject_1 = require('../util/errorObject');
+/* tslint:enable:max-line-length */
+/**
+ * Returns an Observable that emits all items emitted by the source Observable that are distinct by comparison from the previous item.
+ *
+ * If a comparator function is provided, then it will be called for each item to test for whether or not that value should be emitted.
+ *
+ * If a comparator function is not provided, an equality check is used by default.
+ *
+ * @example <caption>A simple example with numbers</caption>
+ * Observable.of(1, 1, 2, 2, 2, 1, 1, 2, 3, 3, 4)
+ * .distinctUntilChanged()
+ * .subscribe(x => console.log(x)); // 1, 2, 1, 2, 3, 4
+ *
+ * @example <caption>An example using a compare function</caption>
+ * interface Person {
+ * age: number,
+ * name: string
+ * }
+ *
+ * Observable.of<Person>(
+ * { age: 4, name: 'Foo'},
+ * { age: 7, name: 'Bar'},
+ * { age: 5, name: 'Foo'})
+ * { age: 6, name: 'Foo'})
+ * .distinctUntilChanged((p: Person, q: Person) => p.name === q.name)
+ * .subscribe(x => console.log(x));
+ *
+ * // displays:
+ * // { age: 4, name: 'Foo' }
+ * // { age: 7, name: 'Bar' }
+ * // { age: 5, name: 'Foo' }
+ *
+ * @see {@link distinct}
+ * @see {@link distinctUntilKeyChanged}
+ *
+ * @param {function} [compare] Optional comparison function called to test if an item is distinct from the previous item in the source.
+ * @return {Observable} An Observable that emits items from the source Observable with distinct values.
+ * @method distinctUntilChanged
+ * @owner Observable
+ */
+function distinctUntilChanged(compare, keySelector) {
+ return function (source) { return source.lift(new DistinctUntilChangedOperator(compare, keySelector)); };
+}
+exports.distinctUntilChanged = distinctUntilChanged;
+var DistinctUntilChangedOperator = (function () {
+ function DistinctUntilChangedOperator(compare, keySelector) {
+ this.compare = compare;
+ this.keySelector = keySelector;
+ }
+ DistinctUntilChangedOperator.prototype.call = function (subscriber, source) {
+ return source.subscribe(new DistinctUntilChangedSubscriber(subscriber, this.compare, this.keySelector));
+ };
+ return DistinctUntilChangedOperator;
+}());
+/**
+ * We need this JSDoc comment for affecting ESDoc.
+ * @ignore
+ * @extends {Ignored}
+ */
+var DistinctUntilChangedSubscriber = (function (_super) {
+ __extends(DistinctUntilChangedSubscriber, _super);
+ function DistinctUntilChangedSubscriber(destination, compare, keySelector) {
+ _super.call(this, destination);
+ this.keySelector = keySelector;
+ this.hasKey = false;
+ if (typeof compare === 'function') {
+ this.compare = compare;
+ }
+ }
+ DistinctUntilChangedSubscriber.prototype.compare = function (x, y) {
+ return x === y;
+ };
+ DistinctUntilChangedSubscriber.prototype._next = function (value) {
+ var keySelector = this.keySelector;
+ var key = value;
+ if (keySelector) {
+ key = tryCatch_1.tryCatch(this.keySelector)(value);
+ if (key === errorObject_1.errorObject) {
+ return this.destination.error(errorObject_1.errorObject.e);
+ }
+ }
+ var result = false;
+ if (this.hasKey) {
+ result = tryCatch_1.tryCatch(this.compare)(this.key, key);
+ if (result === errorObject_1.errorObject) {
+ return this.destination.error(errorObject_1.errorObject.e);
+ }
+ }
+ else {
+ this.hasKey = true;
+ }
+ if (Boolean(result) === false) {
+ this.key = key;
+ this.destination.next(value);
+ }
+ };
+ return DistinctUntilChangedSubscriber;
+}(Subscriber_1.Subscriber));
+
+},{"../Subscriber":36,"../util/errorObject":225,"../util/tryCatch":240}],172:[function(require,module,exports){
+"use strict";
+var __extends = (this && this.__extends) || function (d, b) {
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+};
+var tryCatch_1 = require('../util/tryCatch');
+var errorObject_1 = require('../util/errorObject');
+var OuterSubscriber_1 = require('../OuterSubscriber');
+var subscribeToResult_1 = require('../util/subscribeToResult');
+/* tslint:enable:max-line-length */
+/**
+ * Recursively projects each source value to an Observable which is merged in
+ * the output Observable.
+ *
+ * <span class="informal">It's similar to {@link mergeMap}, but applies the
+ * projection function to every source value as well as every output value.
+ * It's recursive.</span>
+ *
+ * <img src="./img/expand.png" width="100%">
+ *
+ * Returns an Observable that emits items based on applying a function that you
+ * supply to each item emitted by the source Observable, where that function
+ * returns an Observable, and then merging those resulting Observables and
+ * emitting the results of this merger. *Expand* will re-emit on the output
+ * Observable every source value. Then, each output value is given to the
+ * `project` function which returns an inner Observable to be merged on the
+ * output Observable. Those output values resulting from the projection are also
+ * given to the `project` function to produce new output values. This is how
+ * *expand* behaves recursively.
+ *
+ * @example <caption>Start emitting the powers of two on every click, at most 10 of them</caption>
+ * var clicks = Rx.Observable.fromEvent(document, 'click');
+ * var powersOfTwo = clicks
+ * .mapTo(1)
+ * .expand(x => Rx.Observable.of(2 * x).delay(1000))
+ * .take(10);
+ * powersOfTwo.subscribe(x => console.log(x));
+ *
+ * @see {@link mergeMap}
+ * @see {@link mergeScan}
+ *
+ * @param {function(value: T, index: number) => Observable} project A function
+ * that, when applied to an item emitted by the source or the output Observable,
+ * returns an Observable.
+ * @param {number} [concurrent=Number.POSITIVE_INFINITY] Maximum number of input
+ * Observables being subscribed to concurrently.
+ * @param {Scheduler} [scheduler=null] The IScheduler to use for subscribing to
+ * each projected inner Observable.
+ * @return {Observable} An Observable that emits the source values and also
+ * result of applying the projection function to each value emitted on the
+ * output Observable and and merging the results of the Observables obtained
+ * from this transformation.
+ * @method expand
+ * @owner Observable
+ */
+function expand(project, concurrent, scheduler) {
+ if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
+ if (scheduler === void 0) { scheduler = undefined; }
+ concurrent = (concurrent || 0) < 1 ? Number.POSITIVE_INFINITY : concurrent;
+ return function (source) { return source.lift(new ExpandOperator(project, concurrent, scheduler)); };
+}
+exports.expand = expand;
+var ExpandOperator = (function () {
+ function ExpandOperator(project, concurrent, scheduler) {
+ this.project = project;
+ this.concurrent = concurrent;
+ this.scheduler = scheduler;
+ }
+ ExpandOperator.prototype.call = function (subscriber, source) {
+ return source.subscribe(new ExpandSubscriber(subscriber, this.project, this.concurrent, this.scheduler));
+ };
+ return ExpandOperator;
+}());
+exports.ExpandOperator = ExpandOperator;
+/**
+ * We need this JSDoc comment for affecting ESDoc.
+ * @ignore
+ * @extends {Ignored}
+ */
+var ExpandSubscriber = (function (_super) {
+ __extends(ExpandSubscriber, _super);
+ function ExpandSubscriber(destination, project, concurrent, scheduler) {
+ _super.call(this, destination);
+ this.project = project;
+ this.concurrent = concurrent;
+ this.scheduler = scheduler;
+ this.index = 0;
+ this.active = 0;
+ this.hasCompleted = false;
+ if (concurrent < Number.POSITIVE_INFINITY) {
+ this.buffer = [];
+ }
+ }
+ ExpandSubscriber.dispatch = function (arg) {
+ var subscriber = arg.subscriber, result = arg.result, value = arg.value, index = arg.index;
+ subscriber.subscribeToProjection(result, value, index);
+ };
+ ExpandSubscriber.prototype._next = function (value) {
+ var destination = this.destination;
+ if (destination.closed) {
+ this._complete();
+ return;
+ }
+ var index = this.index++;
+ if (this.active < this.concurrent) {
+ destination.next(value);
+ var result = tryCatch_1.tryCatch(this.project)(value, index);
+ if (result === errorObject_1.errorObject) {
+ destination.error(errorObject_1.errorObject.e);
+ }
+ else if (!this.scheduler) {
+ this.subscribeToProjection(result, value, index);
+ }
+ else {
+ var state = { subscriber: this, result: result, value: value, index: index };
+ this.add(this.scheduler.schedule(ExpandSubscriber.dispatch, 0, state));
+ }
+ }
+ else {
+ this.buffer.push(value);
+ }
+ };
+ ExpandSubscriber.prototype.subscribeToProjection = function (result, value, index) {
+ this.active++;
+ this.add(subscribeToResult_1.subscribeToResult(this, result, value, index));
+ };
+ ExpandSubscriber.prototype._complete = function () {
+ this.hasCompleted = true;
+ if (this.hasCompleted && this.active === 0) {
+ this.destination.complete();
+ }
+ };
+ ExpandSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
+ this._next(innerValue);
+ };
+ ExpandSubscriber.prototype.notifyComplete = function (innerSub) {
+ var buffer = this.buffer;
+ this.remove(innerSub);
+ this.active--;
+ if (buffer && buffer.length > 0) {
+ this._next(buffer.shift());
+ }
+ if (this.hasCompleted && this.active === 0) {
+ this.destination.complete();
+ }
+ };
+ return ExpandSubscriber;
+}(OuterSubscriber_1.OuterSubscriber));
+exports.ExpandSubscriber = ExpandSubscriber;
+
+},{"../OuterSubscriber":31,"../util/errorObject":225,"../util/subscribeToResult":238,"../util/tryCatch":240}],173:[function(require,module,exports){
+"use strict";
+var __extends = (this && this.__extends) || function (d, b) {
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+};
+var Subscriber_1 = require('../Subscriber');
+/* tslint:enable:max-line-length */
+/**
+ * Filter items emitted by the source Observable by only emitting those that
+ * satisfy a specified predicate.
+ *
+ * <span class="informal">Like
+ * [Array.prototype.filter()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter),
+ * it only emits a value from the source if it passes a criterion function.</span>
+ *
+ * <img src="./img/filter.png" width="100%">
+ *
+ * Similar to the well-known `Array.prototype.filter` method, this operator
+ * takes values from the source Observable, passes them through a `predicate`
+ * function and only emits those values that yielded `true`.
+ *
+ * @example <caption>Emit only click events whose target was a DIV element</caption>
+ * var clicks = Rx.Observable.fromEvent(document, 'click');
+ * var clicksOnDivs = clicks.filter(ev => ev.target.tagName === 'DIV');
+ * clicksOnDivs.subscribe(x => console.log(x));
+ *
+ * @see {@link distinct}
+ * @see {@link distinctUntilChanged}
+ * @see {@link distinctUntilKeyChanged}
+ * @see {@link ignoreElements}
+ * @see {@link partition}
+ * @see {@link skip}
+ *
+ * @param {function(value: T, index: number): boolean} predicate A function that
+ * evaluates each value emitted by the source Observable. If it returns `true`,
+ * the value is emitted, if `false` the value is not passed to the output
+ * Observable. The `index` parameter is the number `i` for the i-th source
+ * emission that has happened since the subscription, starting from the number
+ * `0`.
+ * @param {any} [thisArg] An optional argument to determine the value of `this`
+ * in the `predicate` function.
+ * @return {Observable} An Observable of values from the source that were
+ * allowed by the `predicate` function.
+ * @method filter
+ * @owner Observable
+ */
+function filter(predicate, thisArg) {
+ return function filterOperatorFunction(source) {
+ return source.lift(new FilterOperator(predicate, thisArg));
+ };
+}
+exports.filter = filter;
+var FilterOperator = (function () {
+ function FilterOperator(predicate, thisArg) {
+ this.predicate = predicate;
+ this.thisArg = thisArg;
+ }
+ FilterOperator.prototype.call = function (subscriber, source) {
+ return source.subscribe(new FilterSubscriber(subscriber, this.predicate, this.thisArg));
+ };
+ return FilterOperator;
+}());
+/**
+ * We need this JSDoc comment for affecting ESDoc.
+ * @ignore
+ * @extends {Ignored}
+ */
+var FilterSubscriber = (function (_super) {
+ __extends(FilterSubscriber, _super);
+ function FilterSubscriber(destination, predicate, thisArg) {
+ _super.call(this, destination);
+ this.predicate = predicate;
+ this.thisArg = thisArg;
+ this.count = 0;
+ }
+ // the try catch block below is left specifically for
+ // optimization and perf reasons. a tryCatcher is not necessary here.
+ FilterSubscriber.prototype._next = function (value) {
+ var result;
+ try {
+ result = this.predicate.call(this.thisArg, value, this.count++);
+ }
+ catch (err) {
+ this.destination.error(err);
+ return;
+ }
+ if (result) {
+ this.destination.next(value);
+ }
+ };
+ return FilterSubscriber;
+}(Subscriber_1.Subscriber));
+
+},{"../Subscriber":36}],174:[function(require,module,exports){
+"use strict";
+var __extends = (this && this.__extends) || function (d, b) {
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+};
+var Subscriber_1 = require('../Subscriber');
+var Subscription_1 = require('../Subscription');
+/**
+ * Returns an Observable that mirrors the source Observable, but will call a specified function when
+ * the source terminates on complete or error.
+ * @param {function} callback Function to be called when source terminates.
+ * @return {Observable} An Observable that mirrors the source, but will call the specified function on termination.
+ * @method finally
+ * @owner Observable
+ */
+function finalize(callback) {
+ return function (source) { return source.lift(new FinallyOperator(callback)); };
+}
+exports.finalize = finalize;
+var FinallyOperator = (function () {
+ function FinallyOperator(callback) {
+ this.callback = callback;
+ }
+ FinallyOperator.prototype.call = function (subscriber, source) {
+ return source.subscribe(new FinallySubscriber(subscriber, this.callback));
+ };
+ return FinallyOperator;
+}());
+/**
+ * We need this JSDoc comment for affecting ESDoc.
+ * @ignore
+ * @extends {Ignored}
+ */
+var FinallySubscriber = (function (_super) {
+ __extends(FinallySubscriber, _super);
+ function FinallySubscriber(destination, callback) {
+ _super.call(this, destination);
+ this.add(new Subscription_1.Subscription(callback));
+ }
+ return FinallySubscriber;
+}(Subscriber_1.Subscriber));
+
+},{"../Subscriber":36,"../Subscription":37}],175:[function(require,module,exports){
+"use strict";
+var __extends = (this && this.__extends) || function (d, b) {
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+};
+var Subscriber_1 = require('../Subscriber');
+var EmptyError_1 = require('../util/EmptyError');
+/**
+ * Emits only the first value (or the first value that meets some condition)
+ * emitted by the source Observable.
+ *
+ * <span class="informal">Emits only the first value. Or emits only the first
+ * value that passes some test.</span>
+ *
+ * <img src="./img/first.png" width="100%">
+ *
+ * If called with no arguments, `first` emits the first value of the source
+ * Observable, then completes. If called with a `predicate` function, `first`
+ * emits the first value of the source that matches the specified condition. It
+ * may also take a `resultSelector` function to produce the output value from
+ * the input value, and a `defaultValue` to emit in case the source completes
+ * before it is able to emit a valid value. Throws an error if `defaultValue`
+ * was not provided and a matching element is not found.
+ *
+ * @example <caption>Emit only the first click that happens on the DOM</caption>
+ * var clicks = Rx.Observable.fromEvent(document, 'click');
+ * var result = clicks.first();
+ * result.subscribe(x => console.log(x));
+ *
+ * @example <caption>Emits the first click that happens on a DIV</caption>
+ * var clicks = Rx.Observable.fromEvent(document, 'click');
+ * var result = clicks.first(ev => ev.target.tagName === 'DIV');
+ * result.subscribe(x => console.log(x));
+ *
+ * @see {@link filter}
+ * @see {@link find}
+ * @see {@link take}
+ *
+ * @throws {EmptyError} Delivers an EmptyError to the Observer's `error`
+ * callback if the Observable completes before any `next` notification was sent.
+ *
+ * @param {function(value: T, index: number, source: Observable<T>): boolean} [predicate]
+ * An optional function called with each item to test for condition matching.
+ * @param {function(value: T, index: number): R} [resultSelector] A function to
+ * produce the value on the output Observable based on the values
+ * and the indices of the source Observable. The arguments passed to this
+ * function are:
+ * - `value`: the value that was emitted on the source.
+ * - `index`: the "index" of the value from the source.
+ * @param {R} [defaultValue] The default value emitted in case no valid value
+ * was found on the source.
+ * @return {Observable<T|R>} An Observable of the first item that matches the
+ * condition.
+ * @method first
+ * @owner Observable
+ */
+function first(predicate, resultSelector, defaultValue) {
+ return function (source) { return source.lift(new FirstOperator(predicate, resultSelector, defaultValue, source)); };
+}
+exports.first = first;
+var FirstOperator = (function () {
+ function FirstOperator(predicate, resultSelector, defaultValue, source) {
+ this.predicate = predicate;
+ this.resultSelector = resultSelector;
+ this.defaultValue = defaultValue;
+ this.source = source;
+ }
+ FirstOperator.prototype.call = function (observer, source) {
+ return source.subscribe(new FirstSubscriber(observer, this.predicate, this.resultSelector, this.defaultValue, this.source));
+ };
+ return FirstOperator;
+}());
+/**
+ * We need this JSDoc comment for affecting ESDoc.
+ * @ignore
+ * @extends {Ignored}
+ */
+var FirstSubscriber = (function (_super) {
+ __extends(FirstSubscriber, _super);
+ function FirstSubscriber(destination, predicate, resultSelector, defaultValue, source) {
+ _super.call(this, destination);
+ this.predicate = predicate;
+ this.resultSelector = resultSelector;
+ this.defaultValue = defaultValue;
+ this.source = source;
+ this.index = 0;
+ this.hasCompleted = false;
+ this._emitted = false;
+ }
+ FirstSubscriber.prototype._next = function (value) {
+ var index = this.index++;
+ if (this.predicate) {
+ this._tryPredicate(value, index);
+ }
+ else {
+ this._emit(value, index);
+ }
+ };
+ FirstSubscriber.prototype._tryPredicate = function (value, index) {
+ var result;
+ try {
+ result = this.predicate(value, index, this.source);
+ }
+ catch (err) {
+ this.destination.error(err);
+ return;
+ }
+ if (result) {
+ this._emit(value, index);
+ }
+ };
+ FirstSubscriber.prototype._emit = function (value, index) {
+ if (this.resultSelector) {
+ this._tryResultSelector(value, index);
+ return;
+ }
+ this._emitFinal(value);
+ };
+ FirstSubscriber.prototype._tryResultSelector = function (value, index) {
+ var result;
+ try {
+ result = this.resultSelector(value, index);
+ }
+ catch (err) {
+ this.destination.error(err);
+ return;
+ }
+ this._emitFinal(result);
+ };
+ FirstSubscriber.prototype._emitFinal = function (value) {
+ var destination = this.destination;
+ if (!this._emitted) {
+ this._emitted = true;
+ destination.next(value);
+ destination.complete();
+ this.hasCompleted = true;
+ }
+ };
+ FirstSubscriber.prototype._complete = function () {
+ var destination = this.destination;
+ if (!this.hasCompleted && typeof this.defaultValue !== 'undefined') {
+ destination.next(this.defaultValue);
+ destination.complete();
+ }
+ else if (!this.hasCompleted) {
+ destination.error(new EmptyError_1.EmptyError);
+ }
+ };
+ return FirstSubscriber;
+}(Subscriber_1.Subscriber));
+
+},{"../Subscriber":36,"../util/EmptyError":220}],176:[function(require,module,exports){
+"use strict";
+var __extends = (this && this.__extends) || function (d, b) {
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+};
+var Subscriber_1 = require('../Subscriber');
+var EmptyError_1 = require('../util/EmptyError');
+/* tslint:enable:max-line-length */
+/**
+ * Returns an Observable that emits only the last item emitted by the source Observable.
+ * It optionally takes a predicate function as a parameter, in which case, rather than emitting
+ * the last item from the source Observable, the resulting Observable will emit the last item
+ * from the source Observable that satisfies the predicate.
+ *
+ * <img src="./img/last.png" width="100%">
+ *
+ * @throws {EmptyError} Delivers an EmptyError to the Observer's `error`
+ * callback if the Observable completes before any `next` notification was sent.
+ * @param {function} predicate - The condition any source emitted item has to satisfy.
+ * @return {Observable} An Observable that emits only the last item satisfying the given condition
+ * from the source, or an NoSuchElementException if no such items are emitted.
+ * @throws - Throws if no items that match the predicate are emitted by the source Observable.
+ * @method last
+ * @owner Observable
+ */
+function last(predicate, resultSelector, defaultValue) {
+ return function (source) { return source.lift(new LastOperator(predicate, resultSelector, defaultValue, source)); };
+}
+exports.last = last;
+var LastOperator = (function () {
+ function LastOperator(predicate, resultSelector, defaultValue, source) {
+ this.predicate = predicate;
+ this.resultSelector = resultSelector;
+ this.defaultValue = defaultValue;
+ this.source = source;
+ }
+ LastOperator.prototype.call = function (observer, source) {
+ return source.subscribe(new LastSubscriber(observer, this.predicate, this.resultSelector, this.defaultValue, this.source));
+ };
+ return LastOperator;
+}());
+/**
+ * We need this JSDoc comment for affecting ESDoc.
+ * @ignore
+ * @extends {Ignored}
+ */
+var LastSubscriber = (function (_super) {
+ __extends(LastSubscriber, _super);
+ function LastSubscriber(destination, predicate, resultSelector, defaultValue, source) {
+ _super.call(this, destination);
+ this.predicate = predicate;
+ this.resultSelector = resultSelector;
+ this.defaultValue = defaultValue;
+ this.source = source;
+ this.hasValue = false;
+ this.index = 0;
+ if (typeof defaultValue !== 'undefined') {
+ this.lastValue = defaultValue;
+ this.hasValue = true;
+ }
+ }
+ LastSubscriber.prototype._next = function (value) {
+ var index = this.index++;
+ if (this.predicate) {
+ this._tryPredicate(value, index);
+ }
+ else {
+ if (this.resultSelector) {
+ this._tryResultSelector(value, index);
+ return;
+ }
+ this.lastValue = value;
+ this.hasValue = true;
+ }
+ };
+ LastSubscriber.prototype._tryPredicate = function (value, index) {
+ var result;
+ try {
+ result = this.predicate(value, index, this.source);
+ }
+ catch (err) {
+ this.destination.error(err);
+ return;
+ }
+ if (result) {
+ if (this.resultSelector) {
+ this._tryResultSelector(value, index);
+ return;
+ }
+ this.lastValue = value;
+ this.hasValue = true;
+ }
+ };
+ LastSubscriber.prototype._tryResultSelector = function (value, index) {
+ var result;
+ try {
+ result = this.resultSelector(value, index);
+ }
+ catch (err) {
+ this.destination.error(err);
+ return;
+ }
+ this.lastValue = result;
+ this.hasValue = true;
+ };
+ LastSubscriber.prototype._complete = function () {
+ var destination = this.destination;
+ if (this.hasValue) {
+ destination.next(this.lastValue);
+ destination.complete();
+ }
+ else {
+ destination.error(new EmptyError_1.EmptyError);
+ }
+ };
+ return LastSubscriber;
+}(Subscriber_1.Subscriber));
+
+},{"../Subscriber":36,"../util/EmptyError":220}],177:[function(require,module,exports){
+"use strict";
+var __extends = (this && this.__extends) || function (d, b) {
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+};
+var Subscriber_1 = require('../Subscriber');
+/**
+ * Applies a given `project` function to each value emitted by the source
+ * Observable, and emits the resulting values as an Observable.
+ *
+ * <span class="informal">Like [Array.prototype.map()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map),
+ * it passes each source value through a transformation function to get
+ * corresponding output values.</span>
+ *
+ * <img src="./img/map.png" width="100%">
+ *
+ * Similar to the well known `Array.prototype.map` function, this operator
+ * applies a projection to each value and emits that projection in the output
+ * Observable.
+ *
+ * @example <caption>Map every click to the clientX position of that click</caption>
+ * var clicks = Rx.Observable.fromEvent(document, 'click');
+ * var positions = clicks.map(ev => ev.clientX);
+ * positions.subscribe(x => console.log(x));
+ *
+ * @see {@link mapTo}
+ * @see {@link pluck}
+ *
+ * @param {function(value: T, index: number): R} project The function to apply
+ * to each `value` emitted by the source Observable. The `index` parameter is
+ * the number `i` for the i-th emission that has happened since the
+ * subscription, starting from the number `0`.
+ * @param {any} [thisArg] An optional argument to define what `this` is in the
+ * `project` function.
+ * @return {Observable<R>} An Observable that emits the values from the source
+ * Observable transformed by the given `project` function.
+ * @method map
+ * @owner Observable
+ */
+function map(project, thisArg) {
+ return function mapOperation(source) {
+ if (typeof project !== 'function') {
+ throw new TypeError('argument is not a function. Are you looking for `mapTo()`?');
+ }
+ return source.lift(new MapOperator(project, thisArg));
+ };
+}
+exports.map = map;
+var MapOperator = (function () {
+ function MapOperator(project, thisArg) {
+ this.project = project;
+ this.thisArg = thisArg;
+ }
+ MapOperator.prototype.call = function (subscriber, source) {
+ return source.subscribe(new MapSubscriber(subscriber, this.project, this.thisArg));
+ };
+ return MapOperator;
+}());
+exports.MapOperator = MapOperator;
+/**
+ * We need this JSDoc comment for affecting ESDoc.
+ * @ignore
+ * @extends {Ignored}
+ */
+var MapSubscriber = (function (_super) {
+ __extends(MapSubscriber, _super);
+ function MapSubscriber(destination, project, thisArg) {
+ _super.call(this, destination);
+ this.project = project;
+ this.count = 0;
+ this.thisArg = thisArg || this;
+ }
+ // NOTE: This looks unoptimized, but it's actually purposefully NOT
+ // using try/catch optimizations.
+ MapSubscriber.prototype._next = function (value) {
+ var result;
+ try {
+ result = this.project.call(this.thisArg, value, this.count++);
+ }
+ catch (err) {
+ this.destination.error(err);
+ return;
+ }
+ this.destination.next(result);
+ };
+ return MapSubscriber;
+}(Subscriber_1.Subscriber));
+
+},{"../Subscriber":36}],178:[function(require,module,exports){
+"use strict";
+var Observable_1 = require('../Observable');
+var ArrayObservable_1 = require('../observable/ArrayObservable');
+var mergeAll_1 = require('./mergeAll');
+var isScheduler_1 = require('../util/isScheduler');
+/* tslint:enable:max-line-length */
+function merge() {
+ var observables = [];
+ for (var _i = 0; _i < arguments.length; _i++) {
+ observables[_i - 0] = arguments[_i];
+ }
+ return function (source) { return source.lift.call(mergeStatic.apply(void 0, [source].concat(observables))); };
+}
+exports.merge = merge;
+/* tslint:enable:max-line-length */
+/**
+ * Creates an output Observable which concurrently emits all values from every
+ * given input Observable.
+ *
+ * <span class="informal">Flattens multiple Observables together by blending
+ * their values into one Observable.</span>
+ *
+ * <img src="./img/merge.png" width="100%">
+ *
+ * `merge` subscribes to each given input Observable (as arguments), and simply
+ * forwards (without doing any transformation) all the values from all the input
+ * Observables to the output Observable. The output Observable only completes
+ * once all input Observables have completed. Any error delivered by an input
+ * Observable will be immediately emitted on the output Observable.
+ *
+ * @example <caption>Merge together two Observables: 1s interval and clicks</caption>
+ * var clicks = Rx.Observable.fromEvent(document, 'click');
+ * var timer = Rx.Observable.interval(1000);
+ * var clicksOrTimer = Rx.Observable.merge(clicks, timer);
+ * clicksOrTimer.subscribe(x => console.log(x));
+ *
+ * // Results in the following:
+ * // timer will emit ascending values, one every second(1000ms) to console
+ * // clicks logs MouseEvents to console everytime the "document" is clicked
+ * // Since the two streams are merged you see these happening
+ * // as they occur.
+ *
+ * @example <caption>Merge together 3 Observables, but only 2 run concurrently</caption>
+ * var timer1 = Rx.Observable.interval(1000).take(10);
+ * var timer2 = Rx.Observable.interval(2000).take(6);
+ * var timer3 = Rx.Observable.interval(500).take(10);
+ * var concurrent = 2; // the argument
+ * var merged = Rx.Observable.merge(timer1, timer2, timer3, concurrent);
+ * merged.subscribe(x => console.log(x));
+ *
+ * // Results in the following:
+ * // - First timer1 and timer2 will run concurrently
+ * // - timer1 will emit a value every 1000ms for 10 iterations
+ * // - timer2 will emit a value every 2000ms for 6 iterations
+ * // - after timer1 hits it's max iteration, timer2 will
+ * // continue, and timer3 will start to run concurrently with timer2
+ * // - when timer2 hits it's max iteration it terminates, and
+ * // timer3 will continue to emit a value every 500ms until it is complete
+ *
+ * @see {@link mergeAll}
+ * @see {@link mergeMap}
+ * @see {@link mergeMapTo}
+ * @see {@link mergeScan}
+ *
+ * @param {...ObservableInput} observables Input Observables to merge together.
+ * @param {number} [concurrent=Number.POSITIVE_INFINITY] Maximum number of input
+ * Observables being subscribed to concurrently.
+ * @param {Scheduler} [scheduler=null] The IScheduler to use for managing
+ * concurrency of input Observables.
+ * @return {Observable} an Observable that emits items that are the result of
+ * every input Observable.
+ * @static true
+ * @name merge
+ * @owner Observable
+ */
+function mergeStatic() {
+ var observables = [];
+ for (var _i = 0; _i < arguments.length; _i++) {
+ observables[_i - 0] = arguments[_i];
+ }
+ var concurrent = Number.POSITIVE_INFINITY;
+ var scheduler = null;
+ var last = observables[observables.length - 1];
+ if (isScheduler_1.isScheduler(last)) {
+ scheduler = observables.pop();
+ if (observables.length > 1 && typeof observables[observables.length - 1] === 'number') {
+ concurrent = observables.pop();
+ }
+ }
+ else if (typeof last === 'number') {
+ concurrent = observables.pop();
+ }
+ if (scheduler === null && observables.length === 1 && observables[0] instanceof Observable_1.Observable) {
+ return observables[0];
+ }
+ return mergeAll_1.mergeAll(concurrent)(new ArrayObservable_1.ArrayObservable(observables, scheduler));
+}
+exports.mergeStatic = mergeStatic;
+
+},{"../Observable":29,"../observable/ArrayObservable":93,"../util/isScheduler":234,"./mergeAll":179}],179:[function(require,module,exports){
+"use strict";
+var mergeMap_1 = require('./mergeMap');
+var identity_1 = require('../util/identity');
+/**
+ * Converts a higher-order Observable into a first-order Observable which
+ * concurrently delivers all values that are emitted on the inner Observables.
+ *
+ * <span class="informal">Flattens an Observable-of-Observables.</span>
+ *
+ * <img src="./img/mergeAll.png" width="100%">
+ *
+ * `mergeAll` subscribes to an Observable that emits Observables, also known as
+ * a higher-order Observable. Each time it observes one of these emitted inner
+ * Observables, it subscribes to that and delivers all the values from the
+ * inner Observable on the output Observable. The output Observable only
+ * completes once all inner Observables have completed. Any error delivered by
+ * a inner Observable will be immediately emitted on the output Observable.
+ *
+ * @example <caption>Spawn a new interval Observable for each click event, and blend their outputs as one Observable</caption>
+ * var clicks = Rx.Observable.fromEvent(document, 'click');
+ * var higherOrder = clicks.map((ev) => Rx.Observable.interval(1000));
+ * var firstOrder = higherOrder.mergeAll();
+ * firstOrder.subscribe(x => console.log(x));
+ *
+ * @example <caption>Count from 0 to 9 every second for each click, but only allow 2 concurrent timers</caption>
+ * var clicks = Rx.Observable.fromEvent(document, 'click');
+ * var higherOrder = clicks.map((ev) => Rx.Observable.interval(1000).take(10));
+ * var firstOrder = higherOrder.mergeAll(2);
+ * firstOrder.subscribe(x => console.log(x));
+ *
+ * @see {@link combineAll}
+ * @see {@link concatAll}
+ * @see {@link exhaust}
+ * @see {@link merge}
+ * @see {@link mergeMap}
+ * @see {@link mergeMapTo}
+ * @see {@link mergeScan}
+ * @see {@link switch}
+ * @see {@link zipAll}
+ *
+ * @param {number} [concurrent=Number.POSITIVE_INFINITY] Maximum number of inner
+ * Observables being subscribed to concurrently.
+ * @return {Observable} An Observable that emits values coming from all the
+ * inner Observables emitted by the source Observable.
+ * @method mergeAll
+ * @owner Observable
+ */
+function mergeAll(concurrent) {
+ if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
+ return mergeMap_1.mergeMap(identity_1.identity, null, concurrent);
+}
+exports.mergeAll = mergeAll;
+
+},{"../util/identity":226,"./mergeMap":180}],180:[function(require,module,exports){
+"use strict";
+var __extends = (this && this.__extends) || function (d, b) {
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+};
+var subscribeToResult_1 = require('../util/subscribeToResult');
+var OuterSubscriber_1 = require('../OuterSubscriber');
+/* tslint:enable:max-line-length */
+/**
+ * Projects each source value to an Observable which is merged in the output
+ * Observable.
+ *
+ * <span class="informal">Maps each value to an Observable, then flattens all of
+ * these inner Observables using {@link mergeAll}.</span>
+ *
+ * <img src="./img/mergeMap.png" width="100%">
+ *
+ * Returns an Observable that emits items based on applying a function that you
+ * supply to each item emitted by the source Observable, where that function
+ * returns an Observable, and then merging those resulting Observables and
+ * emitting the results of this merger.
+ *
+ * @example <caption>Map and flatten each letter to an Observable ticking every 1 second</caption>
+ * var letters = Rx.Observable.of('a', 'b', 'c');
+ * var result = letters.mergeMap(x =>
+ * Rx.Observable.interval(1000).map(i => x+i)
+ * );
+ * result.subscribe(x => console.log(x));
+ *
+ * // Results in the following:
+ * // a0
+ * // b0
+ * // c0
+ * // a1
+ * // b1
+ * // c1
+ * // continues to list a,b,c with respective ascending integers
+ *
+ * @see {@link concatMap}
+ * @see {@link exhaustMap}
+ * @see {@link merge}
+ * @see {@link mergeAll}
+ * @see {@link mergeMapTo}
+ * @see {@link mergeScan}
+ * @see {@link switchMap}
+ *
+ * @param {function(value: T, ?index: number): ObservableInput} project A function
+ * that, when applied to an item emitted by the source Observable, returns an
+ * Observable.
+ * @param {function(outerValue: T, innerValue: I, outerIndex: number, innerIndex: number): any} [resultSelector]
+ * A function to produce the value on the output Observable based on the values
+ * and the indices of the source (outer) emission and the inner Observable
+ * emission. The arguments passed to this function are:
+ * - `outerValue`: the value that came from the source
+ * - `innerValue`: the value that came from the projected Observable
+ * - `outerIndex`: the "index" of the value that came from the source
+ * - `innerIndex`: the "index" of the value from the projected Observable
+ * @param {number} [concurrent=Number.POSITIVE_INFINITY] Maximum number of input
+ * Observables being subscribed to concurrently.
+ * @return {Observable} An Observable that emits the result of applying the
+ * projection function (and the optional `resultSelector`) to each item emitted
+ * by the source Observable and merging the results of the Observables obtained
+ * from this transformation.
+ * @method mergeMap
+ * @owner Observable
+ */
+function mergeMap(project, resultSelector, concurrent) {
+ if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
+ return function mergeMapOperatorFunction(source) {
+ if (typeof resultSelector === 'number') {
+ concurrent = resultSelector;
+ resultSelector = null;
+ }
+ return source.lift(new MergeMapOperator(project, resultSelector, concurrent));
+ };
+}
+exports.mergeMap = mergeMap;
+var MergeMapOperator = (function () {
+ function MergeMapOperator(project, resultSelector, concurrent) {
+ if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
+ this.project = project;
+ this.resultSelector = resultSelector;
+ this.concurrent = concurrent;
+ }
+ MergeMapOperator.prototype.call = function (observer, source) {
+ return source.subscribe(new MergeMapSubscriber(observer, this.project, this.resultSelector, this.concurrent));
+ };
+ return MergeMapOperator;
+}());
+exports.MergeMapOperator = MergeMapOperator;
+/**
+ * We need this JSDoc comment for affecting ESDoc.
+ * @ignore
+ * @extends {Ignored}
+ */
+var MergeMapSubscriber = (function (_super) {
+ __extends(MergeMapSubscriber, _super);
+ function MergeMapSubscriber(destination, project, resultSelector, concurrent) {
+ if (concurrent === void 0) { concurrent = Number.POSITIVE_INFINITY; }
+ _super.call(this, destination);
+ this.project = project;
+ this.resultSelector = resultSelector;
+ this.concurrent = concurrent;
+ this.hasCompleted = false;
+ this.buffer = [];
+ this.active = 0;
+ this.index = 0;
+ }
+ MergeMapSubscriber.prototype._next = function (value) {
+ if (this.active < this.concurrent) {
+ this._tryNext(value);
+ }
+ else {
+ this.buffer.push(value);
+ }
+ };
+ MergeMapSubscriber.prototype._tryNext = function (value) {
+ var result;
+ var index = this.index++;
+ try {
+ result = this.project(value, index);
+ }
+ catch (err) {
+ this.destination.error(err);
+ return;
+ }
+ this.active++;
+ this._innerSub(result, value, index);
+ };
+ MergeMapSubscriber.prototype._innerSub = function (ish, value, index) {
+ this.add(subscribeToResult_1.subscribeToResult(this, ish, value, index));
+ };
+ MergeMapSubscriber.prototype._complete = function () {
+ this.hasCompleted = true;
+ if (this.active === 0 && this.buffer.length === 0) {
+ this.destination.complete();
+ }
+ };
+ MergeMapSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
+ if (this.resultSelector) {
+ this._notifyResultSelector(outerValue, innerValue, outerIndex, innerIndex);
+ }
+ else {
+ this.destination.next(innerValue);
+ }
+ };
+ MergeMapSubscriber.prototype._notifyResultSelector = function (outerValue, innerValue, outerIndex, innerIndex) {
+ var result;
+ try {
+ result = this.resultSelector(outerValue, innerValue, outerIndex, innerIndex);
+ }
+ catch (err) {
+ this.destination.error(err);
+ return;
+ }
+ this.destination.next(result);
+ };
+ MergeMapSubscriber.prototype.notifyComplete = function (innerSub) {
+ var buffer = this.buffer;
+ this.remove(innerSub);
+ this.active--;
+ if (buffer.length > 0) {
+ this._next(buffer.shift());
+ }
+ else if (this.active === 0 && this.hasCompleted) {
+ this.destination.complete();
+ }
+ };
+ return MergeMapSubscriber;
+}(OuterSubscriber_1.OuterSubscriber));
+exports.MergeMapSubscriber = MergeMapSubscriber;
+
+},{"../OuterSubscriber":31,"../util/subscribeToResult":238}],181:[function(require,module,exports){
+"use strict";
+var ConnectableObservable_1 = require('../observable/ConnectableObservable');
+/* tslint:enable:max-line-length */
+/**
+ * Returns an Observable that emits the results of invoking a specified selector on items
+ * emitted by a ConnectableObservable that shares a single subscription to the underlying stream.
+ *
+ * <img src="./img/multicast.png" width="100%">
+ *
+ * @param {Function|Subject} subjectOrSubjectFactory - Factory function to create an intermediate subject through
+ * which the source sequence's elements will be multicast to the selector function
+ * or Subject to push source elements into.
+ * @param {Function} [selector] - Optional selector function that can use the multicasted source stream
+ * as many times as needed, without causing multiple subscriptions to the source stream.
+ * Subscribers to the given source will receive all notifications of the source from the
+ * time of the subscription forward.
+ * @return {Observable} An Observable that emits the results of invoking the selector
+ * on the items emitted by a `ConnectableObservable` that shares a single subscription to
+ * the underlying stream.
+ * @method multicast
+ * @owner Observable
+ */
+function multicast(subjectOrSubjectFactory, selector) {
+ return function multicastOperatorFunction(source) {
+ var subjectFactory;
+ if (typeof subjectOrSubjectFactory === 'function') {
+ subjectFactory = subjectOrSubjectFactory;
+ }
+ else {
+ subjectFactory = function subjectFactory() {
+ return subjectOrSubjectFactory;
+ };
+ }
+ if (typeof selector === 'function') {
+ return source.lift(new MulticastOperator(subjectFactory, selector));
+ }
+ var connectable = Object.create(source, ConnectableObservable_1.connectableObservableDescriptor);
+ connectable.source = source;
+ connectable.subjectFactory = subjectFactory;
+ return connectable;
+ };
+}
+exports.multicast = multicast;
+var MulticastOperator = (function () {
+ function MulticastOperator(subjectFactory, selector) {
+ this.subjectFactory = subjectFactory;
+ this.selector = selector;
+ }
+ MulticastOperator.prototype.call = function (subscriber, source) {
+ var selector = this.selector;
+ var subject = this.subjectFactory();
+ var subscription = selector(subject).subscribe(subscriber);
+ subscription.add(source.subscribe(subject));
+ return subscription;
+ };
+ return MulticastOperator;
+}());
+exports.MulticastOperator = MulticastOperator;
+
+},{"../observable/ConnectableObservable":94}],182:[function(require,module,exports){
+"use strict";
+var __extends = (this && this.__extends) || function (d, b) {
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+};
+var Subscriber_1 = require('../Subscriber');
+var Notification_1 = require('../Notification');
+/**
+ *
+ * Re-emits all notifications from source Observable with specified scheduler.
+ *
+ * <span class="informal">Ensure a specific scheduler is used, from outside of an Observable.</span>
+ *
+ * `observeOn` is an operator that accepts a scheduler as a first parameter, which will be used to reschedule
+ * notifications emitted by the source Observable. It might be useful, if you do not have control over
+ * internal scheduler of a given Observable, but want to control when its values are emitted nevertheless.
+ *
+ * Returned Observable emits the same notifications (nexted values, complete and error events) as the source Observable,
+ * but rescheduled with provided scheduler. Note that this doesn't mean that source Observables internal
+ * scheduler will be replaced in any way. Original scheduler still will be used, but when the source Observable emits
+ * notification, it will be immediately scheduled again - this time with scheduler passed to `observeOn`.
+ * An anti-pattern would be calling `observeOn` on Observable that emits lots of values synchronously, to split
+ * that emissions into asynchronous chunks. For this to happen, scheduler would have to be passed into the source
+ * Observable directly (usually into the operator that creates it). `observeOn` simply delays notifications a
+ * little bit more, to ensure that they are emitted at expected moments.
+ *
+ * As a matter of fact, `observeOn` accepts second parameter, which specifies in milliseconds with what delay notifications
+ * will be emitted. The main difference between {@link delay} operator and `observeOn` is that `observeOn`
+ * will delay all notifications - including error notifications - while `delay` will pass through error
+ * from source Observable immediately when it is emitted. In general it is highly recommended to use `delay` operator
+ * for any kind of delaying of values in the stream, while using `observeOn` to specify which scheduler should be used
+ * for notification emissions in general.
+ *
+ * @example <caption>Ensure values in subscribe are called just before browser repaint.</caption>
+ * const intervals = Rx.Observable.interval(10); // Intervals are scheduled
+ * // with async scheduler by default...
+ *
+ * intervals
+ * .observeOn(Rx.Scheduler.animationFrame) // ...but we will observe on animationFrame
+ * .subscribe(val => { // scheduler to ensure smooth animation.
+ * someDiv.style.height = val + 'px';
+ * });
+ *
+ * @see {@link delay}
+ *
+ * @param {IScheduler} scheduler Scheduler that will be used to reschedule notifications from source Observable.
+ * @param {number} [delay] Number of milliseconds that states with what delay every notification should be rescheduled.
+ * @return {Observable<T>} Observable that emits the same notifications as the source Observable,
+ * but with provided scheduler.
+ *
+ * @method observeOn
+ * @owner Observable
+ */
+function observeOn(scheduler, delay) {
+ if (delay === void 0) { delay = 0; }
+ return function observeOnOperatorFunction(source) {
+ return source.lift(new ObserveOnOperator(scheduler, delay));
+ };
+}
+exports.observeOn = observeOn;
+var ObserveOnOperator = (function () {
+ function ObserveOnOperator(scheduler, delay) {
+ if (delay === void 0) { delay = 0; }
+ this.scheduler = scheduler;
+ this.delay = delay;
+ }
+ ObserveOnOperator.prototype.call = function (subscriber, source) {
+ return source.subscribe(new ObserveOnSubscriber(subscriber, this.scheduler, this.delay));
+ };
+ return ObserveOnOperator;
+}());
+exports.ObserveOnOperator = ObserveOnOperator;
+/**
+ * We need this JSDoc comment for affecting ESDoc.
+ * @ignore
+ * @extends {Ignored}
+ */
+var ObserveOnSubscriber = (function (_super) {
+ __extends(ObserveOnSubscriber, _super);
+ function ObserveOnSubscriber(destination, scheduler, delay) {
+ if (delay === void 0) { delay = 0; }
+ _super.call(this, destination);
+ this.scheduler = scheduler;
+ this.delay = delay;
+ }
+ ObserveOnSubscriber.dispatch = function (arg) {
+ var notification = arg.notification, destination = arg.destination;
+ notification.observe(destination);
+ this.unsubscribe();
+ };
+ ObserveOnSubscriber.prototype.scheduleMessage = function (notification) {
+ this.add(this.scheduler.schedule(ObserveOnSubscriber.dispatch, this.delay, new ObserveOnMessage(notification, this.destination)));
+ };
+ ObserveOnSubscriber.prototype._next = function (value) {
+ this.scheduleMessage(Notification_1.Notification.createNext(value));
+ };
+ ObserveOnSubscriber.prototype._error = function (err) {
+ this.scheduleMessage(Notification_1.Notification.createError(err));
+ };
+ ObserveOnSubscriber.prototype._complete = function () {
+ this.scheduleMessage(Notification_1.Notification.createComplete());
+ };
+ return ObserveOnSubscriber;
+}(Subscriber_1.Subscriber));
+exports.ObserveOnSubscriber = ObserveOnSubscriber;
+var ObserveOnMessage = (function () {
+ function ObserveOnMessage(notification, destination) {
+ this.notification = notification;
+ this.destination = destination;
+ }
+ return ObserveOnMessage;
+}());
+exports.ObserveOnMessage = ObserveOnMessage;
+
+},{"../Notification":28,"../Subscriber":36}],183:[function(require,module,exports){
+"use strict";
+var __extends = (this && this.__extends) || function (d, b) {
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+};
+var Subscriber_1 = require('../Subscriber');
+/**
+ * Groups pairs of consecutive emissions together and emits them as an array of
+ * two values.
+ *
+ * <span class="informal">Puts the current value and previous value together as
+ * an array, and emits that.</span>
+ *
+ * <img src="./img/pairwise.png" width="100%">
+ *
+ * The Nth emission from the source Observable will cause the output Observable
+ * to emit an array [(N-1)th, Nth] of the previous and the current value, as a
+ * pair. For this reason, `pairwise` emits on the second and subsequent
+ * emissions from the source Observable, but not on the first emission, because
+ * there is no previous value in that case.
+ *
+ * @example <caption>On every click (starting from the second), emit the relative distance to the previous click</caption>
+ * var clicks = Rx.Observable.fromEvent(document, 'click');
+ * var pairs = clicks.pairwise();
+ * var distance = pairs.map(pair => {
+ * var x0 = pair[0].clientX;
+ * var y0 = pair[0].clientY;
+ * var x1 = pair[1].clientX;
+ * var y1 = pair[1].clientY;
+ * return Math.sqrt(Math.pow(x0 - x1, 2) + Math.pow(y0 - y1, 2));
+ * });
+ * distance.subscribe(x => console.log(x));
+ *
+ * @see {@link buffer}
+ * @see {@link bufferCount}
+ *
+ * @return {Observable<Array<T>>} An Observable of pairs (as arrays) of
+ * consecutive values from the source Observable.
+ * @method pairwise
+ * @owner Observable
+ */
+function pairwise() {
+ return function (source) { return source.lift(new PairwiseOperator()); };
+}
+exports.pairwise = pairwise;
+var PairwiseOperator = (function () {
+ function PairwiseOperator() {
+ }
+ PairwiseOperator.prototype.call = function (subscriber, source) {
+ return source.subscribe(new PairwiseSubscriber(subscriber));
+ };
+ return PairwiseOperator;
+}());
+/**
+ * We need this JSDoc comment for affecting ESDoc.
+ * @ignore
+ * @extends {Ignored}
+ */
+var PairwiseSubscriber = (function (_super) {
+ __extends(PairwiseSubscriber, _super);
+ function PairwiseSubscriber(destination) {
+ _super.call(this, destination);
+ this.hasPrev = false;
+ }
+ PairwiseSubscriber.prototype._next = function (value) {
+ if (this.hasPrev) {
+ this.destination.next([this.prev, value]);
+ }
+ else {
+ this.hasPrev = true;
+ }
+ this.prev = value;
+ };
+ return PairwiseSubscriber;
+}(Subscriber_1.Subscriber));
+
+},{"../Subscriber":36}],184:[function(require,module,exports){
+"use strict";
+var map_1 = require('./map');
+/**
+ * Maps each source value (an object) to its specified nested property.
+ *
+ * <span class="informal">Like {@link map}, but meant only for picking one of
+ * the nested properties of every emitted object.</span>
+ *
+ * <img src="./img/pluck.png" width="100%">
+ *
+ * Given a list of strings describing a path to an object property, retrieves
+ * the value of a specified nested property from all values in the source
+ * Observable. If a property can't be resolved, it will return `undefined` for
+ * that value.
+ *
+ * @example <caption>Map every click to the tagName of the clicked target element</caption>
+ * var clicks = Rx.Observable.fromEvent(document, 'click');
+ * var tagNames = clicks.pluck('target', 'tagName');
+ * tagNames.subscribe(x => console.log(x));
+ *
+ * @see {@link map}
+ *
+ * @param {...string} properties The nested properties to pluck from each source
+ * value (an object).
+ * @return {Observable} A new Observable of property values from the source values.
+ * @method pluck
+ * @owner Observable
+ */
+function pluck() {
+ var properties = [];
+ for (var _i = 0; _i < arguments.length; _i++) {
+ properties[_i - 0] = arguments[_i];
+ }
+ var length = properties.length;
+ if (length === 0) {
+ throw new Error('list of properties cannot be empty.');
+ }
+ return function (source) { return map_1.map(plucker(properties, length))(source); };
+}
+exports.pluck = pluck;
+function plucker(props, length) {
+ var mapper = function (x) {
+ var currentProp = x;
+ for (var i = 0; i < length; i++) {
+ var p = currentProp[props[i]];
+ if (typeof p !== 'undefined') {
+ currentProp = p;
+ }
+ else {
+ return undefined;
+ }
+ }
+ return currentProp;
+ };
+ return mapper;
+}
+
+},{"./map":177}],185:[function(require,module,exports){
+"use strict";
+var Subject_1 = require('../Subject');
+var multicast_1 = require('./multicast');
+/* tslint:enable:max-line-length */
+/**
+ * Returns a ConnectableObservable, which is a variety of Observable that waits until its connect method is called
+ * before it begins emitting items to those Observers that have subscribed to it.
+ *
+ * <img src="./img/publish.png" width="100%">
+ *
+ * @param {Function} [selector] - Optional selector function which can use the multicasted source sequence as many times
+ * as needed, without causing multiple subscriptions to the source sequence.
+ * Subscribers to the given source will receive all notifications of the source from the time of the subscription on.
+ * @return A ConnectableObservable that upon connection causes the source Observable to emit items to its Observers.
+ * @method publish
+ * @owner Observable
+ */
+function publish(selector) {
+ return selector ?
+ multicast_1.multicast(function () { return new Subject_1.Subject(); }, selector) :
+ multicast_1.multicast(new Subject_1.Subject());
+}
+exports.publish = publish;
+
+},{"../Subject":34,"./multicast":181}],186:[function(require,module,exports){
+"use strict";
+var ReplaySubject_1 = require('../ReplaySubject');
+var multicast_1 = require('./multicast');
+/* tslint:enable:max-line-length */
+function publishReplay(bufferSize, windowTime, selectorOrScheduler, scheduler) {
+ if (selectorOrScheduler && typeof selectorOrScheduler !== 'function') {
+ scheduler = selectorOrScheduler;
+ }
+ var selector = typeof selectorOrScheduler === 'function' ? selectorOrScheduler : undefined;
+ var subject = new ReplaySubject_1.ReplaySubject(bufferSize, windowTime, scheduler);
+ return function (source) { return multicast_1.multicast(function () { return subject; }, selector)(source); };
+}
+exports.publishReplay = publishReplay;
+
+},{"../ReplaySubject":32,"./multicast":181}],187:[function(require,module,exports){
+"use strict";
+var scan_1 = require('./scan');
+var takeLast_1 = require('./takeLast');
+var defaultIfEmpty_1 = require('./defaultIfEmpty');
+var pipe_1 = require('../util/pipe');
+/* tslint:enable:max-line-length */
+/**
+ * Applies an accumulator function over the source Observable, and returns the
+ * accumulated result when the source completes, given an optional seed value.
+ *
+ * <span class="informal">Combines together all values emitted on the source,
+ * using an accumulator function that knows how to join a new source value into
+ * the accumulation from the past.</span>
+ *
+ * <img src="./img/reduce.png" width="100%">
+ *
+ * Like
+ * [Array.prototype.reduce()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce),
+ * `reduce` applies an `accumulator` function against an accumulation and each
+ * value of the source Observable (from the past) to reduce it to a single
+ * value, emitted on the output Observable. Note that `reduce` will only emit
+ * one value, only when the source Observable completes. It is equivalent to
+ * applying operator {@link scan} followed by operator {@link last}.
+ *
+ * Returns an Observable that applies a specified `accumulator` function to each
+ * item emitted by the source Observable. If a `seed` value is specified, then
+ * that value will be used as the initial value for the accumulator. If no seed
+ * value is specified, the first item of the source is used as the seed.
+ *
+ * @example <caption>Count the number of click events that happened in 5 seconds</caption>
+ * var clicksInFiveSeconds = Rx.Observable.fromEvent(document, 'click')
+ * .takeUntil(Rx.Observable.interval(5000));
+ * var ones = clicksInFiveSeconds.mapTo(1);
+ * var seed = 0;
+ * var count = ones.reduce((acc, one) => acc + one, seed);
+ * count.subscribe(x => console.log(x));
+ *
+ * @see {@link count}
+ * @see {@link expand}
+ * @see {@link mergeScan}
+ * @see {@link scan}
+ *
+ * @param {function(acc: R, value: T, index: number): R} accumulator The accumulator function
+ * called on each source value.
+ * @param {R} [seed] The initial accumulation value.
+ * @return {Observable<R>} An Observable that emits a single value that is the
+ * result of accumulating the values emitted by the source Observable.
+ * @method reduce
+ * @owner Observable
+ */
+function reduce(accumulator, seed) {
+ // providing a seed of `undefined` *should* be valid and trigger
+ // hasSeed! so don't use `seed !== undefined` checks!
+ // For this reason, we have to check it here at the original call site
+ // otherwise inside Operator/Subscriber we won't know if `undefined`
+ // means they didn't provide anything or if they literally provided `undefined`
+ if (arguments.length >= 2) {
+ return function reduceOperatorFunctionWithSeed(source) {
+ return pipe_1.pipe(scan_1.scan(accumulator, seed), takeLast_1.takeLast(1), defaultIfEmpty_1.defaultIfEmpty(seed))(source);
+ };
+ }
+ return function reduceOperatorFunction(source) {
+ return pipe_1.pipe(scan_1.scan(function (acc, value, index) {
+ return accumulator(acc, value, index + 1);
+ }), takeLast_1.takeLast(1))(source);
+ };
+}
+exports.reduce = reduce;
+
+},{"../util/pipe":236,"./defaultIfEmpty":168,"./scan":191,"./takeLast":199}],188:[function(require,module,exports){
+"use strict";
+var __extends = (this && this.__extends) || function (d, b) {
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+};
+var Subscriber_1 = require('../Subscriber');
+function refCount() {
+ return function refCountOperatorFunction(source) {
+ return source.lift(new RefCountOperator(source));
+ };
+}
+exports.refCount = refCount;
+var RefCountOperator = (function () {
+ function RefCountOperator(connectable) {
+ this.connectable = connectable;
+ }
+ RefCountOperator.prototype.call = function (subscriber, source) {
+ var connectable = this.connectable;
+ connectable._refCount++;
+ var refCounter = new RefCountSubscriber(subscriber, connectable);
+ var subscription = source.subscribe(refCounter);
+ if (!refCounter.closed) {
+ refCounter.connection = connectable.connect();
+ }
+ return subscription;
+ };
+ return RefCountOperator;
+}());
+var RefCountSubscriber = (function (_super) {
+ __extends(RefCountSubscriber, _super);
+ function RefCountSubscriber(destination, connectable) {
+ _super.call(this, destination);
+ this.connectable = connectable;
+ }
+ RefCountSubscriber.prototype._unsubscribe = function () {
+ var connectable = this.connectable;
+ if (!connectable) {
+ this.connection = null;
+ return;
+ }
+ this.connectable = null;
+ var refCount = connectable._refCount;
+ if (refCount <= 0) {
+ this.connection = null;
+ return;
+ }
+ connectable._refCount = refCount - 1;
+ if (refCount > 1) {
+ this.connection = null;
+ return;
+ }
+ ///
+ // Compare the local RefCountSubscriber's connection Subscription to the
+ // connection Subscription on the shared ConnectableObservable. In cases
+ // where the ConnectableObservable source synchronously emits values, and
+ // the RefCountSubscriber's downstream Observers synchronously unsubscribe,
+ // execution continues to here before the RefCountOperator has a chance to
+ // supply the RefCountSubscriber with the shared connection Subscription.
+ // For example:
+ // ```
+ // Observable.range(0, 10)
+ // .publish()
+ // .refCount()
+ // .take(5)
+ // .subscribe();
+ // ```
+ // In order to account for this case, RefCountSubscriber should only dispose
+ // the ConnectableObservable's shared connection Subscription if the
+ // connection Subscription exists, *and* either:
+ // a. RefCountSubscriber doesn't have a reference to the shared connection
+ // Subscription yet, or,
+ // b. RefCountSubscriber's connection Subscription reference is identical
+ // to the shared connection Subscription
+ ///
+ var connection = this.connection;
+ var sharedConnection = connectable._connection;
+ this.connection = null;
+ if (sharedConnection && (!connection || sharedConnection === connection)) {
+ sharedConnection.unsubscribe();
+ }
+ };
+ return RefCountSubscriber;
+}(Subscriber_1.Subscriber));
+
+},{"../Subscriber":36}],189:[function(require,module,exports){
+"use strict";
+var __extends = (this && this.__extends) || function (d, b) {
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+};
+var Subscriber_1 = require('../Subscriber');
+/**
+ * Returns an Observable that mirrors the source Observable with the exception of an `error`. If the source Observable
+ * calls `error`, this method will resubscribe to the source Observable for a maximum of `count` resubscriptions (given
+ * as a number parameter) rather than propagating the `error` call.
+ *
+ * <img src="./img/retry.png" width="100%">
+ *
+ * Any and all items emitted by the source Observable will be emitted by the resulting Observable, even those emitted
+ * during failed subscriptions. For example, if an Observable fails at first but emits [1, 2] then succeeds the second
+ * time and emits: [1, 2, 3, 4, 5] then the complete stream of emissions and notifications
+ * would be: [1, 2, 1, 2, 3, 4, 5, `complete`].
+ * @param {number} count - Number of retry attempts before failing.
+ * @return {Observable} The source Observable modified with the retry logic.
+ * @method retry
+ * @owner Observable
+ */
+function retry(count) {
+ if (count === void 0) { count = -1; }
+ return function (source) { return source.lift(new RetryOperator(count, source)); };
+}
+exports.retry = retry;
+var RetryOperator = (function () {
+ function RetryOperator(count, source) {
+ this.count = count;
+ this.source = source;
+ }
+ RetryOperator.prototype.call = function (subscriber, source) {
+ return source.subscribe(new RetrySubscriber(subscriber, this.count, this.source));
+ };
+ return RetryOperator;
+}());
+/**
+ * We need this JSDoc comment for affecting ESDoc.
+ * @ignore
+ * @extends {Ignored}
+ */
+var RetrySubscriber = (function (_super) {
+ __extends(RetrySubscriber, _super);
+ function RetrySubscriber(destination, count, source) {
+ _super.call(this, destination);
+ this.count = count;
+ this.source = source;
+ }
+ RetrySubscriber.prototype.error = function (err) {
+ if (!this.isStopped) {
+ var _a = this, source = _a.source, count = _a.count;
+ if (count === 0) {
+ return _super.prototype.error.call(this, err);
+ }
+ else if (count > -1) {
+ this.count = count - 1;
+ }
+ source.subscribe(this._unsubscribeAndRecycle());
+ }
+ };
+ return RetrySubscriber;
+}(Subscriber_1.Subscriber));
+
+},{"../Subscriber":36}],190:[function(require,module,exports){
+"use strict";
+var __extends = (this && this.__extends) || function (d, b) {
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+};
+var OuterSubscriber_1 = require('../OuterSubscriber');
+var subscribeToResult_1 = require('../util/subscribeToResult');
+/**
+ * Emits the most recently emitted value from the source Observable whenever
+ * another Observable, the `notifier`, emits.
+ *
+ * <span class="informal">It's like {@link sampleTime}, but samples whenever
+ * the `notifier` Observable emits something.</span>
+ *
+ * <img src="./img/sample.png" width="100%">
+ *
+ * Whenever the `notifier` Observable emits a value or completes, `sample`
+ * looks at the source Observable and emits whichever value it has most recently
+ * emitted since the previous sampling, unless the source has not emitted
+ * anything since the previous sampling. The `notifier` is subscribed to as soon
+ * as the output Observable is subscribed.
+ *
+ * @example <caption>On every click, sample the most recent "seconds" timer</caption>
+ * var seconds = Rx.Observable.interval(1000);
+ * var clicks = Rx.Observable.fromEvent(document, 'click');
+ * var result = seconds.sample(clicks);
+ * result.subscribe(x => console.log(x));
+ *
+ * @see {@link audit}
+ * @see {@link debounce}
+ * @see {@link sampleTime}
+ * @see {@link throttle}
+ *
+ * @param {Observable<any>} notifier The Observable to use for sampling the
+ * source Observable.
+ * @return {Observable<T>} An Observable that emits the results of sampling the
+ * values emitted by the source Observable whenever the notifier Observable
+ * emits value or completes.
+ * @method sample
+ * @owner Observable
+ */
+function sample(notifier) {
+ return function (source) { return source.lift(new SampleOperator(notifier)); };
+}
+exports.sample = sample;
+var SampleOperator = (function () {
+ function SampleOperator(notifier) {
+ this.notifier = notifier;
+ }
+ SampleOperator.prototype.call = function (subscriber, source) {
+ var sampleSubscriber = new SampleSubscriber(subscriber);
+ var subscription = source.subscribe(sampleSubscriber);
+ subscription.add(subscribeToResult_1.subscribeToResult(sampleSubscriber, this.notifier));
+ return subscription;
+ };
+ return SampleOperator;
+}());
+/**
+ * We need this JSDoc comment for affecting ESDoc.
+ * @ignore
+ * @extends {Ignored}
+ */
+var SampleSubscriber = (function (_super) {
+ __extends(SampleSubscriber, _super);
+ function SampleSubscriber() {
+ _super.apply(this, arguments);
+ this.hasValue = false;
+ }
+ SampleSubscriber.prototype._next = function (value) {
+ this.value = value;
+ this.hasValue = true;
+ };
+ SampleSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
+ this.emitValue();
+ };
+ SampleSubscriber.prototype.notifyComplete = function () {
+ this.emitValue();
+ };
+ SampleSubscriber.prototype.emitValue = function () {
+ if (this.hasValue) {
+ this.hasValue = false;
+ this.destination.next(this.value);
+ }
+ };
+ return SampleSubscriber;
+}(OuterSubscriber_1.OuterSubscriber));
+
+},{"../OuterSubscriber":31,"../util/subscribeToResult":238}],191:[function(require,module,exports){
+"use strict";
+var __extends = (this && this.__extends) || function (d, b) {
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+};
+var Subscriber_1 = require('../Subscriber');
+/* tslint:enable:max-line-length */
+/**
+ * Applies an accumulator function over the source Observable, and returns each
+ * intermediate result, with an optional seed value.
+ *
+ * <span class="informal">It's like {@link reduce}, but emits the current
+ * accumulation whenever the source emits a value.</span>
+ *
+ * <img src="./img/scan.png" width="100%">
+ *
+ * Combines together all values emitted on the source, using an accumulator
+ * function that knows how to join a new source value into the accumulation from
+ * the past. Is similar to {@link reduce}, but emits the intermediate
+ * accumulations.
+ *
+ * Returns an Observable that applies a specified `accumulator` function to each
+ * item emitted by the source Observable. If a `seed` value is specified, then
+ * that value will be used as the initial value for the accumulator. If no seed
+ * value is specified, the first item of the source is used as the seed.
+ *
+ * @example <caption>Count the number of click events</caption>
+ * var clicks = Rx.Observable.fromEvent(document, 'click');
+ * var ones = clicks.mapTo(1);
+ * var seed = 0;
+ * var count = ones.scan((acc, one) => acc + one, seed);
+ * count.subscribe(x => console.log(x));
+ *
+ * @see {@link expand}
+ * @see {@link mergeScan}
+ * @see {@link reduce}
+ *
+ * @param {function(acc: R, value: T, index: number): R} accumulator
+ * The accumulator function called on each source value.
+ * @param {T|R} [seed] The initial accumulation value.
+ * @return {Observable<R>} An observable of the accumulated values.
+ * @method scan
+ * @owner Observable
+ */
+function scan(accumulator, seed) {
+ var hasSeed = false;
+ // providing a seed of `undefined` *should* be valid and trigger
+ // hasSeed! so don't use `seed !== undefined` checks!
+ // For this reason, we have to check it here at the original call site
+ // otherwise inside Operator/Subscriber we won't know if `undefined`
+ // means they didn't provide anything or if they literally provided `undefined`
+ if (arguments.length >= 2) {
+ hasSeed = true;
+ }
+ return function scanOperatorFunction(source) {
+ return source.lift(new ScanOperator(accumulator, seed, hasSeed));
+ };
+}
+exports.scan = scan;
+var ScanOperator = (function () {
+ function ScanOperator(accumulator, seed, hasSeed) {
+ if (hasSeed === void 0) { hasSeed = false; }
+ this.accumulator = accumulator;
+ this.seed = seed;
+ this.hasSeed = hasSeed;
+ }
+ ScanOperator.prototype.call = function (subscriber, source) {
+ return source.subscribe(new ScanSubscriber(subscriber, this.accumulator, this.seed, this.hasSeed));
+ };
+ return ScanOperator;
+}());
+/**
+ * We need this JSDoc comment for affecting ESDoc.
+ * @ignore
+ * @extends {Ignored}
+ */
+var ScanSubscriber = (function (_super) {
+ __extends(ScanSubscriber, _super);
+ function ScanSubscriber(destination, accumulator, _seed, hasSeed) {
+ _super.call(this, destination);
+ this.accumulator = accumulator;
+ this._seed = _seed;
+ this.hasSeed = hasSeed;
+ this.index = 0;
+ }
+ Object.defineProperty(ScanSubscriber.prototype, "seed", {
+ get: function () {
+ return this._seed;
+ },
+ set: function (value) {
+ this.hasSeed = true;
+ this._seed = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ ScanSubscriber.prototype._next = function (value) {
+ if (!this.hasSeed) {
+ this.seed = value;
+ this.destination.next(value);
+ }
+ else {
+ return this._tryNext(value);
+ }
+ };
+ ScanSubscriber.prototype._tryNext = function (value) {
+ var index = this.index++;
+ var result;
+ try {
+ result = this.accumulator(this.seed, value, index);
+ }
+ catch (err) {
+ this.destination.error(err);
+ }
+ this.seed = result;
+ this.destination.next(result);
+ };
+ return ScanSubscriber;
+}(Subscriber_1.Subscriber));
+
+},{"../Subscriber":36}],192:[function(require,module,exports){
+"use strict";
+var multicast_1 = require('./multicast');
+var refCount_1 = require('./refCount');
+var Subject_1 = require('../Subject');
+function shareSubjectFactory() {
+ return new Subject_1.Subject();
+}
+/**
+ * Returns a new Observable that multicasts (shares) the original Observable. As long as there is at least one
+ * Subscriber this Observable will be subscribed and emitting data. When all subscribers have unsubscribed it will
+ * unsubscribe from the source Observable. Because the Observable is multicasting it makes the stream `hot`.
+ * This is an alias for .multicast(() => new Subject()).refCount().
+ *
+ * <img src="./img/share.png" width="100%">
+ *
+ * @return {Observable<T>} An Observable that upon connection causes the source Observable to emit items to its Observers.
+ * @method share
+ * @owner Observable
+ */
+function share() {
+ return function (source) { return refCount_1.refCount()(multicast_1.multicast(shareSubjectFactory)(source)); };
+}
+exports.share = share;
+;
+
+},{"../Subject":34,"./multicast":181,"./refCount":188}],193:[function(require,module,exports){
+"use strict";
+var __extends = (this && this.__extends) || function (d, b) {
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+};
+var Subscriber_1 = require('../Subscriber');
+/**
+ * Returns an Observable that skips the first `count` items emitted by the source Observable.
+ *
+ * <img src="./img/skip.png" width="100%">
+ *
+ * @param {Number} count - The number of times, items emitted by source Observable should be skipped.
+ * @return {Observable} An Observable that skips values emitted by the source Observable.
+ *
+ * @method skip
+ * @owner Observable
+ */
+function skip(count) {
+ return function (source) { return source.lift(new SkipOperator(count)); };
+}
+exports.skip = skip;
+var SkipOperator = (function () {
+ function SkipOperator(total) {
+ this.total = total;
+ }
+ SkipOperator.prototype.call = function (subscriber, source) {
+ return source.subscribe(new SkipSubscriber(subscriber, this.total));
+ };
+ return SkipOperator;
+}());
+/**
+ * We need this JSDoc comment for affecting ESDoc.
+ * @ignore
+ * @extends {Ignored}
+ */
+var SkipSubscriber = (function (_super) {
+ __extends(SkipSubscriber, _super);
+ function SkipSubscriber(destination, total) {
+ _super.call(this, destination);
+ this.total = total;
+ this.count = 0;
+ }
+ SkipSubscriber.prototype._next = function (x) {
+ if (++this.count > this.total) {
+ this.destination.next(x);
+ }
+ };
+ return SkipSubscriber;
+}(Subscriber_1.Subscriber));
+
+},{"../Subscriber":36}],194:[function(require,module,exports){
+"use strict";
+var __extends = (this && this.__extends) || function (d, b) {
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+};
+var OuterSubscriber_1 = require('../OuterSubscriber');
+var subscribeToResult_1 = require('../util/subscribeToResult');
+/**
+ * Returns an Observable that skips items emitted by the source Observable until a second Observable emits an item.
+ *
+ * <img src="./img/skipUntil.png" width="100%">
+ *
+ * @param {Observable} notifier - The second Observable that has to emit an item before the source Observable's elements begin to
+ * be mirrored by the resulting Observable.
+ * @return {Observable<T>} An Observable that skips items from the source Observable until the second Observable emits
+ * an item, then emits the remaining items.
+ * @method skipUntil
+ * @owner Observable
+ */
+function skipUntil(notifier) {
+ return function (source) { return source.lift(new SkipUntilOperator(notifier)); };
+}
+exports.skipUntil = skipUntil;
+var SkipUntilOperator = (function () {
+ function SkipUntilOperator(notifier) {
+ this.notifier = notifier;
+ }
+ SkipUntilOperator.prototype.call = function (subscriber, source) {
+ return source.subscribe(new SkipUntilSubscriber(subscriber, this.notifier));
+ };
+ return SkipUntilOperator;
+}());
+/**
+ * We need this JSDoc comment for affecting ESDoc.
+ * @ignore
+ * @extends {Ignored}
+ */
+var SkipUntilSubscriber = (function (_super) {
+ __extends(SkipUntilSubscriber, _super);
+ function SkipUntilSubscriber(destination, notifier) {
+ _super.call(this, destination);
+ this.hasValue = false;
+ this.isInnerStopped = false;
+ this.add(subscribeToResult_1.subscribeToResult(this, notifier));
+ }
+ SkipUntilSubscriber.prototype._next = function (value) {
+ if (this.hasValue) {
+ _super.prototype._next.call(this, value);
+ }
+ };
+ SkipUntilSubscriber.prototype._complete = function () {
+ if (this.isInnerStopped) {
+ _super.prototype._complete.call(this);
+ }
+ else {
+ this.unsubscribe();
+ }
+ };
+ SkipUntilSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
+ this.hasValue = true;
+ };
+ SkipUntilSubscriber.prototype.notifyComplete = function () {
+ this.isInnerStopped = true;
+ if (this.isStopped) {
+ _super.prototype._complete.call(this);
+ }
+ };
+ return SkipUntilSubscriber;
+}(OuterSubscriber_1.OuterSubscriber));
+
+},{"../OuterSubscriber":31,"../util/subscribeToResult":238}],195:[function(require,module,exports){
+"use strict";
+var __extends = (this && this.__extends) || function (d, b) {
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+};
+var Subscriber_1 = require('../Subscriber');
+/**
+ * Returns an Observable that skips all items emitted by the source Observable as long as a specified condition holds
+ * true, but emits all further source items as soon as the condition becomes false.
+ *
+ * <img src="./img/skipWhile.png" width="100%">
+ *
+ * @param {Function} predicate - A function to test each item emitted from the source Observable.
+ * @return {Observable<T>} An Observable that begins emitting items emitted by the source Observable when the
+ * specified predicate becomes false.
+ * @method skipWhile
+ * @owner Observable
+ */
+function skipWhile(predicate) {
+ return function (source) { return source.lift(new SkipWhileOperator(predicate)); };
+}
+exports.skipWhile = skipWhile;
+var SkipWhileOperator = (function () {
+ function SkipWhileOperator(predicate) {
+ this.predicate = predicate;
+ }
+ SkipWhileOperator.prototype.call = function (subscriber, source) {
+ return source.subscribe(new SkipWhileSubscriber(subscriber, this.predicate));
+ };
+ return SkipWhileOperator;
+}());
+/**
+ * We need this JSDoc comment for affecting ESDoc.
+ * @ignore
+ * @extends {Ignored}
+ */
+var SkipWhileSubscriber = (function (_super) {
+ __extends(SkipWhileSubscriber, _super);
+ function SkipWhileSubscriber(destination, predicate) {
+ _super.call(this, destination);
+ this.predicate = predicate;
+ this.skipping = true;
+ this.index = 0;
+ }
+ SkipWhileSubscriber.prototype._next = function (value) {
+ var destination = this.destination;
+ if (this.skipping) {
+ this.tryCallPredicate(value);
+ }
+ if (!this.skipping) {
+ destination.next(value);
+ }
+ };
+ SkipWhileSubscriber.prototype.tryCallPredicate = function (value) {
+ try {
+ var result = this.predicate(value, this.index++);
+ this.skipping = Boolean(result);
+ }
+ catch (err) {
+ this.destination.error(err);
+ }
+ };
+ return SkipWhileSubscriber;
+}(Subscriber_1.Subscriber));
+
+},{"../Subscriber":36}],196:[function(require,module,exports){
+"use strict";
+var ArrayObservable_1 = require('../observable/ArrayObservable');
+var ScalarObservable_1 = require('../observable/ScalarObservable');
+var EmptyObservable_1 = require('../observable/EmptyObservable');
+var concat_1 = require('../observable/concat');
+var isScheduler_1 = require('../util/isScheduler');
+/* tslint:enable:max-line-length */
+/**
+ * Returns an Observable that emits the items you specify as arguments before it begins to emit
+ * items emitted by the source Observable.
+ *
+ * <img src="./img/startWith.png" width="100%">
+ *
+ * @param {...T} values - Items you want the modified Observable to emit first.
+ * @param {Scheduler} [scheduler] - A {@link IScheduler} to use for scheduling
+ * the emissions of the `next` notifications.
+ * @return {Observable} An Observable that emits the items in the specified Iterable and then emits the items
+ * emitted by the source Observable.
+ * @method startWith
+ * @owner Observable
+ */
+function startWith() {
+ var array = [];
+ for (var _i = 0; _i < arguments.length; _i++) {
+ array[_i - 0] = arguments[_i];
+ }
+ return function (source) {
+ var scheduler = array[array.length - 1];
+ if (isScheduler_1.isScheduler(scheduler)) {
+ array.pop();
+ }
+ else {
+ scheduler = null;
+ }
+ var len = array.length;
+ if (len === 1) {
+ return concat_1.concat(new ScalarObservable_1.ScalarObservable(array[0], scheduler), source);
+ }
+ else if (len > 1) {
+ return concat_1.concat(new ArrayObservable_1.ArrayObservable(array, scheduler), source);
+ }
+ else {
+ return concat_1.concat(new EmptyObservable_1.EmptyObservable(scheduler), source);
+ }
+ };
+}
+exports.startWith = startWith;
+
+},{"../observable/ArrayObservable":93,"../observable/EmptyObservable":96,"../observable/ScalarObservable":102,"../observable/concat":105,"../util/isScheduler":234}],197:[function(require,module,exports){
+"use strict";
+var __extends = (this && this.__extends) || function (d, b) {
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+};
+var OuterSubscriber_1 = require('../OuterSubscriber');
+var subscribeToResult_1 = require('../util/subscribeToResult');
+/* tslint:enable:max-line-length */
+/**
+ * Projects each source value to an Observable which is merged in the output
+ * Observable, emitting values only from the most recently projected Observable.
+ *
+ * <span class="informal">Maps each value to an Observable, then flattens all of
+ * these inner Observables using {@link switch}.</span>
+ *
+ * <img src="./img/switchMap.png" width="100%">
+ *
+ * Returns an Observable that emits items based on applying a function that you
+ * supply to each item emitted by the source Observable, where that function
+ * returns an (so-called "inner") Observable. Each time it observes one of these
+ * inner Observables, the output Observable begins emitting the items emitted by
+ * that inner Observable. When a new inner Observable is emitted, `switchMap`
+ * stops emitting items from the earlier-emitted inner Observable and begins
+ * emitting items from the new one. It continues to behave like this for
+ * subsequent inner Observables.
+ *
+ * @example <caption>Rerun an interval Observable on every click event</caption>
+ * var clicks = Rx.Observable.fromEvent(document, 'click');
+ * var result = clicks.switchMap((ev) => Rx.Observable.interval(1000));
+ * result.subscribe(x => console.log(x));
+ *
+ * @see {@link concatMap}
+ * @see {@link exhaustMap}
+ * @see {@link mergeMap}
+ * @see {@link switch}
+ * @see {@link switchMapTo}
+ *
+ * @param {function(value: T, ?index: number): ObservableInput} project A function
+ * that, when applied to an item emitted by the source Observable, returns an
+ * Observable.
+ * @param {function(outerValue: T, innerValue: I, outerIndex: number, innerIndex: number): any} [resultSelector]
+ * A function to produce the value on the output Observable based on the values
+ * and the indices of the source (outer) emission and the inner Observable
+ * emission. The arguments passed to this function are:
+ * - `outerValue`: the value that came from the source
+ * - `innerValue`: the value that came from the projected Observable
+ * - `outerIndex`: the "index" of the value that came from the source
+ * - `innerIndex`: the "index" of the value from the projected Observable
+ * @return {Observable} An Observable that emits the result of applying the
+ * projection function (and the optional `resultSelector`) to each item emitted
+ * by the source Observable and taking only the values from the most recently
+ * projected inner Observable.
+ * @method switchMap
+ * @owner Observable
+ */
+function switchMap(project, resultSelector) {
+ return function switchMapOperatorFunction(source) {
+ return source.lift(new SwitchMapOperator(project, resultSelector));
+ };
+}
+exports.switchMap = switchMap;
+var SwitchMapOperator = (function () {
+ function SwitchMapOperator(project, resultSelector) {
+ this.project = project;
+ this.resultSelector = resultSelector;
+ }
+ SwitchMapOperator.prototype.call = function (subscriber, source) {
+ return source.subscribe(new SwitchMapSubscriber(subscriber, this.project, this.resultSelector));
+ };
+ return SwitchMapOperator;
+}());
+/**
+ * We need this JSDoc comment for affecting ESDoc.
+ * @ignore
+ * @extends {Ignored}
+ */
+var SwitchMapSubscriber = (function (_super) {
+ __extends(SwitchMapSubscriber, _super);
+ function SwitchMapSubscriber(destination, project, resultSelector) {
+ _super.call(this, destination);
+ this.project = project;
+ this.resultSelector = resultSelector;
+ this.index = 0;
+ }
+ SwitchMapSubscriber.prototype._next = function (value) {
+ var result;
+ var index = this.index++;
+ try {
+ result = this.project(value, index);
+ }
+ catch (error) {
+ this.destination.error(error);
+ return;
+ }
+ this._innerSub(result, value, index);
+ };
+ SwitchMapSubscriber.prototype._innerSub = function (result, value, index) {
+ var innerSubscription = this.innerSubscription;
+ if (innerSubscription) {
+ innerSubscription.unsubscribe();
+ }
+ this.add(this.innerSubscription = subscribeToResult_1.subscribeToResult(this, result, value, index));
+ };
+ SwitchMapSubscriber.prototype._complete = function () {
+ var innerSubscription = this.innerSubscription;
+ if (!innerSubscription || innerSubscription.closed) {
+ _super.prototype._complete.call(this);
+ }
+ };
+ SwitchMapSubscriber.prototype._unsubscribe = function () {
+ this.innerSubscription = null;
+ };
+ SwitchMapSubscriber.prototype.notifyComplete = function (innerSub) {
+ this.remove(innerSub);
+ this.innerSubscription = null;
+ if (this.isStopped) {
+ _super.prototype._complete.call(this);
+ }
+ };
+ SwitchMapSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
+ if (this.resultSelector) {
+ this._tryNotifyNext(outerValue, innerValue, outerIndex, innerIndex);
+ }
+ else {
+ this.destination.next(innerValue);
+ }
+ };
+ SwitchMapSubscriber.prototype._tryNotifyNext = function (outerValue, innerValue, outerIndex, innerIndex) {
+ var result;
+ try {
+ result = this.resultSelector(outerValue, innerValue, outerIndex, innerIndex);
+ }
+ catch (err) {
+ this.destination.error(err);
+ return;
+ }
+ this.destination.next(result);
+ };
+ return SwitchMapSubscriber;
+}(OuterSubscriber_1.OuterSubscriber));
+
+},{"../OuterSubscriber":31,"../util/subscribeToResult":238}],198:[function(require,module,exports){
+"use strict";
+var __extends = (this && this.__extends) || function (d, b) {
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+};
+var Subscriber_1 = require('../Subscriber');
+var ArgumentOutOfRangeError_1 = require('../util/ArgumentOutOfRangeError');
+var EmptyObservable_1 = require('../observable/EmptyObservable');
+/**
+ * Emits only the first `count` values emitted by the source Observable.
+ *
+ * <span class="informal">Takes the first `count` values from the source, then
+ * completes.</span>
+ *
+ * <img src="./img/take.png" width="100%">
+ *
+ * `take` returns an Observable that emits only the first `count` values emitted
+ * by the source Observable. If the source emits fewer than `count` values then
+ * all of its values are emitted. After that, it completes, regardless if the
+ * source completes.
+ *
+ * @example <caption>Take the first 5 seconds of an infinite 1-second interval Observable</caption>
+ * var interval = Rx.Observable.interval(1000);
+ * var five = interval.take(5);
+ * five.subscribe(x => console.log(x));
+ *
+ * @see {@link takeLast}
+ * @see {@link takeUntil}
+ * @see {@link takeWhile}
+ * @see {@link skip}
+ *
+ * @throws {ArgumentOutOfRangeError} When using `take(i)`, it delivers an
+ * ArgumentOutOrRangeError to the Observer's `error` callback if `i < 0`.
+ *
+ * @param {number} count The maximum number of `next` values to emit.
+ * @return {Observable<T>} An Observable that emits only the first `count`
+ * values emitted by the source Observable, or all of the values from the source
+ * if the source emits fewer than `count` values.
+ * @method take
+ * @owner Observable
+ */
+function take(count) {
+ return function (source) {
+ if (count === 0) {
+ return new EmptyObservable_1.EmptyObservable();
+ }
+ else {
+ return source.lift(new TakeOperator(count));
+ }
+ };
+}
+exports.take = take;
+var TakeOperator = (function () {
+ function TakeOperator(total) {
+ this.total = total;
+ if (this.total < 0) {
+ throw new ArgumentOutOfRangeError_1.ArgumentOutOfRangeError;
+ }
+ }
+ TakeOperator.prototype.call = function (subscriber, source) {
+ return source.subscribe(new TakeSubscriber(subscriber, this.total));
+ };
+ return TakeOperator;
+}());
+/**
+ * We need this JSDoc comment for affecting ESDoc.
+ * @ignore
+ * @extends {Ignored}
+ */
+var TakeSubscriber = (function (_super) {
+ __extends(TakeSubscriber, _super);
+ function TakeSubscriber(destination, total) {
+ _super.call(this, destination);
+ this.total = total;
+ this.count = 0;
+ }
+ TakeSubscriber.prototype._next = function (value) {
+ var total = this.total;
+ var count = ++this.count;
+ if (count <= total) {
+ this.destination.next(value);
+ if (count === total) {
+ this.destination.complete();
+ this.unsubscribe();
+ }
+ }
+ };
+ return TakeSubscriber;
+}(Subscriber_1.Subscriber));
+
+},{"../Subscriber":36,"../observable/EmptyObservable":96,"../util/ArgumentOutOfRangeError":219}],199:[function(require,module,exports){
+"use strict";
+var __extends = (this && this.__extends) || function (d, b) {
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+};
+var Subscriber_1 = require('../Subscriber');
+var ArgumentOutOfRangeError_1 = require('../util/ArgumentOutOfRangeError');
+var EmptyObservable_1 = require('../observable/EmptyObservable');
+/**
+ * Emits only the last `count` values emitted by the source Observable.
+ *
+ * <span class="informal">Remembers the latest `count` values, then emits those
+ * only when the source completes.</span>
+ *
+ * <img src="./img/takeLast.png" width="100%">
+ *
+ * `takeLast` returns an Observable that emits at most the last `count` values
+ * emitted by the source Observable. If the source emits fewer than `count`
+ * values then all of its values are emitted. This operator must wait until the
+ * `complete` notification emission from the source in order to emit the `next`
+ * values on the output Observable, because otherwise it is impossible to know
+ * whether or not more values will be emitted on the source. For this reason,
+ * all values are emitted synchronously, followed by the complete notification.
+ *
+ * @example <caption>Take the last 3 values of an Observable with many values</caption>
+ * var many = Rx.Observable.range(1, 100);
+ * var lastThree = many.takeLast(3);
+ * lastThree.subscribe(x => console.log(x));
+ *
+ * @see {@link take}
+ * @see {@link takeUntil}
+ * @see {@link takeWhile}
+ * @see {@link skip}
+ *
+ * @throws {ArgumentOutOfRangeError} When using `takeLast(i)`, it delivers an
+ * ArgumentOutOrRangeError to the Observer's `error` callback if `i < 0`.
+ *
+ * @param {number} count The maximum number of values to emit from the end of
+ * the sequence of values emitted by the source Observable.
+ * @return {Observable<T>} An Observable that emits at most the last count
+ * values emitted by the source Observable.
+ * @method takeLast
+ * @owner Observable
+ */
+function takeLast(count) {
+ return function takeLastOperatorFunction(source) {
+ if (count === 0) {
+ return new EmptyObservable_1.EmptyObservable();
+ }
+ else {
+ return source.lift(new TakeLastOperator(count));
+ }
+ };
+}
+exports.takeLast = takeLast;
+var TakeLastOperator = (function () {
+ function TakeLastOperator(total) {
+ this.total = total;
+ if (this.total < 0) {
+ throw new ArgumentOutOfRangeError_1.ArgumentOutOfRangeError;
+ }
+ }
+ TakeLastOperator.prototype.call = function (subscriber, source) {
+ return source.subscribe(new TakeLastSubscriber(subscriber, this.total));
+ };
+ return TakeLastOperator;
+}());
+/**
+ * We need this JSDoc comment for affecting ESDoc.
+ * @ignore
+ * @extends {Ignored}
+ */
+var TakeLastSubscriber = (function (_super) {
+ __extends(TakeLastSubscriber, _super);
+ function TakeLastSubscriber(destination, total) {
+ _super.call(this, destination);
+ this.total = total;
+ this.ring = new Array();
+ this.count = 0;
+ }
+ TakeLastSubscriber.prototype._next = function (value) {
+ var ring = this.ring;
+ var total = this.total;
+ var count = this.count++;
+ if (ring.length < total) {
+ ring.push(value);
+ }
+ else {
+ var index = count % total;
+ ring[index] = value;
+ }
+ };
+ TakeLastSubscriber.prototype._complete = function () {
+ var destination = this.destination;
+ var count = this.count;
+ if (count > 0) {
+ var total = this.count >= this.total ? this.total : this.count;
+ var ring = this.ring;
+ for (var i = 0; i < total; i++) {
+ var idx = (count++) % total;
+ destination.next(ring[idx]);
+ }
+ }
+ destination.complete();
+ };
+ return TakeLastSubscriber;
+}(Subscriber_1.Subscriber));
+
+},{"../Subscriber":36,"../observable/EmptyObservable":96,"../util/ArgumentOutOfRangeError":219}],200:[function(require,module,exports){
+"use strict";
+var __extends = (this && this.__extends) || function (d, b) {
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+};
+var OuterSubscriber_1 = require('../OuterSubscriber');
+var subscribeToResult_1 = require('../util/subscribeToResult');
+/**
+ * Emits the values emitted by the source Observable until a `notifier`
+ * Observable emits a value.
+ *
+ * <span class="informal">Lets values pass until a second Observable,
+ * `notifier`, emits something. Then, it completes.</span>
+ *
+ * <img src="./img/takeUntil.png" width="100%">
+ *
+ * `takeUntil` subscribes and begins mirroring the source Observable. It also
+ * monitors a second Observable, `notifier` that you provide. If the `notifier`
+ * emits a value or a complete notification, the output Observable stops
+ * mirroring the source Observable and completes.
+ *
+ * @example <caption>Tick every second until the first click happens</caption>
+ * var interval = Rx.Observable.interval(1000);
+ * var clicks = Rx.Observable.fromEvent(document, 'click');
+ * var result = interval.takeUntil(clicks);
+ * result.subscribe(x => console.log(x));
+ *
+ * @see {@link take}
+ * @see {@link takeLast}
+ * @see {@link takeWhile}
+ * @see {@link skip}
+ *
+ * @param {Observable} notifier The Observable whose first emitted value will
+ * cause the output Observable of `takeUntil` to stop emitting values from the
+ * source Observable.
+ * @return {Observable<T>} An Observable that emits the values from the source
+ * Observable until such time as `notifier` emits its first value.
+ * @method takeUntil
+ * @owner Observable
+ */
+function takeUntil(notifier) {
+ return function (source) { return source.lift(new TakeUntilOperator(notifier)); };
+}
+exports.takeUntil = takeUntil;
+var TakeUntilOperator = (function () {
+ function TakeUntilOperator(notifier) {
+ this.notifier = notifier;
+ }
+ TakeUntilOperator.prototype.call = function (subscriber, source) {
+ return source.subscribe(new TakeUntilSubscriber(subscriber, this.notifier));
+ };
+ return TakeUntilOperator;
+}());
+/**
+ * We need this JSDoc comment for affecting ESDoc.
+ * @ignore
+ * @extends {Ignored}
+ */
+var TakeUntilSubscriber = (function (_super) {
+ __extends(TakeUntilSubscriber, _super);
+ function TakeUntilSubscriber(destination, notifier) {
+ _super.call(this, destination);
+ this.notifier = notifier;
+ this.add(subscribeToResult_1.subscribeToResult(this, notifier));
+ }
+ TakeUntilSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
+ this.complete();
+ };
+ TakeUntilSubscriber.prototype.notifyComplete = function () {
+ // noop
+ };
+ return TakeUntilSubscriber;
+}(OuterSubscriber_1.OuterSubscriber));
+
+},{"../OuterSubscriber":31,"../util/subscribeToResult":238}],201:[function(require,module,exports){
+"use strict";
+var __extends = (this && this.__extends) || function (d, b) {
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+};
+var Subscriber_1 = require('../Subscriber');
+/**
+ * Emits values emitted by the source Observable so long as each value satisfies
+ * the given `predicate`, and then completes as soon as this `predicate` is not
+ * satisfied.
+ *
+ * <span class="informal">Takes values from the source only while they pass the
+ * condition given. When the first value does not satisfy, it completes.</span>
+ *
+ * <img src="./img/takeWhile.png" width="100%">
+ *
+ * `takeWhile` subscribes and begins mirroring the source Observable. Each value
+ * emitted on the source is given to the `predicate` function which returns a
+ * boolean, representing a condition to be satisfied by the source values. The
+ * output Observable emits the source values until such time as the `predicate`
+ * returns false, at which point `takeWhile` stops mirroring the source
+ * Observable and completes the output Observable.
+ *
+ * @example <caption>Emit click events only while the clientX property is greater than 200</caption>
+ * var clicks = Rx.Observable.fromEvent(document, 'click');
+ * var result = clicks.takeWhile(ev => ev.clientX > 200);
+ * result.subscribe(x => console.log(x));
+ *
+ * @see {@link take}
+ * @see {@link takeLast}
+ * @see {@link takeUntil}
+ * @see {@link skip}
+ *
+ * @param {function(value: T, index: number): boolean} predicate A function that
+ * evaluates a value emitted by the source Observable and returns a boolean.
+ * Also takes the (zero-based) index as the second argument.
+ * @return {Observable<T>} An Observable that emits the values from the source
+ * Observable so long as each value satisfies the condition defined by the
+ * `predicate`, then completes.
+ * @method takeWhile
+ * @owner Observable
+ */
+function takeWhile(predicate) {
+ return function (source) { return source.lift(new TakeWhileOperator(predicate)); };
+}
+exports.takeWhile = takeWhile;
+var TakeWhileOperator = (function () {
+ function TakeWhileOperator(predicate) {
+ this.predicate = predicate;
+ }
+ TakeWhileOperator.prototype.call = function (subscriber, source) {
+ return source.subscribe(new TakeWhileSubscriber(subscriber, this.predicate));
+ };
+ return TakeWhileOperator;
+}());
+/**
+ * We need this JSDoc comment for affecting ESDoc.
+ * @ignore
+ * @extends {Ignored}
+ */
+var TakeWhileSubscriber = (function (_super) {
+ __extends(TakeWhileSubscriber, _super);
+ function TakeWhileSubscriber(destination, predicate) {
+ _super.call(this, destination);
+ this.predicate = predicate;
+ this.index = 0;
+ }
+ TakeWhileSubscriber.prototype._next = function (value) {
+ var destination = this.destination;
+ var result;
+ try {
+ result = this.predicate(value, this.index++);
+ }
+ catch (err) {
+ destination.error(err);
+ return;
+ }
+ this.nextOrComplete(value, result);
+ };
+ TakeWhileSubscriber.prototype.nextOrComplete = function (value, predicateResult) {
+ var destination = this.destination;
+ if (Boolean(predicateResult)) {
+ destination.next(value);
+ }
+ else {
+ destination.complete();
+ }
+ };
+ return TakeWhileSubscriber;
+}(Subscriber_1.Subscriber));
+
+},{"../Subscriber":36}],202:[function(require,module,exports){
+"use strict";
+var __extends = (this && this.__extends) || function (d, b) {
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+};
+var Subscriber_1 = require('../Subscriber');
+/* tslint:enable:max-line-length */
+/**
+ * Perform a side effect for every emission on the source Observable, but return
+ * an Observable that is identical to the source.
+ *
+ * <span class="informal">Intercepts each emission on the source and runs a
+ * function, but returns an output which is identical to the source as long as errors don't occur.</span>
+ *
+ * <img src="./img/do.png" width="100%">
+ *
+ * Returns a mirrored Observable of the source Observable, but modified so that
+ * the provided Observer is called to perform a side effect for every value,
+ * error, and completion emitted by the source. Any errors that are thrown in
+ * the aforementioned Observer or handlers are safely sent down the error path
+ * of the output Observable.
+ *
+ * This operator is useful for debugging your Observables for the correct values
+ * or performing other side effects.
+ *
+ * Note: this is different to a `subscribe` on the Observable. If the Observable
+ * returned by `do` is not subscribed, the side effects specified by the
+ * Observer will never happen. `do` therefore simply spies on existing
+ * execution, it does not trigger an execution to happen like `subscribe` does.
+ *
+ * @example <caption>Map every click to the clientX position of that click, while also logging the click event</caption>
+ * var clicks = Rx.Observable.fromEvent(document, 'click');
+ * var positions = clicks
+ * .do(ev => console.log(ev))
+ * .map(ev => ev.clientX);
+ * positions.subscribe(x => console.log(x));
+ *
+ * @see {@link map}
+ * @see {@link subscribe}
+ *
+ * @param {Observer|function} [nextOrObserver] A normal Observer object or a
+ * callback for `next`.
+ * @param {function} [error] Callback for errors in the source.
+ * @param {function} [complete] Callback for the completion of the source.
+ * @return {Observable} An Observable identical to the source, but runs the
+ * specified Observer or callback(s) for each item.
+ * @name tap
+ */
+function tap(nextOrObserver, error, complete) {
+ return function tapOperatorFunction(source) {
+ return source.lift(new DoOperator(nextOrObserver, error, complete));
+ };
+}
+exports.tap = tap;
+var DoOperator = (function () {
+ function DoOperator(nextOrObserver, error, complete) {
+ this.nextOrObserver = nextOrObserver;
+ this.error = error;
+ this.complete = complete;
+ }
+ DoOperator.prototype.call = function (subscriber, source) {
+ return source.subscribe(new DoSubscriber(subscriber, this.nextOrObserver, this.error, this.complete));
+ };
+ return DoOperator;
+}());
+/**
+ * We need this JSDoc comment for affecting ESDoc.
+ * @ignore
+ * @extends {Ignored}
+ */
+var DoSubscriber = (function (_super) {
+ __extends(DoSubscriber, _super);
+ function DoSubscriber(destination, nextOrObserver, error, complete) {
+ _super.call(this, destination);
+ var safeSubscriber = new Subscriber_1.Subscriber(nextOrObserver, error, complete);
+ safeSubscriber.syncErrorThrowable = true;
+ this.add(safeSubscriber);
+ this.safeSubscriber = safeSubscriber;
+ }
+ DoSubscriber.prototype._next = function (value) {
+ var safeSubscriber = this.safeSubscriber;
+ safeSubscriber.next(value);
+ if (safeSubscriber.syncErrorThrown) {
+ this.destination.error(safeSubscriber.syncErrorValue);
+ }
+ else {
+ this.destination.next(value);
+ }
+ };
+ DoSubscriber.prototype._error = function (err) {
+ var safeSubscriber = this.safeSubscriber;
+ safeSubscriber.error(err);
+ if (safeSubscriber.syncErrorThrown) {
+ this.destination.error(safeSubscriber.syncErrorValue);
+ }
+ else {
+ this.destination.error(err);
+ }
+ };
+ DoSubscriber.prototype._complete = function () {
+ var safeSubscriber = this.safeSubscriber;
+ safeSubscriber.complete();
+ if (safeSubscriber.syncErrorThrown) {
+ this.destination.error(safeSubscriber.syncErrorValue);
+ }
+ else {
+ this.destination.complete();
+ }
+ };
+ return DoSubscriber;
+}(Subscriber_1.Subscriber));
+
+},{"../Subscriber":36}],203:[function(require,module,exports){
+"use strict";
+var __extends = (this && this.__extends) || function (d, b) {
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+};
+var OuterSubscriber_1 = require('../OuterSubscriber');
+var subscribeToResult_1 = require('../util/subscribeToResult');
+exports.defaultThrottleConfig = {
+ leading: true,
+ trailing: false
+};
+/**
+ * Emits a value from the source Observable, then ignores subsequent source
+ * values for a duration determined by another Observable, then repeats this
+ * process.
+ *
+ * <span class="informal">It's like {@link throttleTime}, but the silencing
+ * duration is determined by a second Observable.</span>
+ *
+ * <img src="./img/throttle.png" width="100%">
+ *
+ * `throttle` emits the source Observable values on the output Observable
+ * when its internal timer is disabled, and ignores source values when the timer
+ * is enabled. Initially, the timer is disabled. As soon as the first source
+ * value arrives, it is forwarded to the output Observable, and then the timer
+ * is enabled by calling the `durationSelector` function with the source value,
+ * which returns the "duration" Observable. When the duration Observable emits a
+ * value or completes, the timer is disabled, and this process repeats for the
+ * next source value.
+ *
+ * @example <caption>Emit clicks at a rate of at most one click per second</caption>
+ * var clicks = Rx.Observable.fromEvent(document, 'click');
+ * var result = clicks.throttle(ev => Rx.Observable.interval(1000));
+ * result.subscribe(x => console.log(x));
+ *
+ * @see {@link audit}
+ * @see {@link debounce}
+ * @see {@link delayWhen}
+ * @see {@link sample}
+ * @see {@link throttleTime}
+ *
+ * @param {function(value: T): SubscribableOrPromise} durationSelector A function
+ * that receives a value from the source Observable, for computing the silencing
+ * duration for each source value, returned as an Observable or a Promise.
+ * @param {Object} config a configuration object to define `leading` and `trailing` behavior. Defaults
+ * to `{ leading: true, trailing: false }`.
+ * @return {Observable<T>} An Observable that performs the throttle operation to
+ * limit the rate of emissions from the source.
+ * @method throttle
+ * @owner Observable
+ */
+function throttle(durationSelector, config) {
+ if (config === void 0) { config = exports.defaultThrottleConfig; }
+ return function (source) { return source.lift(new ThrottleOperator(durationSelector, config.leading, config.trailing)); };
+}
+exports.throttle = throttle;
+var ThrottleOperator = (function () {
+ function ThrottleOperator(durationSelector, leading, trailing) {
+ this.durationSelector = durationSelector;
+ this.leading = leading;
+ this.trailing = trailing;
+ }
+ ThrottleOperator.prototype.call = function (subscriber, source) {
+ return source.subscribe(new ThrottleSubscriber(subscriber, this.durationSelector, this.leading, this.trailing));
+ };
+ return ThrottleOperator;
+}());
+/**
+ * We need this JSDoc comment for affecting ESDoc
+ * @ignore
+ * @extends {Ignored}
+ */
+var ThrottleSubscriber = (function (_super) {
+ __extends(ThrottleSubscriber, _super);
+ function ThrottleSubscriber(destination, durationSelector, _leading, _trailing) {
+ _super.call(this, destination);
+ this.destination = destination;
+ this.durationSelector = durationSelector;
+ this._leading = _leading;
+ this._trailing = _trailing;
+ this._hasTrailingValue = false;
+ }
+ ThrottleSubscriber.prototype._next = function (value) {
+ if (this.throttled) {
+ if (this._trailing) {
+ this._hasTrailingValue = true;
+ this._trailingValue = value;
+ }
+ }
+ else {
+ var duration = this.tryDurationSelector(value);
+ if (duration) {
+ this.add(this.throttled = subscribeToResult_1.subscribeToResult(this, duration));
+ }
+ if (this._leading) {
+ this.destination.next(value);
+ if (this._trailing) {
+ this._hasTrailingValue = true;
+ this._trailingValue = value;
+ }
+ }
+ }
+ };
+ ThrottleSubscriber.prototype.tryDurationSelector = function (value) {
+ try {
+ return this.durationSelector(value);
+ }
+ catch (err) {
+ this.destination.error(err);
+ return null;
+ }
+ };
+ ThrottleSubscriber.prototype._unsubscribe = function () {
+ var _a = this, throttled = _a.throttled, _trailingValue = _a._trailingValue, _hasTrailingValue = _a._hasTrailingValue, _trailing = _a._trailing;
+ this._trailingValue = null;
+ this._hasTrailingValue = false;
+ if (throttled) {
+ this.remove(throttled);
+ this.throttled = null;
+ throttled.unsubscribe();
+ }
+ };
+ ThrottleSubscriber.prototype._sendTrailing = function () {
+ var _a = this, destination = _a.destination, throttled = _a.throttled, _trailing = _a._trailing, _trailingValue = _a._trailingValue, _hasTrailingValue = _a._hasTrailingValue;
+ if (throttled && _trailing && _hasTrailingValue) {
+ destination.next(_trailingValue);
+ this._trailingValue = null;
+ this._hasTrailingValue = false;
+ }
+ };
+ ThrottleSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
+ this._sendTrailing();
+ this._unsubscribe();
+ };
+ ThrottleSubscriber.prototype.notifyComplete = function () {
+ this._sendTrailing();
+ this._unsubscribe();
+ };
+ return ThrottleSubscriber;
+}(OuterSubscriber_1.OuterSubscriber));
+
+},{"../OuterSubscriber":31,"../util/subscribeToResult":238}],204:[function(require,module,exports){
+"use strict";
+var __extends = (this && this.__extends) || function (d, b) {
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+};
+var Subscriber_1 = require('../Subscriber');
+var async_1 = require('../scheduler/async');
+var throttle_1 = require('./throttle');
+/**
+ * Emits a value from the source Observable, then ignores subsequent source
+ * values for `duration` milliseconds, then repeats this process.
+ *
+ * <span class="informal">Lets a value pass, then ignores source values for the
+ * next `duration` milliseconds.</span>
+ *
+ * <img src="./img/throttleTime.png" width="100%">
+ *
+ * `throttleTime` emits the source Observable values on the output Observable
+ * when its internal timer is disabled, and ignores source values when the timer
+ * is enabled. Initially, the timer is disabled. As soon as the first source
+ * value arrives, it is forwarded to the output Observable, and then the timer
+ * is enabled. After `duration` milliseconds (or the time unit determined
+ * internally by the optional `scheduler`) has passed, the timer is disabled,
+ * and this process repeats for the next source value. Optionally takes a
+ * {@link IScheduler} for managing timers.
+ *
+ * @example <caption>Emit clicks at a rate of at most one click per second</caption>
+ * var clicks = Rx.Observable.fromEvent(document, 'click');
+ * var result = clicks.throttleTime(1000);
+ * result.subscribe(x => console.log(x));
+ *
+ * @see {@link auditTime}
+ * @see {@link debounceTime}
+ * @see {@link delay}
+ * @see {@link sampleTime}
+ * @see {@link throttle}
+ *
+ * @param {number} duration Time to wait before emitting another value after
+ * emitting the last value, measured in milliseconds or the time unit determined
+ * internally by the optional `scheduler`.
+ * @param {Scheduler} [scheduler=async] The {@link IScheduler} to use for
+ * managing the timers that handle the throttling.
+ * @return {Observable<T>} An Observable that performs the throttle operation to
+ * limit the rate of emissions from the source.
+ * @method throttleTime
+ * @owner Observable
+ */
+function throttleTime(duration, scheduler, config) {
+ if (scheduler === void 0) { scheduler = async_1.async; }
+ if (config === void 0) { config = throttle_1.defaultThrottleConfig; }
+ return function (source) { return source.lift(new ThrottleTimeOperator(duration, scheduler, config.leading, config.trailing)); };
+}
+exports.throttleTime = throttleTime;
+var ThrottleTimeOperator = (function () {
+ function ThrottleTimeOperator(duration, scheduler, leading, trailing) {
+ this.duration = duration;
+ this.scheduler = scheduler;
+ this.leading = leading;
+ this.trailing = trailing;
+ }
+ ThrottleTimeOperator.prototype.call = function (subscriber, source) {
+ return source.subscribe(new ThrottleTimeSubscriber(subscriber, this.duration, this.scheduler, this.leading, this.trailing));
+ };
+ return ThrottleTimeOperator;
+}());
+/**
+ * We need this JSDoc comment for affecting ESDoc.
+ * @ignore
+ * @extends {Ignored}
+ */
+var ThrottleTimeSubscriber = (function (_super) {
+ __extends(ThrottleTimeSubscriber, _super);
+ function ThrottleTimeSubscriber(destination, duration, scheduler, leading, trailing) {
+ _super.call(this, destination);
+ this.duration = duration;
+ this.scheduler = scheduler;
+ this.leading = leading;
+ this.trailing = trailing;
+ this._hasTrailingValue = false;
+ this._trailingValue = null;
+ }
+ ThrottleTimeSubscriber.prototype._next = function (value) {
+ if (this.throttled) {
+ if (this.trailing) {
+ this._trailingValue = value;
+ this._hasTrailingValue = true;
+ }
+ }
+ else {
+ this.add(this.throttled = this.scheduler.schedule(dispatchNext, this.duration, { subscriber: this }));
+ if (this.leading) {
+ this.destination.next(value);
+ }
+ }
+ };
+ ThrottleTimeSubscriber.prototype.clearThrottle = function () {
+ var throttled = this.throttled;
+ if (throttled) {
+ if (this.trailing && this._hasTrailingValue) {
+ this.destination.next(this._trailingValue);
+ this._trailingValue = null;
+ this._hasTrailingValue = false;
+ }
+ throttled.unsubscribe();
+ this.remove(throttled);
+ this.throttled = null;
+ }
+ };
+ return ThrottleTimeSubscriber;
+}(Subscriber_1.Subscriber));
+function dispatchNext(arg) {
+ var subscriber = arg.subscriber;
+ subscriber.clearThrottle();
+}
+
+},{"../Subscriber":36,"../scheduler/async":213,"./throttle":203}],205:[function(require,module,exports){
+"use strict";
+var __extends = (this && this.__extends) || function (d, b) {
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+};
+var async_1 = require('../scheduler/async');
+var isDate_1 = require('../util/isDate');
+var Subscriber_1 = require('../Subscriber');
+var TimeoutError_1 = require('../util/TimeoutError');
+/**
+ *
+ * Errors if Observable does not emit a value in given time span.
+ *
+ * <span class="informal">Timeouts on Observable that doesn't emit values fast enough.</span>
+ *
+ * <img src="./img/timeout.png" width="100%">
+ *
+ * `timeout` operator accepts as an argument either a number or a Date.
+ *
+ * If number was provided, it returns an Observable that behaves like a source
+ * Observable, unless there is a period of time where there is no value emitted.
+ * So if you provide `100` as argument and first value comes after 50ms from
+ * the moment of subscription, this value will be simply re-emitted by the resulting
+ * Observable. If however after that 100ms passes without a second value being emitted,
+ * stream will end with an error and source Observable will be unsubscribed.
+ * These checks are performed throughout whole lifecycle of Observable - from the moment
+ * it was subscribed to, until it completes or errors itself. Thus every value must be
+ * emitted within specified period since previous value.
+ *
+ * If provided argument was Date, returned Observable behaves differently. It throws
+ * if Observable did not complete before provided Date. This means that periods between
+ * emission of particular values do not matter in this case. If Observable did not complete
+ * before provided Date, source Observable will be unsubscribed. Other than that, resulting
+ * stream behaves just as source Observable.
+ *
+ * `timeout` accepts also a Scheduler as a second parameter. It is used to schedule moment (or moments)
+ * when returned Observable will check if source stream emitted value or completed.
+ *
+ * @example <caption>Check if ticks are emitted within certain timespan</caption>
+ * const seconds = Rx.Observable.interval(1000);
+ *
+ * seconds.timeout(1100) // Let's use bigger timespan to be safe,
+ * // since `interval` might fire a bit later then scheduled.
+ * .subscribe(
+ * value => console.log(value), // Will emit numbers just as regular `interval` would.
+ * err => console.log(err) // Will never be called.
+ * );
+ *
+ * seconds.timeout(900).subscribe(
+ * value => console.log(value), // Will never be called.
+ * err => console.log(err) // Will emit error before even first value is emitted,
+ * // since it did not arrive within 900ms period.
+ * );
+ *
+ * @example <caption>Use Date to check if Observable completed</caption>
+ * const seconds = Rx.Observable.interval(1000);
+ *
+ * seconds.timeout(new Date("December 17, 2020 03:24:00"))
+ * .subscribe(
+ * value => console.log(value), // Will emit values as regular `interval` would
+ * // until December 17, 2020 at 03:24:00.
+ * err => console.log(err) // On December 17, 2020 at 03:24:00 it will emit an error,
+ * // since Observable did not complete by then.
+ * );
+ *
+ * @see {@link timeoutWith}
+ *
+ * @param {number|Date} due Number specifying period within which Observable must emit values
+ * or Date specifying before when Observable should complete
+ * @param {Scheduler} [scheduler] Scheduler controlling when timeout checks occur.
+ * @return {Observable<T>} Observable that mirrors behaviour of source, unless timeout checks fail.
+ * @method timeout
+ * @owner Observable
+ */
+function timeout(due, scheduler) {
+ if (scheduler === void 0) { scheduler = async_1.async; }
+ var absoluteTimeout = isDate_1.isDate(due);
+ var waitFor = absoluteTimeout ? (+due - scheduler.now()) : Math.abs(due);
+ return function (source) { return source.lift(new TimeoutOperator(waitFor, absoluteTimeout, scheduler, new TimeoutError_1.TimeoutError())); };
+}
+exports.timeout = timeout;
+var TimeoutOperator = (function () {
+ function TimeoutOperator(waitFor, absoluteTimeout, scheduler, errorInstance) {
+ this.waitFor = waitFor;
+ this.absoluteTimeout = absoluteTimeout;
+ this.scheduler = scheduler;
+ this.errorInstance = errorInstance;
+ }
+ TimeoutOperator.prototype.call = function (subscriber, source) {
+ return source.subscribe(new TimeoutSubscriber(subscriber, this.absoluteTimeout, this.waitFor, this.scheduler, this.errorInstance));
+ };
+ return TimeoutOperator;
+}());
+/**
+ * We need this JSDoc comment for affecting ESDoc.
+ * @ignore
+ * @extends {Ignored}
+ */
+var TimeoutSubscriber = (function (_super) {
+ __extends(TimeoutSubscriber, _super);
+ function TimeoutSubscriber(destination, absoluteTimeout, waitFor, scheduler, errorInstance) {
+ _super.call(this, destination);
+ this.absoluteTimeout = absoluteTimeout;
+ this.waitFor = waitFor;
+ this.scheduler = scheduler;
+ this.errorInstance = errorInstance;
+ this.action = null;
+ this.scheduleTimeout();
+ }
+ TimeoutSubscriber.dispatchTimeout = function (subscriber) {
+ subscriber.error(subscriber.errorInstance);
+ };
+ TimeoutSubscriber.prototype.scheduleTimeout = function () {
+ var action = this.action;
+ if (action) {
+ // Recycle the action if we've already scheduled one. All the production
+ // Scheduler Actions mutate their state/delay time and return themeselves.
+ // VirtualActions are immutable, so they create and return a clone. In this
+ // case, we need to set the action reference to the most recent VirtualAction,
+ // to ensure that's the one we clone from next time.
+ this.action = action.schedule(this, this.waitFor);
+ }
+ else {
+ this.add(this.action = this.scheduler.schedule(TimeoutSubscriber.dispatchTimeout, this.waitFor, this));
+ }
+ };
+ TimeoutSubscriber.prototype._next = function (value) {
+ if (!this.absoluteTimeout) {
+ this.scheduleTimeout();
+ }
+ _super.prototype._next.call(this, value);
+ };
+ TimeoutSubscriber.prototype._unsubscribe = function () {
+ this.action = null;
+ this.scheduler = null;
+ this.errorInstance = null;
+ };
+ return TimeoutSubscriber;
+}(Subscriber_1.Subscriber));
+
+},{"../Subscriber":36,"../scheduler/async":213,"../util/TimeoutError":223,"../util/isDate":229}],206:[function(require,module,exports){
+"use strict";
+var __extends = (this && this.__extends) || function (d, b) {
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+};
+var OuterSubscriber_1 = require('../OuterSubscriber');
+var subscribeToResult_1 = require('../util/subscribeToResult');
+/* tslint:enable:max-line-length */
+/**
+ * Combines the source Observable with other Observables to create an Observable
+ * whose values are calculated from the latest values of each, only when the
+ * source emits.
+ *
+ * <span class="informal">Whenever the source Observable emits a value, it
+ * computes a formula using that value plus the latest values from other input
+ * Observables, then emits the output of that formula.</span>
+ *
+ * <img src="./img/withLatestFrom.png" width="100%">
+ *
+ * `withLatestFrom` combines each value from the source Observable (the
+ * instance) with the latest values from the other input Observables only when
+ * the source emits a value, optionally using a `project` function to determine
+ * the value to be emitted on the output Observable. All input Observables must
+ * emit at least one value before the output Observable will emit a value.
+ *
+ * @example <caption>On every click event, emit an array with the latest timer event plus the click event</caption>
+ * var clicks = Rx.Observable.fromEvent(document, 'click');
+ * var timer = Rx.Observable.interval(1000);
+ * var result = clicks.withLatestFrom(timer);
+ * result.subscribe(x => console.log(x));
+ *
+ * @see {@link combineLatest}
+ *
+ * @param {ObservableInput} other An input Observable to combine with the source
+ * Observable. More than one input Observables may be given as argument.
+ * @param {Function} [project] Projection function for combining values
+ * together. Receives all values in order of the Observables passed, where the
+ * first parameter is a value from the source Observable. (e.g.
+ * `a.withLatestFrom(b, c, (a1, b1, c1) => a1 + b1 + c1)`). If this is not
+ * passed, arrays will be emitted on the output Observable.
+ * @return {Observable} An Observable of projected values from the most recent
+ * values from each input Observable, or an array of the most recent values from
+ * each input Observable.
+ * @method withLatestFrom
+ * @owner Observable
+ */
+function withLatestFrom() {
+ var args = [];
+ for (var _i = 0; _i < arguments.length; _i++) {
+ args[_i - 0] = arguments[_i];
+ }
+ return function (source) {
+ var project;
+ if (typeof args[args.length - 1] === 'function') {
+ project = args.pop();
+ }
+ var observables = args;
+ return source.lift(new WithLatestFromOperator(observables, project));
+ };
+}
+exports.withLatestFrom = withLatestFrom;
+var WithLatestFromOperator = (function () {
+ function WithLatestFromOperator(observables, project) {
+ this.observables = observables;
+ this.project = project;
+ }
+ WithLatestFromOperator.prototype.call = function (subscriber, source) {
+ return source.subscribe(new WithLatestFromSubscriber(subscriber, this.observables, this.project));
+ };
+ return WithLatestFromOperator;
+}());
+/**
+ * We need this JSDoc comment for affecting ESDoc.
+ * @ignore
+ * @extends {Ignored}
+ */
+var WithLatestFromSubscriber = (function (_super) {
+ __extends(WithLatestFromSubscriber, _super);
+ function WithLatestFromSubscriber(destination, observables, project) {
+ _super.call(this, destination);
+ this.observables = observables;
+ this.project = project;
+ this.toRespond = [];
+ var len = observables.length;
+ this.values = new Array(len);
+ for (var i = 0; i < len; i++) {
+ this.toRespond.push(i);
+ }
+ for (var i = 0; i < len; i++) {
+ var observable = observables[i];
+ this.add(subscribeToResult_1.subscribeToResult(this, observable, observable, i));
+ }
+ }
+ WithLatestFromSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
+ this.values[outerIndex] = innerValue;
+ var toRespond = this.toRespond;
+ if (toRespond.length > 0) {
+ var found = toRespond.indexOf(outerIndex);
+ if (found !== -1) {
+ toRespond.splice(found, 1);
+ }
+ }
+ };
+ WithLatestFromSubscriber.prototype.notifyComplete = function () {
+ // noop
+ };
+ WithLatestFromSubscriber.prototype._next = function (value) {
+ if (this.toRespond.length === 0) {
+ var args = [value].concat(this.values);
+ if (this.project) {
+ this._tryProject(args);
+ }
+ else {
+ this.destination.next(args);
+ }
+ }
+ };
+ WithLatestFromSubscriber.prototype._tryProject = function (args) {
+ var result;
+ try {
+ result = this.project.apply(this, args);
+ }
+ catch (err) {
+ this.destination.error(err);
+ return;
+ }
+ this.destination.next(result);
+ };
+ return WithLatestFromSubscriber;
+}(OuterSubscriber_1.OuterSubscriber));
+
+},{"../OuterSubscriber":31,"../util/subscribeToResult":238}],207:[function(require,module,exports){
+"use strict";
+var __extends = (this && this.__extends) || function (d, b) {
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+};
+var ArrayObservable_1 = require('../observable/ArrayObservable');
+var isArray_1 = require('../util/isArray');
+var Subscriber_1 = require('../Subscriber');
+var OuterSubscriber_1 = require('../OuterSubscriber');
+var subscribeToResult_1 = require('../util/subscribeToResult');
+var iterator_1 = require('../symbol/iterator');
+/* tslint:enable:max-line-length */
+/**
+ * @param observables
+ * @return {Observable<R>}
+ * @method zip
+ * @owner Observable
+ */
+function zip() {
+ var observables = [];
+ for (var _i = 0; _i < arguments.length; _i++) {
+ observables[_i - 0] = arguments[_i];
+ }
+ return function zipOperatorFunction(source) {
+ return source.lift.call(zipStatic.apply(void 0, [source].concat(observables)));
+ };
+}
+exports.zip = zip;
+/* tslint:enable:max-line-length */
+/**
+ * Combines multiple Observables to create an Observable whose values are calculated from the values, in order, of each
+ * of its input Observables.
+ *
+ * If the latest parameter is a function, this function is used to compute the created value from the input values.
+ * Otherwise, an array of the input values is returned.
+ *
+ * @example <caption>Combine age and name from different sources</caption>
+ *
+ * let age$ = Observable.of<number>(27, 25, 29);
+ * let name$ = Observable.of<string>('Foo', 'Bar', 'Beer');
+ * let isDev$ = Observable.of<boolean>(true, true, false);
+ *
+ * Observable
+ * .zip(age$,
+ * name$,
+ * isDev$,
+ * (age: number, name: string, isDev: boolean) => ({ age, name, isDev }))
+ * .subscribe(x => console.log(x));
+ *
+ * // outputs
+ * // { age: 27, name: 'Foo', isDev: true }
+ * // { age: 25, name: 'Bar', isDev: true }
+ * // { age: 29, name: 'Beer', isDev: false }
+ *
+ * @param observables
+ * @return {Observable<R>}
+ * @static true
+ * @name zip
+ * @owner Observable
+ */
+function zipStatic() {
+ var observables = [];
+ for (var _i = 0; _i < arguments.length; _i++) {
+ observables[_i - 0] = arguments[_i];
+ }
+ var project = observables[observables.length - 1];
+ if (typeof project === 'function') {
+ observables.pop();
+ }
+ return new ArrayObservable_1.ArrayObservable(observables).lift(new ZipOperator(project));
+}
+exports.zipStatic = zipStatic;
+var ZipOperator = (function () {
+ function ZipOperator(project) {
+ this.project = project;
+ }
+ ZipOperator.prototype.call = function (subscriber, source) {
+ return source.subscribe(new ZipSubscriber(subscriber, this.project));
+ };
+ return ZipOperator;
+}());
+exports.ZipOperator = ZipOperator;
+/**
+ * We need this JSDoc comment for affecting ESDoc.
+ * @ignore
+ * @extends {Ignored}
+ */
+var ZipSubscriber = (function (_super) {
+ __extends(ZipSubscriber, _super);
+ function ZipSubscriber(destination, project, values) {
+ if (values === void 0) { values = Object.create(null); }
+ _super.call(this, destination);
+ this.iterators = [];
+ this.active = 0;
+ this.project = (typeof project === 'function') ? project : null;
+ this.values = values;
+ }
+ ZipSubscriber.prototype._next = function (value) {
+ var iterators = this.iterators;
+ if (isArray_1.isArray(value)) {
+ iterators.push(new StaticArrayIterator(value));
+ }
+ else if (typeof value[iterator_1.iterator] === 'function') {
+ iterators.push(new StaticIterator(value[iterator_1.iterator]()));
+ }
+ else {
+ iterators.push(new ZipBufferIterator(this.destination, this, value));
+ }
+ };
+ ZipSubscriber.prototype._complete = function () {
+ var iterators = this.iterators;
+ var len = iterators.length;
+ if (len === 0) {
+ this.destination.complete();
+ return;
+ }
+ this.active = len;
+ for (var i = 0; i < len; i++) {
+ var iterator = iterators[i];
+ if (iterator.stillUnsubscribed) {
+ this.add(iterator.subscribe(iterator, i));
+ }
+ else {
+ this.active--; // not an observable
+ }
+ }
+ };
+ ZipSubscriber.prototype.notifyInactive = function () {
+ this.active--;
+ if (this.active === 0) {
+ this.destination.complete();
+ }
+ };
+ ZipSubscriber.prototype.checkIterators = function () {
+ var iterators = this.iterators;
+ var len = iterators.length;
+ var destination = this.destination;
+ // abort if not all of them have values
+ for (var i = 0; i < len; i++) {
+ var iterator = iterators[i];
+ if (typeof iterator.hasValue === 'function' && !iterator.hasValue()) {
+ return;
+ }
+ }
+ var shouldComplete = false;
+ var args = [];
+ for (var i = 0; i < len; i++) {
+ var iterator = iterators[i];
+ var result = iterator.next();
+ // check to see if it's completed now that you've gotten
+ // the next value.
+ if (iterator.hasCompleted()) {
+ shouldComplete = true;
+ }
+ if (result.done) {
+ destination.complete();
+ return;
+ }
+ args.push(result.value);
+ }
+ if (this.project) {
+ this._tryProject(args);
+ }
+ else {
+ destination.next(args);
+ }
+ if (shouldComplete) {
+ destination.complete();
+ }
+ };
+ ZipSubscriber.prototype._tryProject = function (args) {
+ var result;
+ try {
+ result = this.project.apply(this, args);
+ }
+ catch (err) {
+ this.destination.error(err);
+ return;
+ }
+ this.destination.next(result);
+ };
+ return ZipSubscriber;
+}(Subscriber_1.Subscriber));
+exports.ZipSubscriber = ZipSubscriber;
+var StaticIterator = (function () {
+ function StaticIterator(iterator) {
+ this.iterator = iterator;
+ this.nextResult = iterator.next();
+ }
+ StaticIterator.prototype.hasValue = function () {
+ return true;
+ };
+ StaticIterator.prototype.next = function () {
+ var result = this.nextResult;
+ this.nextResult = this.iterator.next();
+ return result;
+ };
+ StaticIterator.prototype.hasCompleted = function () {
+ var nextResult = this.nextResult;
+ return nextResult && nextResult.done;
+ };
+ return StaticIterator;
+}());
+var StaticArrayIterator = (function () {
+ function StaticArrayIterator(array) {
+ this.array = array;
+ this.index = 0;
+ this.length = 0;
+ this.length = array.length;
+ }
+ StaticArrayIterator.prototype[iterator_1.iterator] = function () {
+ return this;
+ };
+ StaticArrayIterator.prototype.next = function (value) {
+ var i = this.index++;
+ var array = this.array;
+ return i < this.length ? { value: array[i], done: false } : { value: null, done: true };
+ };
+ StaticArrayIterator.prototype.hasValue = function () {
+ return this.array.length > this.index;
+ };
+ StaticArrayIterator.prototype.hasCompleted = function () {
+ return this.array.length === this.index;
+ };
+ return StaticArrayIterator;
+}());
+/**
+ * We need this JSDoc comment for affecting ESDoc.
+ * @ignore
+ * @extends {Ignored}
+ */
+var ZipBufferIterator = (function (_super) {
+ __extends(ZipBufferIterator, _super);
+ function ZipBufferIterator(destination, parent, observable) {
+ _super.call(this, destination);
+ this.parent = parent;
+ this.observable = observable;
+ this.stillUnsubscribed = true;
+ this.buffer = [];
+ this.isComplete = false;
+ }
+ ZipBufferIterator.prototype[iterator_1.iterator] = function () {
+ return this;
+ };
+ // NOTE: there is actually a name collision here with Subscriber.next and Iterator.next
+ // this is legit because `next()` will never be called by a subscription in this case.
+ ZipBufferIterator.prototype.next = function () {
+ var buffer = this.buffer;
+ if (buffer.length === 0 && this.isComplete) {
+ return { value: null, done: true };
+ }
+ else {
+ return { value: buffer.shift(), done: false };
+ }
+ };
+ ZipBufferIterator.prototype.hasValue = function () {
+ return this.buffer.length > 0;
+ };
+ ZipBufferIterator.prototype.hasCompleted = function () {
+ return this.buffer.length === 0 && this.isComplete;
+ };
+ ZipBufferIterator.prototype.notifyComplete = function () {
+ if (this.buffer.length > 0) {
+ this.isComplete = true;
+ this.parent.notifyInactive();
+ }
+ else {
+ this.destination.complete();
+ }
+ };
+ ZipBufferIterator.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
+ this.buffer.push(innerValue);
+ this.parent.checkIterators();
+ };
+ ZipBufferIterator.prototype.subscribe = function (value, index) {
+ return subscribeToResult_1.subscribeToResult(this, this.observable, this, index);
+ };
+ return ZipBufferIterator;
+}(OuterSubscriber_1.OuterSubscriber));
+
+},{"../OuterSubscriber":31,"../Subscriber":36,"../observable/ArrayObservable":93,"../symbol/iterator":215,"../util/isArray":227,"../util/subscribeToResult":238}],208:[function(require,module,exports){
+"use strict";
+var __extends = (this && this.__extends) || function (d, b) {
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+};
+var Subscription_1 = require('../Subscription');
+/**
+ * A unit of work to be executed in a {@link Scheduler}. An action is typically
+ * created from within a Scheduler and an RxJS user does not need to concern
+ * themselves about creating and manipulating an Action.
+ *
+ * ```ts
+ * class Action<T> extends Subscription {
+ * new (scheduler: Scheduler, work: (state?: T) => void);
+ * schedule(state?: T, delay: number = 0): Subscription;
+ * }
+ * ```
+ *
+ * @class Action<T>
+ */
+var Action = (function (_super) {
+ __extends(Action, _super);
+ function Action(scheduler, work) {
+ _super.call(this);
+ }
+ /**
+ * Schedules this action on its parent Scheduler for execution. May be passed
+ * some context object, `state`. May happen at some point in the future,
+ * according to the `delay` parameter, if specified.
+ * @param {T} [state] Some contextual data that the `work` function uses when
+ * called by the Scheduler.
+ * @param {number} [delay] Time to wait before executing the work, where the
+ * time unit is implicit and defined by the Scheduler.
+ * @return {void}
+ */
+ Action.prototype.schedule = function (state, delay) {
+ if (delay === void 0) { delay = 0; }
+ return this;
+ };
+ return Action;
+}(Subscription_1.Subscription));
+exports.Action = Action;
+
+},{"../Subscription":37}],209:[function(require,module,exports){
+"use strict";
+var __extends = (this && this.__extends) || function (d, b) {
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+};
+var root_1 = require('../util/root');
+var Action_1 = require('./Action');
+/**
+ * We need this JSDoc comment for affecting ESDoc.
+ * @ignore
+ * @extends {Ignored}
+ */
+var AsyncAction = (function (_super) {
+ __extends(AsyncAction, _super);
+ function AsyncAction(scheduler, work) {
+ _super.call(this, scheduler, work);
+ this.scheduler = scheduler;
+ this.work = work;
+ this.pending = false;
+ }
+ AsyncAction.prototype.schedule = function (state, delay) {
+ if (delay === void 0) { delay = 0; }
+ if (this.closed) {
+ return this;
+ }
+ // Always replace the current state with the new state.
+ this.state = state;
+ // Set the pending flag indicating that this action has been scheduled, or
+ // has recursively rescheduled itself.
+ this.pending = true;
+ var id = this.id;
+ var scheduler = this.scheduler;
+ //
+ // Important implementation note:
+ //
+ // Actions only execute once by default, unless rescheduled from within the
+ // scheduled callback. This allows us to implement single and repeat
+ // actions via the same code path, without adding API surface area, as well
+ // as mimic traditional recursion but across asynchronous boundaries.
+ //
+ // However, JS runtimes and timers distinguish between intervals achieved by
+ // serial `setTimeout` calls vs. a single `setInterval` call. An interval of
+ // serial `setTimeout` calls can be individually delayed, which delays
+ // scheduling the next `setTimeout`, and so on. `setInterval` attempts to
+ // guarantee the interval callback will be invoked more precisely to the
+ // interval period, regardless of load.
+ //
+ // Therefore, we use `setInterval` to schedule single and repeat actions.
+ // If the action reschedules itself with the same delay, the interval is not
+ // canceled. If the action doesn't reschedule, or reschedules with a
+ // different delay, the interval will be canceled after scheduled callback
+ // execution.
+ //
+ if (id != null) {
+ this.id = this.recycleAsyncId(scheduler, id, delay);
+ }
+ this.delay = delay;
+ // If this action has already an async Id, don't request a new one.
+ this.id = this.id || this.requestAsyncId(scheduler, this.id, delay);
+ return this;
+ };
+ AsyncAction.prototype.requestAsyncId = function (scheduler, id, delay) {
+ if (delay === void 0) { delay = 0; }
+ return root_1.root.setInterval(scheduler.flush.bind(scheduler, this), delay);
+ };
+ AsyncAction.prototype.recycleAsyncId = function (scheduler, id, delay) {
+ if (delay === void 0) { delay = 0; }
+ // If this action is rescheduled with the same delay time, don't clear the interval id.
+ if (delay !== null && this.delay === delay && this.pending === false) {
+ return id;
+ }
+ // Otherwise, if the action's delay time is different from the current delay,
+ // or the action has been rescheduled before it's executed, clear the interval id
+ return root_1.root.clearInterval(id) && undefined || undefined;
+ };
+ /**
+ * Immediately executes this action and the `work` it contains.
+ * @return {any}
+ */
+ AsyncAction.prototype.execute = function (state, delay) {
+ if (this.closed) {
+ return new Error('executing a cancelled action');
+ }
+ this.pending = false;
+ var error = this._execute(state, delay);
+ if (error) {
+ return error;
+ }
+ else if (this.pending === false && this.id != null) {
+ // Dequeue if the action didn't reschedule itself. Don't call
+ // unsubscribe(), because the action could reschedule later.
+ // For example:
+ // ```
+ // scheduler.schedule(function doWork(counter) {
+ // /* ... I'm a busy worker bee ... */
+ // var originalAction = this;
+ // /* wait 100ms before rescheduling the action */
+ // setTimeout(function () {
+ // originalAction.schedule(counter + 1);
+ // }, 100);
+ // }, 1000);
+ // ```
+ this.id = this.recycleAsyncId(this.scheduler, this.id, null);
+ }
+ };
+ AsyncAction.prototype._execute = function (state, delay) {
+ var errored = false;
+ var errorValue = undefined;
+ try {
+ this.work(state);
+ }
+ catch (e) {
+ errored = true;
+ errorValue = !!e && e || new Error(e);
+ }
+ if (errored) {
+ this.unsubscribe();
+ return errorValue;
+ }
+ };
+ AsyncAction.prototype._unsubscribe = function () {
+ var id = this.id;
+ var scheduler = this.scheduler;
+ var actions = scheduler.actions;
+ var index = actions.indexOf(this);
+ this.work = null;
+ this.state = null;
+ this.pending = false;
+ this.scheduler = null;
+ if (index !== -1) {
+ actions.splice(index, 1);
+ }
+ if (id != null) {
+ this.id = this.recycleAsyncId(scheduler, id, null);
+ }
+ this.delay = null;
+ };
+ return AsyncAction;
+}(Action_1.Action));
+exports.AsyncAction = AsyncAction;
+
+},{"../util/root":237,"./Action":208}],210:[function(require,module,exports){
+"use strict";
+var __extends = (this && this.__extends) || function (d, b) {
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+};
+var Scheduler_1 = require('../Scheduler');
+var AsyncScheduler = (function (_super) {
+ __extends(AsyncScheduler, _super);
+ function AsyncScheduler() {
+ _super.apply(this, arguments);
+ this.actions = [];
+ /**
+ * A flag to indicate whether the Scheduler is currently executing a batch of
+ * queued actions.
+ * @type {boolean}
+ */
+ this.active = false;
+ /**
+ * An internal ID used to track the latest asynchronous task such as those
+ * coming from `setTimeout`, `setInterval`, `requestAnimationFrame`, and
+ * others.
+ * @type {any}
+ */
+ this.scheduled = undefined;
+ }
+ AsyncScheduler.prototype.flush = function (action) {
+ var actions = this.actions;
+ if (this.active) {
+ actions.push(action);
+ return;
+ }
+ var error;
+ this.active = true;
+ do {
+ if (error = action.execute(action.state, action.delay)) {
+ break;
+ }
+ } while (action = actions.shift()); // exhaust the scheduler queue
+ this.active = false;
+ if (error) {
+ while (action = actions.shift()) {
+ action.unsubscribe();
+ }
+ throw error;
+ }
+ };
+ return AsyncScheduler;
+}(Scheduler_1.Scheduler));
+exports.AsyncScheduler = AsyncScheduler;
+
+},{"../Scheduler":33}],211:[function(require,module,exports){
+"use strict";
+var __extends = (this && this.__extends) || function (d, b) {
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+};
+var AsyncAction_1 = require('./AsyncAction');
+/**
+ * We need this JSDoc comment for affecting ESDoc.
+ * @ignore
+ * @extends {Ignored}
+ */
+var QueueAction = (function (_super) {
+ __extends(QueueAction, _super);
+ function QueueAction(scheduler, work) {
+ _super.call(this, scheduler, work);
+ this.scheduler = scheduler;
+ this.work = work;
+ }
+ QueueAction.prototype.schedule = function (state, delay) {
+ if (delay === void 0) { delay = 0; }
+ if (delay > 0) {
+ return _super.prototype.schedule.call(this, state, delay);
+ }
+ this.delay = delay;
+ this.state = state;
+ this.scheduler.flush(this);
+ return this;
+ };
+ QueueAction.prototype.execute = function (state, delay) {
+ return (delay > 0 || this.closed) ?
+ _super.prototype.execute.call(this, state, delay) :
+ this._execute(state, delay);
+ };
+ QueueAction.prototype.requestAsyncId = function (scheduler, id, delay) {
+ if (delay === void 0) { delay = 0; }
+ // If delay exists and is greater than 0, or if the delay is null (the
+ // action wasn't rescheduled) but was originally scheduled as an async
+ // action, then recycle as an async action.
+ if ((delay !== null && delay > 0) || (delay === null && this.delay > 0)) {
+ return _super.prototype.requestAsyncId.call(this, scheduler, id, delay);
+ }
+ // Otherwise flush the scheduler starting with this action.
+ return scheduler.flush(this);
+ };
+ return QueueAction;
+}(AsyncAction_1.AsyncAction));
+exports.QueueAction = QueueAction;
+
+},{"./AsyncAction":209}],212:[function(require,module,exports){
+"use strict";
+var __extends = (this && this.__extends) || function (d, b) {
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+};
+var AsyncScheduler_1 = require('./AsyncScheduler');
+var QueueScheduler = (function (_super) {
+ __extends(QueueScheduler, _super);
+ function QueueScheduler() {
+ _super.apply(this, arguments);
+ }
+ return QueueScheduler;
+}(AsyncScheduler_1.AsyncScheduler));
+exports.QueueScheduler = QueueScheduler;
+
+},{"./AsyncScheduler":210}],213:[function(require,module,exports){
+"use strict";
+var AsyncAction_1 = require('./AsyncAction');
+var AsyncScheduler_1 = require('./AsyncScheduler');
+/**
+ *
+ * Async Scheduler
+ *
+ * <span class="informal">Schedule task as if you used setTimeout(task, duration)</span>
+ *
+ * `async` scheduler schedules tasks asynchronously, by putting them on the JavaScript
+ * event loop queue. It is best used to delay tasks in time or to schedule tasks repeating
+ * in intervals.
+ *
+ * If you just want to "defer" task, that is to perform it right after currently
+ * executing synchronous code ends (commonly achieved by `setTimeout(deferredTask, 0)`),
+ * better choice will be the {@link asap} scheduler.
+ *
+ * @example <caption>Use async scheduler to delay task</caption>
+ * const task = () => console.log('it works!');
+ *
+ * Rx.Scheduler.async.schedule(task, 2000);
+ *
+ * // After 2 seconds logs:
+ * // "it works!"
+ *
+ *
+ * @example <caption>Use async scheduler to repeat task in intervals</caption>
+ * function task(state) {
+ * console.log(state);
+ * this.schedule(state + 1, 1000); // `this` references currently executing Action,
+ * // which we reschedule with new state and delay
+ * }
+ *
+ * Rx.Scheduler.async.schedule(task, 3000, 0);
+ *
+ * // Logs:
+ * // 0 after 3s
+ * // 1 after 4s
+ * // 2 after 5s
+ * // 3 after 6s
+ *
+ * @static true
+ * @name async
+ * @owner Scheduler
+ */
+exports.async = new AsyncScheduler_1.AsyncScheduler(AsyncAction_1.AsyncAction);
+
+},{"./AsyncAction":209,"./AsyncScheduler":210}],214:[function(require,module,exports){
+"use strict";
+var QueueAction_1 = require('./QueueAction');
+var QueueScheduler_1 = require('./QueueScheduler');
+/**
+ *
+ * Queue Scheduler
+ *
+ * <span class="informal">Put every next task on a queue, instead of executing it immediately</span>
+ *
+ * `queue` scheduler, when used with delay, behaves the same as {@link async} scheduler.
+ *
+ * When used without delay, it schedules given task synchronously - executes it right when
+ * it is scheduled. However when called recursively, that is when inside the scheduled task,
+ * another task is scheduled with queue scheduler, instead of executing immediately as well,
+ * that task will be put on a queue and wait for current one to finish.
+ *
+ * This means that when you execute task with `queue` scheduler, you are sure it will end
+ * before any other task scheduled with that scheduler will start.
+ *
+ * @examples <caption>Schedule recursively first, then do something</caption>
+ *
+ * Rx.Scheduler.queue.schedule(() => {
+ * Rx.Scheduler.queue.schedule(() => console.log('second')); // will not happen now, but will be put on a queue
+ *
+ * console.log('first');
+ * });
+ *
+ * // Logs:
+ * // "first"
+ * // "second"
+ *
+ *
+ * @example <caption>Reschedule itself recursively</caption>
+ *
+ * Rx.Scheduler.queue.schedule(function(state) {
+ * if (state !== 0) {
+ * console.log('before', state);
+ * this.schedule(state - 1); // `this` references currently executing Action,
+ * // which we reschedule with new state
+ * console.log('after', state);
+ * }
+ * }, 0, 3);
+ *
+ * // In scheduler that runs recursively, you would expect:
+ * // "before", 3
+ * // "before", 2
+ * // "before", 1
+ * // "after", 1
+ * // "after", 2
+ * // "after", 3
+ *
+ * // But with queue it logs:
+ * // "before", 3
+ * // "after", 3
+ * // "before", 2
+ * // "after", 2
+ * // "before", 1
+ * // "after", 1
+ *
+ *
+ * @static true
+ * @name queue
+ * @owner Scheduler
+ */
+exports.queue = new QueueScheduler_1.QueueScheduler(QueueAction_1.QueueAction);
+
+},{"./QueueAction":211,"./QueueScheduler":212}],215:[function(require,module,exports){
+"use strict";
+var root_1 = require('../util/root');
+function symbolIteratorPonyfill(root) {
+ var Symbol = root.Symbol;
+ if (typeof Symbol === 'function') {
+ if (!Symbol.iterator) {
+ Symbol.iterator = Symbol('iterator polyfill');
+ }
+ return Symbol.iterator;
+ }
+ else {
+ // [for Mozilla Gecko 27-35:](https://mzl.la/2ewE1zC)
+ var Set_1 = root.Set;
+ if (Set_1 && typeof new Set_1()['@@iterator'] === 'function') {
+ return '@@iterator';
+ }
+ var Map_1 = root.Map;
+ // required for compatability with es6-shim
+ if (Map_1) {
+ var keys = Object.getOwnPropertyNames(Map_1.prototype);
+ for (var i = 0; i < keys.length; ++i) {
+ var key = keys[i];
+ // according to spec, Map.prototype[@@iterator] and Map.orototype.entries must be equal.
+ if (key !== 'entries' && key !== 'size' && Map_1.prototype[key] === Map_1.prototype['entries']) {
+ return key;
+ }
+ }
+ }
+ return '@@iterator';
+ }
+}
+exports.symbolIteratorPonyfill = symbolIteratorPonyfill;
+exports.iterator = symbolIteratorPonyfill(root_1.root);
+/**
+ * @deprecated use iterator instead
+ */
+exports.$$iterator = exports.iterator;
+
+},{"../util/root":237}],216:[function(require,module,exports){
+"use strict";
+var root_1 = require('../util/root');
+function getSymbolObservable(context) {
+ var $$observable;
+ var Symbol = context.Symbol;
+ if (typeof Symbol === 'function') {
+ if (Symbol.observable) {
+ $$observable = Symbol.observable;
+ }
+ else {
+ $$observable = Symbol('observable');
+ Symbol.observable = $$observable;
+ }
+ }
+ else {
+ $$observable = '@@observable';
+ }
+ return $$observable;
+}
+exports.getSymbolObservable = getSymbolObservable;
+exports.observable = getSymbolObservable(root_1.root);
+/**
+ * @deprecated use observable instead
+ */
+exports.$$observable = exports.observable;
+
+},{"../util/root":237}],217:[function(require,module,exports){
+"use strict";
+var root_1 = require('../util/root');
+var Symbol = root_1.root.Symbol;
+exports.rxSubscriber = (typeof Symbol === 'function' && typeof Symbol.for === 'function') ?
+ Symbol.for('rxSubscriber') : '@@rxSubscriber';
+/**
+ * @deprecated use rxSubscriber instead
+ */
+exports.$$rxSubscriber = exports.rxSubscriber;
+
+},{"../util/root":237}],218:[function(require,module,exports){
+"use strict";
+var root_1 = require('./root');
+var RequestAnimationFrameDefinition = (function () {
+ function RequestAnimationFrameDefinition(root) {
+ if (root.requestAnimationFrame) {
+ this.cancelAnimationFrame = root.cancelAnimationFrame.bind(root);
+ this.requestAnimationFrame = root.requestAnimationFrame.bind(root);
+ }
+ else if (root.mozRequestAnimationFrame) {
+ this.cancelAnimationFrame = root.mozCancelAnimationFrame.bind(root);
+ this.requestAnimationFrame = root.mozRequestAnimationFrame.bind(root);
+ }
+ else if (root.webkitRequestAnimationFrame) {
+ this.cancelAnimationFrame = root.webkitCancelAnimationFrame.bind(root);
+ this.requestAnimationFrame = root.webkitRequestAnimationFrame.bind(root);
+ }
+ else if (root.msRequestAnimationFrame) {
+ this.cancelAnimationFrame = root.msCancelAnimationFrame.bind(root);
+ this.requestAnimationFrame = root.msRequestAnimationFrame.bind(root);
+ }
+ else if (root.oRequestAnimationFrame) {
+ this.cancelAnimationFrame = root.oCancelAnimationFrame.bind(root);
+ this.requestAnimationFrame = root.oRequestAnimationFrame.bind(root);
+ }
+ else {
+ this.cancelAnimationFrame = root.clearTimeout.bind(root);
+ this.requestAnimationFrame = function (cb) { return root.setTimeout(cb, 1000 / 60); };
+ }
+ }
+ return RequestAnimationFrameDefinition;
+}());
+exports.RequestAnimationFrameDefinition = RequestAnimationFrameDefinition;
+exports.AnimationFrame = new RequestAnimationFrameDefinition(root_1.root);
+
+},{"./root":237}],219:[function(require,module,exports){
+"use strict";
+var __extends = (this && this.__extends) || function (d, b) {
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+};
+/**
+ * An error thrown when an element was queried at a certain index of an
+ * Observable, but no such index or position exists in that sequence.
+ *
+ * @see {@link elementAt}
+ * @see {@link take}
+ * @see {@link takeLast}
+ *
+ * @class ArgumentOutOfRangeError
+ */
+var ArgumentOutOfRangeError = (function (_super) {
+ __extends(ArgumentOutOfRangeError, _super);
+ function ArgumentOutOfRangeError() {
+ var err = _super.call(this, 'argument out of range');
+ this.name = err.name = 'ArgumentOutOfRangeError';
+ this.stack = err.stack;
+ this.message = err.message;
+ }
+ return ArgumentOutOfRangeError;
+}(Error));
+exports.ArgumentOutOfRangeError = ArgumentOutOfRangeError;
+
+},{}],220:[function(require,module,exports){
+"use strict";
+var __extends = (this && this.__extends) || function (d, b) {
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+};
+/**
+ * An error thrown when an Observable or a sequence was queried but has no
+ * elements.
+ *
+ * @see {@link first}
+ * @see {@link last}
+ * @see {@link single}
+ *
+ * @class EmptyError
+ */
+var EmptyError = (function (_super) {
+ __extends(EmptyError, _super);
+ function EmptyError() {
+ var err = _super.call(this, 'no elements in sequence');
+ this.name = err.name = 'EmptyError';
+ this.stack = err.stack;
+ this.message = err.message;
+ }
+ return EmptyError;
+}(Error));
+exports.EmptyError = EmptyError;
+
+},{}],221:[function(require,module,exports){
+"use strict";
+var __extends = (this && this.__extends) || function (d, b) {
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+};
+/**
+ * An error thrown when an action is invalid because the object has been
+ * unsubscribed.
+ *
+ * @see {@link Subject}
+ * @see {@link BehaviorSubject}
+ *
+ * @class ObjectUnsubscribedError
+ */
+var ObjectUnsubscribedError = (function (_super) {
+ __extends(ObjectUnsubscribedError, _super);
+ function ObjectUnsubscribedError() {
+ var err = _super.call(this, 'object unsubscribed');
+ this.name = err.name = 'ObjectUnsubscribedError';
+ this.stack = err.stack;
+ this.message = err.message;
+ }
+ return ObjectUnsubscribedError;
+}(Error));
+exports.ObjectUnsubscribedError = ObjectUnsubscribedError;
+
+},{}],222:[function(require,module,exports){
+"use strict";
+var root_1 = require('./root');
+function minimalSetImpl() {
+ // THIS IS NOT a full impl of Set, this is just the minimum
+ // bits of functionality we need for this library.
+ return (function () {
+ function MinimalSet() {
+ this._values = [];
+ }
+ MinimalSet.prototype.add = function (value) {
+ if (!this.has(value)) {
+ this._values.push(value);
+ }
+ };
+ MinimalSet.prototype.has = function (value) {
+ return this._values.indexOf(value) !== -1;
+ };
+ Object.defineProperty(MinimalSet.prototype, "size", {
+ get: function () {
+ return this._values.length;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ MinimalSet.prototype.clear = function () {
+ this._values.length = 0;
+ };
+ return MinimalSet;
+ }());
+}
+exports.minimalSetImpl = minimalSetImpl;
+exports.Set = root_1.root.Set || minimalSetImpl();
+
+},{"./root":237}],223:[function(require,module,exports){
+"use strict";
+var __extends = (this && this.__extends) || function (d, b) {
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+};
+/**
+ * An error thrown when duetime elapses.
+ *
+ * @see {@link timeout}
+ *
+ * @class TimeoutError
+ */
+var TimeoutError = (function (_super) {
+ __extends(TimeoutError, _super);
+ function TimeoutError() {
+ var err = _super.call(this, 'Timeout has occurred');
+ this.name = err.name = 'TimeoutError';
+ this.stack = err.stack;
+ this.message = err.message;
+ }
+ return TimeoutError;
+}(Error));
+exports.TimeoutError = TimeoutError;
+
+},{}],224:[function(require,module,exports){
+"use strict";
+var __extends = (this && this.__extends) || function (d, b) {
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+};
+/**
+ * An error thrown when one or more errors have occurred during the
+ * `unsubscribe` of a {@link Subscription}.
+ */
+var UnsubscriptionError = (function (_super) {
+ __extends(UnsubscriptionError, _super);
+ function UnsubscriptionError(errors) {
+ _super.call(this);
+ this.errors = errors;
+ var err = Error.call(this, errors ?
+ errors.length + " errors occurred during unsubscription:\n " + errors.map(function (err, i) { return ((i + 1) + ") " + err.toString()); }).join('\n ') : '');
+ this.name = err.name = 'UnsubscriptionError';
+ this.stack = err.stack;
+ this.message = err.message;
+ }
+ return UnsubscriptionError;
+}(Error));
+exports.UnsubscriptionError = UnsubscriptionError;
+
+},{}],225:[function(require,module,exports){
+"use strict";
+// typeof any so that it we don't have to cast when comparing a result to the error object
+exports.errorObject = { e: {} };
+
+},{}],226:[function(require,module,exports){
+"use strict";
+function identity(x) {
+ return x;
+}
+exports.identity = identity;
+
+},{}],227:[function(require,module,exports){
+"use strict";
+exports.isArray = Array.isArray || (function (x) { return x && typeof x.length === 'number'; });
+
+},{}],228:[function(require,module,exports){
+"use strict";
+exports.isArrayLike = (function (x) { return x && typeof x.length === 'number'; });
+
+},{}],229:[function(require,module,exports){
+"use strict";
+function isDate(value) {
+ return value instanceof Date && !isNaN(+value);
+}
+exports.isDate = isDate;
+
+},{}],230:[function(require,module,exports){
+"use strict";
+function isFunction(x) {
+ return typeof x === 'function';
+}
+exports.isFunction = isFunction;
+
+},{}],231:[function(require,module,exports){
+"use strict";
+var isArray_1 = require('../util/isArray');
+function isNumeric(val) {
+ // parseFloat NaNs numeric-cast false positives (null|true|false|"")
+ // ...but misinterprets leading-number strings, particularly hex literals ("0x...")
+ // subtraction forces infinities to NaN
+ // adding 1 corrects loss of precision from parseFloat (#15100)
+ return !isArray_1.isArray(val) && (val - parseFloat(val) + 1) >= 0;
+}
+exports.isNumeric = isNumeric;
+;
+
+},{"../util/isArray":227}],232:[function(require,module,exports){
+"use strict";
+function isObject(x) {
+ return x != null && typeof x === 'object';
+}
+exports.isObject = isObject;
+
+},{}],233:[function(require,module,exports){
+"use strict";
+function isPromise(value) {
+ return value && typeof value.subscribe !== 'function' && typeof value.then === 'function';
+}
+exports.isPromise = isPromise;
+
+},{}],234:[function(require,module,exports){
+"use strict";
+function isScheduler(value) {
+ return value && typeof value.schedule === 'function';
+}
+exports.isScheduler = isScheduler;
+
+},{}],235:[function(require,module,exports){
+"use strict";
+/* tslint:disable:no-empty */
+function noop() { }
+exports.noop = noop;
+
+},{}],236:[function(require,module,exports){
+"use strict";
+var noop_1 = require('./noop');
+/* tslint:enable:max-line-length */
+function pipe() {
+ var fns = [];
+ for (var _i = 0; _i < arguments.length; _i++) {
+ fns[_i - 0] = arguments[_i];
+ }
+ return pipeFromArray(fns);
+}
+exports.pipe = pipe;
+/* @internal */
+function pipeFromArray(fns) {
+ if (!fns) {
+ return noop_1.noop;
+ }
+ if (fns.length === 1) {
+ return fns[0];
+ }
+ return function piped(input) {
+ return fns.reduce(function (prev, fn) { return fn(prev); }, input);
+ };
+}
+exports.pipeFromArray = pipeFromArray;
+
+},{"./noop":235}],237:[function(require,module,exports){
+(function (global){
+"use strict";
+// CommonJS / Node have global context exposed as "global" variable.
+// We don't want to include the whole node.d.ts this this compilation unit so we'll just fake
+// the global "global" var for now.
+var __window = typeof window !== 'undefined' && window;
+var __self = typeof self !== 'undefined' && typeof WorkerGlobalScope !== 'undefined' &&
+ self instanceof WorkerGlobalScope && self;
+var __global = typeof global !== 'undefined' && global;
+var _root = __window || __global || __self;
+exports.root = _root;
+// Workaround Closure Compiler restriction: The body of a goog.module cannot use throw.
+// This is needed when used with angular/tsickle which inserts a goog.module statement.
+// Wrap in IIFE
+(function () {
+ if (!_root) {
+ throw new Error('RxJS could not find any global context (window, self, global)');
+ }
+})();
+
+}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
+
+},{}],238:[function(require,module,exports){
+"use strict";
+var root_1 = require('./root');
+var isArrayLike_1 = require('./isArrayLike');
+var isPromise_1 = require('./isPromise');
+var isObject_1 = require('./isObject');
+var Observable_1 = require('../Observable');
+var iterator_1 = require('../symbol/iterator');
+var InnerSubscriber_1 = require('../InnerSubscriber');
+var observable_1 = require('../symbol/observable');
+function subscribeToResult(outerSubscriber, result, outerValue, outerIndex) {
+ var destination = new InnerSubscriber_1.InnerSubscriber(outerSubscriber, outerValue, outerIndex);
+ if (destination.closed) {
+ return null;
+ }
+ if (result instanceof Observable_1.Observable) {
+ if (result._isScalar) {
+ destination.next(result.value);
+ destination.complete();
+ return null;
+ }
+ else {
+ destination.syncErrorThrowable = true;
+ return result.subscribe(destination);
+ }
+ }
+ else if (isArrayLike_1.isArrayLike(result)) {
+ for (var i = 0, len = result.length; i < len && !destination.closed; i++) {
+ destination.next(result[i]);
+ }
+ if (!destination.closed) {
+ destination.complete();
+ }
+ }
+ else if (isPromise_1.isPromise(result)) {
+ result.then(function (value) {
+ if (!destination.closed) {
+ destination.next(value);
+ destination.complete();
+ }
+ }, function (err) { return destination.error(err); })
+ .then(null, function (err) {
+ // Escaping the Promise trap: globally throw unhandled errors
+ root_1.root.setTimeout(function () { throw err; });
+ });
+ return destination;
+ }
+ else if (result && typeof result[iterator_1.iterator] === 'function') {
+ var iterator = result[iterator_1.iterator]();