+ *
+ * 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; }
+ return timeout_1.timeout(due, scheduler)(this);
+}
+exports.timeout = timeout;
+
+},{"../operators/timeout":205,"../scheduler/async":213}],156:[function(require,module,exports){
+"use strict";
+var withLatestFrom_1 = require('../operators/withLatestFrom');
+/* 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 withLatestFrom_1.withLatestFrom.apply(void 0, args)(this);
+}
+exports.withLatestFrom = withLatestFrom;
+
+},{"../operators/withLatestFrom":206}],157:[function(require,module,exports){
+"use strict";
+var zip_1 = require('../operators/zip');
+/* tslint:enable:max-line-length */
+/**
+ * @param observables
+ * @return {Observable<R>}
+ * @method zip
+ * @owner Observable
+ */
+function zipProto() {
+ var observables = [];
+ for (var _i = 0; _i < arguments.length; _i++) {
+ observables[_i - 0] = arguments[_i];
+ }
+ return zip_1.zip.apply(void 0, observables)(this);
+}
+exports.zipProto = zipProto;
+
+},{"../operators/zip":207}],158:[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');
+/**
+ * Ignores source values for a duration determined by another Observable, then
+ * emits the most recent value from the source Observable, then repeats this
+ * process.
+ *
+ * <span class="informal">It's like {@link auditTime}, but the silencing
+ * duration is determined by a second Observable.</span>
+ *
+ * <img src="./img/audit.png" width="100%">
+ *
+ * `audit` is similar to `throttle`, but emits the last value from the silenced
+ * time window, instead of the first value. `audit` emits the most recent value
+ * from the source Observable on the output Observable as soon as its internal
+ * timer becomes disabled, and ignores source values while the timer is enabled.
+ * Initially, the timer is disabled. As soon as the first source value arrives,
+ * 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, then the most
+ * recent source value is emitted on the output Observable, 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.audit(ev => Rx.Observable.interval(1000));
+ * result.subscribe(x => console.log(x));
+ *
+ * @see {@link auditTime}
+ * @see {@link debounce}
+ * @see {@link delayWhen}
+ * @see {@link sample}
+ * @see {@link throttle}
+ *
+ * @param {function(value: T): SubscribableOrPromise} durationSelector A function
+ * that receives a value from the source Observable, for computing the silencing
+ * duration, returned as an Observable or a Promise.
+ * @return {Observable<T>} An Observable that performs rate-limiting of
+ * emissions from the source Observable.
+ * @method audit
+ * @owner Observable
+ */
+function audit(durationSelector) {
+ return function auditOperatorFunction(source) {
+ return source.lift(new AuditOperator(durationSelector));
+ };
+}
+exports.audit = audit;
+var AuditOperator = (function () {
+ function AuditOperator(durationSelector) {
+ this.durationSelector = durationSelector;
+ }
+ AuditOperator.prototype.call = function (subscriber, source) {
+ return source.subscribe(new AuditSubscriber(subscriber, this.durationSelector));
+ };
+ return AuditOperator;
+}());
+/**
+ * We need this JSDoc comment for affecting ESDoc.
+ * @ignore
+ * @extends {Ignored}
+ */
+var AuditSubscriber = (function (_super) {
+ __extends(AuditSubscriber, _super);
+ function AuditSubscriber(destination, durationSelector) {
+ _super.call(this, destination);
+ this.durationSelector = durationSelector;
+ this.hasValue = false;
+ }
+ AuditSubscriber.prototype._next = function (value) {
+ this.value = value;
+ this.hasValue = true;
+ if (!this.throttled) {
+ var duration = tryCatch_1.tryCatch(this.durationSelector)(value);
+ if (duration === errorObject_1.errorObject) {
+ this.destination.error(errorObject_1.errorObject.e);
+ }
+ else {
+ var innerSubscription = subscribeToResult_1.subscribeToResult(this, duration);
+ if (innerSubscription.closed) {
+ this.clearThrottle();
+ }
+ else {
+ this.add(this.throttled = innerSubscription);
+ }
+ }
+ }
+ };
+ AuditSubscriber.prototype.clearThrottle = function () {
+ var _a = this, value = _a.value, hasValue = _a.hasValue, throttled = _a.throttled;
+ if (throttled) {
+ this.remove(throttled);
+ this.throttled = null;
+ throttled.unsubscribe();
+ }
+ if (hasValue) {
+ this.value = null;
+ this.hasValue = false;
+ this.destination.next(value);
+ }
+ };
+ AuditSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex) {
+ this.clearThrottle();
+ };
+ AuditSubscriber.prototype.notifyComplete = function () {
+ this.clearThrottle();
+ };
+ return AuditSubscriber;
+}(OuterSubscriber_1.OuterSubscriber));
+
+},{"../OuterSubscriber":31,"../util/errorObject":225,"../util/subscribeToResult":238,"../util/tryCatch":240}],159:[function(require,module,exports){
+"use strict";
+var async_1 = require('../scheduler/async');
+var audit_1 = require('./audit');
+var timer_1 = require('../observable/timer');
+/**
+ * Ignores source values for `duration` milliseconds, then emits the most recent
+ * value from the source Observable, then repeats this process.
+ *
+ * <span class="informal">When it sees a source values, it ignores that plus
+ * the next ones for `duration` milliseconds, and then it emits the most recent
+ * value from the source.</span>
+ *
+ * <img src="./img/auditTime.png" width="100%">
+ *
+ * `auditTime` is similar to `throttleTime`, but emits the last value from the
+ * silenced time window, instead of the first value. `auditTime` emits the most
+ * recent value from the source Observable on the output Observable as soon as
+ * its internal timer becomes disabled, and ignores source values while the
+ * timer is enabled. Initially, the timer is disabled. As soon as the first
+ * source value arrives, the timer is enabled. After `duration` milliseconds (or
+ * the time unit determined internally by the optional `scheduler`) has passed,
+ * the timer is disabled, then the most recent source value is emitted on the
+ * output Observable, 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.auditTime(1000);
+ * result.subscribe(x => console.log(x));
+ *
+ * @see {@link audit}
+ * @see {@link debounceTime}
+ * @see {@link delay}
+ * @see {@link sampleTime}
+ * @see {@link throttleTime}
+ *
+ * @param {number} duration Time to wait before emitting the most recent source
+ * 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 rate-limiting behavior.
+ * @return {Observable<T>} An Observable that performs rate-limiting of
+ * emissions from the source Observable.
+ * @method auditTime
+ * @owner Observable
+ */
+function auditTime(duration, scheduler) {
+ if (scheduler === void 0) { scheduler = async_1.async; }
+ return audit_1.audit(function () { return timer_1.timer(duration, scheduler); });
+}
+exports.auditTime = auditTime;
+
+},{"../observable/timer":114,"../scheduler/async":213,"./audit":158}],160:[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');
+/**
+ * Buffers the source Observable values until `closingNotifier` emits.
+ *
+ * <span class="informal">Collects values from the past as an array, and emits
+ * that array only when another Observable emits.</span>
+ *
+ * <img src="./img/buffer.png" width="100%">
+ *
+ * Buffers the incoming Observable values until the given `closingNotifier`
+ * Observable emits a value, at which point it emits the buffer on the output
+ * Observable and starts a new buffer internally, awaiting the next time
+ * `closingNotifier` emits.
+ *
+ * @example <caption>On every click, emit array of most recent interval events</caption>
+ * var clicks = Rx.Observable.fromEvent(document, 'click');
+ * var interval = Rx.Observable.interval(1000);
+ * var buffered = interval.buffer(clicks);
+ * buffered.subscribe(x => console.log(x));
+ *
+ * @see {@link bufferCount}
+ * @see {@link bufferTime}
+ * @see {@link bufferToggle}
+ * @see {@link bufferWhen}
+ * @see {@link window}
+ *
+ * @param {Observable<any>} closingNotifier An Observable that signals the
+ * buffer to be emitted on the output Observable.
+ * @return {Observable<T[]>} An Observable of buffers, which are arrays of
+ * values.
+ * @method buffer
+ * @owner Observable
+ */
+function buffer(closingNotifier) {
+ return function bufferOperatorFunction(source) {
+ return source.lift(new BufferOperator(closingNotifier));
+ };
+}
+exports.buffer = buffer;
+var BufferOperator = (function () {
+ function BufferOperator(closingNotifier) {
+ this.closingNotifier = closingNotifier;
+ }
+ BufferOperator.prototype.call = function (subscriber, source) {
+ return source.subscribe(new BufferSubscriber(subscriber, this.closingNotifier));
+ };
+ return BufferOperator;
+}());
+/**
+ * We need this JSDoc comment for affecting ESDoc.
+ * @ignore
+ * @extends {Ignored}
+ */
+var BufferSubscriber = (function (_super) {
+ __extends(BufferSubscriber, _super);
+ function BufferSubscriber(destination, closingNotifier) {
+ _super.call(this, destination);
+ this.buffer = [];
+ this.add(subscribeToResult_1.subscribeToResult(this, closingNotifier));
+ }
+ BufferSubscriber.prototype._next = function (value) {
+ this.buffer.push(value);
+ };
+ BufferSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
+ var buffer = this.buffer;
+ this.buffer = [];
+ this.destination.next(buffer);
+ };
+ return BufferSubscriber;
+}(OuterSubscriber_1.OuterSubscriber));
+
+},{"../OuterSubscriber":31,"../util/subscribeToResult":238}],161:[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');
+/**
+ * Buffers the source Observable values until the size hits the maximum
+ * `bufferSize` given.
+ *
+ * <span class="informal">Collects values from the past as an array, and emits
+ * that array only when its size reaches `bufferSize`.</span>
+ *
+ * <img src="./img/bufferCount.png" width="100%">
+ *
+ * Buffers a number of values from the source Observable by `bufferSize` then
+ * emits the buffer and clears it, and starts a new buffer each
+ * `startBufferEvery` values. If `startBufferEvery` is not provided or is
+ * `null`, then new buffers are started immediately at the start of the source
+ * and when each buffer closes and is emitted.
+ *
+ * @example <caption>Emit the last two click events as an array</caption>
+ * var clicks = Rx.Observable.fromEvent(document, 'click');
+ * var buffered = clicks.bufferCount(2);
+ * buffered.subscribe(x => console.log(x));
+ *
+ * @example <caption>On every click, emit the last two click events as an array</caption>
+ * var clicks = Rx.Observable.fromEvent(document, 'click');
+ * var buffered = clicks.bufferCount(2, 1);
+ * buffered.subscribe(x => console.log(x));
+ *
+ * @see {@link buffer}
+ * @see {@link bufferTime}
+ * @see {@link bufferToggle}
+ * @see {@link bufferWhen}
+ * @see {@link pairwise}
+ * @see {@link windowCount}
+ *
+ * @param {number} bufferSize The maximum size of the buffer emitted.
+ * @param {number} [startBufferEvery] Interval at which to start a new buffer.
+ * For example if `startBufferEvery` is `2`, then a new buffer will be started
+ * on every other value from the source. A new buffer is started at the
+ * beginning of the source by default.
+ * @return {Observable<T[]>} An Observable of arrays of buffered values.
+ * @method bufferCount
+ * @owner Observable
+ */
+function bufferCount(bufferSize, startBufferEvery) {
+ if (startBufferEvery === void 0) { startBufferEvery = null; }
+ return function bufferCountOperatorFunction(source) {
+ return source.lift(new BufferCountOperator(bufferSize, startBufferEvery));
+ };
+}
+exports.bufferCount = bufferCount;
+var BufferCountOperator = (function () {
+ function BufferCountOperator(bufferSize, startBufferEvery) {
+ this.bufferSize = bufferSize;
+ this.startBufferEvery = startBufferEvery;
+ if (!startBufferEvery || bufferSize === startBufferEvery) {
+ this.subscriberClass = BufferCountSubscriber;
+ }
+ else {
+ this.subscriberClass = BufferSkipCountSubscriber;
+ }
+ }
+ BufferCountOperator.prototype.call = function (subscriber, source) {
+ return source.subscribe(new this.subscriberClass(subscriber, this.bufferSize, this.startBufferEvery));
+ };
+ return BufferCountOperator;
+}());
+/**
+ * We need this JSDoc comment for affecting ESDoc.
+ * @ignore
+ * @extends {Ignored}
+ */
+var BufferCountSubscriber = (function (_super) {
+ __extends(BufferCountSubscriber, _super);
+ function BufferCountSubscriber(destination, bufferSize) {
+ _super.call(this, destination);
+ this.bufferSize = bufferSize;
+ this.buffer = [];
+ }
+ BufferCountSubscriber.prototype._next = function (value) {
+ var buffer = this.buffer;
+ buffer.push(value);
+ if (buffer.length == this.bufferSize) {
+ this.destination.next(buffer);
+ this.buffer = [];
+ }
+ };
+ BufferCountSubscriber.prototype._complete = function () {
+ var buffer = this.buffer;
+ if (buffer.length > 0) {
+ this.destination.next(buffer);
+ }
+ _super.prototype._complete.call(this);
+ };
+ return BufferCountSubscriber;
+}(Subscriber_1.Subscriber));
+/**
+ * We need this JSDoc comment for affecting ESDoc.
+ * @ignore
+ * @extends {Ignored}
+ */
+var BufferSkipCountSubscriber = (function (_super) {
+ __extends(BufferSkipCountSubscriber, _super);
+ function BufferSkipCountSubscriber(destination, bufferSize, startBufferEvery) {
+ _super.call(this, destination);
+ this.bufferSize = bufferSize;
+ this.startBufferEvery = startBufferEvery;
+ this.buffers = [];
+ this.count = 0;
+ }
+ BufferSkipCountSubscriber.prototype._next = function (value) {
+ var _a = this, bufferSize = _a.bufferSize, startBufferEvery = _a.startBufferEvery, buffers = _a.buffers, count = _a.count;
+ this.count++;
+ if (count % startBufferEvery === 0) {
+ buffers.push([]);
+ }
+ for (var i = buffers.length; i--;) {
+ var buffer = buffers[i];
+ buffer.push(value);
+ if (buffer.length === bufferSize) {
+ buffers.splice(i, 1);
+ this.destination.next(buffer);
+ }
+ }
+ };
+ BufferSkipCountSubscriber.prototype._complete = function () {
+ var _a = this, buffers = _a.buffers, destination = _a.destination;
+ while (buffers.length > 0) {
+ var buffer = buffers.shift();
+ if (buffer.length > 0) {
+ destination.next(buffer);
+ }
+ }
+ _super.prototype._complete.call(this);
+ };
+ return BufferSkipCountSubscriber;
+}(Subscriber_1.Subscriber));
+
+},{"../Subscriber":36}],162:[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');
+var tryCatch_1 = require('../util/tryCatch');
+var errorObject_1 = require('../util/errorObject');
+var OuterSubscriber_1 = require('../OuterSubscriber');
+var subscribeToResult_1 = require('../util/subscribeToResult');
+/**
+ * Buffers the source Observable values, using a factory function of closing
+ * Observables to determine when to close, emit, and reset the buffer.
+ *
+ * <span class="informal">Collects values from the past as an array. When it
+ * starts collecting values, it calls a function that returns an Observable that
+ * tells when to close the buffer and restart collecting.</span>
+ *
+ * <img src="./img/bufferWhen.png" width="100%">
+ *
+ * Opens a buffer immediately, then closes the buffer when the observable
+ * returned by calling `closingSelector` function emits a value. When it closes
+ * the buffer, it immediately opens a new buffer and repeats the process.
+ *
+ * @example <caption>Emit an array of the last clicks every [1-5] random seconds</caption>
+ * var clicks = Rx.Observable.fromEvent(document, 'click');
+ * var buffered = clicks.bufferWhen(() =>
+ * Rx.Observable.interval(1000 + Math.random() * 4000)
+ * );
+ * buffered.subscribe(x => console.log(x));
+ *
+ * @see {@link buffer}
+ * @see {@link bufferCount}
+ * @see {@link bufferTime}
+ * @see {@link bufferToggle}
+ * @see {@link windowWhen}
+ *
+ * @param {function(): Observable} closingSelector A function that takes no
+ * arguments and returns an Observable that signals buffer closure.
+ * @return {Observable<T[]>} An observable of arrays of buffered values.
+ * @method bufferWhen
+ * @owner Observable
+ */
+function bufferWhen(closingSelector) {
+ return function (source) {
+ return source.lift(new BufferWhenOperator(closingSelector));
+ };
+}
+exports.bufferWhen = bufferWhen;
+var BufferWhenOperator = (function () {
+ function BufferWhenOperator(closingSelector) {
+ this.closingSelector = closingSelector;
+ }
+ BufferWhenOperator.prototype.call = function (subscriber, source) {
+ return source.subscribe(new BufferWhenSubscriber(subscriber, this.closingSelector));
+ };
+ return BufferWhenOperator;
+}());
+/**
+ * We need this JSDoc comment for affecting ESDoc.
+ * @ignore
+ * @extends {Ignored}
+ */
+var BufferWhenSubscriber = (function (_super) {
+ __extends(BufferWhenSubscriber, _super);
+ function BufferWhenSubscriber(destination, closingSelector) {
+ _super.call(this, destination);
+ this.closingSelector = closingSelector;
+ this.subscribing = false;
+ this.openBuffer();
+ }
+ BufferWhenSubscriber.prototype._next = function (value) {
+ this.buffer.push(value);
+ };
+ BufferWhenSubscriber.prototype._complete = function () {
+ var buffer = this.buffer;
+ if (buffer) {
+ this.destination.next(buffer);
+ }
+ _super.prototype._complete.call(this);
+ };
+ BufferWhenSubscriber.prototype._unsubscribe = function () {
+ this.buffer = null;
+ this.subscribing = false;
+ };
+ BufferWhenSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
+ this.openBuffer();
+ };
+ BufferWhenSubscriber.prototype.notifyComplete = function () {
+ if (this.subscribing) {
+ this.complete();
+ }
+ else {
+ this.openBuffer();
+ }
+ };
+ BufferWhenSubscriber.prototype.openBuffer = function () {
+ var closingSubscription = this.closingSubscription;
+ if (closingSubscription) {
+ this.remove(closingSubscription);
+ closingSubscription.unsubscribe();
+ }
+ var buffer = this.buffer;
+ if (this.buffer) {
+ this.destination.next(buffer);
+ }
+ this.buffer = [];
+ var closingNotifier = tryCatch_1.tryCatch(this.closingSelector)();
+ if (closingNotifier === errorObject_1.errorObject) {
+ this.error(errorObject_1.errorObject.e);
+ }
+ else {
+ closingSubscription = new Subscription_1.Subscription();
+ this.closingSubscription = closingSubscription;
+ this.add(closingSubscription);
+ this.subscribing = true;
+ closingSubscription.add(subscribeToResult_1.subscribeToResult(this, closingNotifier));
+ this.subscribing = false;
+ }
+ };
+ return BufferWhenSubscriber;
+}(OuterSubscriber_1.OuterSubscriber));
+
+},{"../OuterSubscriber":31,"../Subscription":37,"../util/errorObject":225,"../util/subscribeToResult":238,"../util/tryCatch":240}],163:[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');
+/**
+ * Catches errors on the observable to be handled by returning a new observable or throwing an error.
+ *
+ * <img src="./img/catch.png" width="100%">
+ *
+ * @example <caption>Continues with a different Observable when there's an error</caption>
+ *
+ * Observable.of(1, 2, 3, 4, 5)
+ * .map(n => {
+ * if (n == 4) {
+ * throw 'four!';
+ * }
+ * return n;
+ * })
+ * .catch(err => Observable.of('I', 'II', 'III', 'IV', 'V'))
+ * .subscribe(x => console.log(x));
+ * // 1, 2, 3, I, II, III, IV, V
+ *
+ * @example <caption>Retries the caught source Observable again in case of error, similar to retry() operator</caption>
+ *
+ * Observable.of(1, 2, 3, 4, 5)
+ * .map(n => {
+ * if (n === 4) {
+ * throw 'four!';
+ * }
+ * return n;
+ * })
+ * .catch((err, caught) => caught)
+ * .take(30)
+ * .subscribe(x => console.log(x));
+ * // 1, 2, 3, 1, 2, 3, ...
+ *
+ * @example <caption>Throws a new error when the source Observable throws an error</caption>
+ *
+ * Observable.of(1, 2, 3, 4, 5)
+ * .map(n => {
+ * if (n == 4) {
+ * throw 'four!';
+ * }
+ * return n;
+ * })
+ * .catch(err => {
+ * throw 'error in source. Details: ' + err;
+ * })
+ * .subscribe(
+ * x => console.log(x),
+ * err => console.log(err)
+ * );
+ * // 1, 2, 3, error in source. Details: four!
+ *
+ * @param {function} selector a function that takes as arguments `err`, which is the error, and `caught`, which
+ * is the source observable, in case you'd like to "retry" that observable by returning it again. Whatever observable
+ * is returned by the `selector` will be used to continue the observable chain.
+ * @return {Observable} An observable that originates from either the source or the observable returned by the
+ * catch `selector` function.
+ * @name catchError
+ */
+function catchError(selector) {
+ return function catchErrorOperatorFunction(source) {
+ var operator = new CatchOperator(selector);
+ var caught = source.lift(operator);
+ return (operator.caught = caught);
+ };
+}
+exports.catchError = catchError;
+var CatchOperator = (function () {
+ function CatchOperator(selector) {
+ this.selector = selector;
+ }
+ CatchOperator.prototype.call = function (subscriber, source) {
+ return source.subscribe(new CatchSubscriber(subscriber, this.selector, this.caught));
+ };
+ return CatchOperator;
+}());
+/**
+ * We need this JSDoc comment for affecting ESDoc.
+ * @ignore
+ * @extends {Ignored}
+ */
+var CatchSubscriber = (function (_super) {
+ __extends(CatchSubscriber, _super);
+ function CatchSubscriber(destination, selector, caught) {
+ _super.call(this, destination);
+ this.selector = selector;
+ this.caught = caught;
+ }
+ // NOTE: overriding `error` instead of `_error` because we don't want
+ // to have this flag this subscriber as `isStopped`. We can mimic the
+ // behavior of the RetrySubscriber (from the `retry` operator), where
+ // we unsubscribe from our source chain, reset our Subscriber flags,
+ // then subscribe to the selector result.
+ CatchSubscriber.prototype.error = function (err) {
+ if (!this.isStopped) {
+ var result = void 0;
+ try {
+ result = this.selector(err, this.caught);
+ }
+ catch (err2) {
+ _super.prototype.error.call(this, err2);
+ return;
+ }
+ this._unsubscribeAndRecycle();
+ this.add(subscribeToResult_1.subscribeToResult(this, result));
+ }
+ };
+ return CatchSubscriber;
+}(OuterSubscriber_1.OuterSubscriber));
+
+},{"../OuterSubscriber":31,"../util/subscribeToResult":238}],164:[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 OuterSubscriber_1 = require('../OuterSubscriber');
+var subscribeToResult_1 = require('../util/subscribeToResult');
+var none = {};
+/* tslint:enable:max-line-length */
+/**
+ * Combines multiple Observables to create an Observable whose values are
+ * calculated from the latest values of each of its input Observables.
+ *
+ * <span class="informal">Whenever any input Observable emits a value, it
+ * computes a formula using the latest values from all the inputs, then emits
+ * the output of that formula.</span>
+ *
+ * <img src="./img/combineLatest.png" width="100%">
+ *
+ * `combineLatest` combines the values from this Observable with values from
+ * Observables passed as arguments. This is done by subscribing to each
+ * Observable, in order, and collecting an array of each of the most recent
+ * values any time any of the input Observables emits, then either taking that
+ * array and passing it as arguments to an optional `project` function and
+ * emitting the return value of that, or just emitting the array of recent
+ * values directly if there is no `project` function.
+ *
+ * @example <caption>Dynamically calculate the Body-Mass Index from an Observable of weight and one for height</caption>
+ * var weight = Rx.Observable.of(70, 72, 76, 79, 75);
+ * var height = Rx.Observable.of(1.76, 1.77, 1.78);
+ * var bmi = weight.combineLatest(height, (w, h) => w / (h * h));
+ * bmi.subscribe(x => console.log('BMI is ' + x));
+ *
+ * // With output to console:
+ * // BMI is 24.212293388429753
+ * // BMI is 23.93948099205209
+ * // BMI is 23.671253629592222
+ *
+ * @see {@link combineAll}
+ * @see {@link merge}
+ * @see {@link withLatestFrom}
+ *
+ * @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] An optional function to project the values from
+ * the combined latest values into a new value 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 combineLatest
+ * @owner Observable
+ */
+function combineLatest() {
+ var observables = [];
+ for (var _i = 0; _i < arguments.length; _i++) {
+ observables[_i - 0] = arguments[_i];
+ }
+ var project = null;
+ if (typeof observables[observables.length - 1] === 'function') {
+ project = observables.pop();
+ }
+ // if the first and only other argument besides the resultSelector is an array
+ // assume it's been called with `combineLatest([obs1, obs2, obs3], project)`
+ if (observables.length === 1 && isArray_1.isArray(observables[0])) {
+ observables = observables[0].slice();
+ }
+ return function (source) { return source.lift.call(new ArrayObservable_1.ArrayObservable([source].concat(observables)), new CombineLatestOperator(project)); };
+}
+exports.combineLatest = combineLatest;
+var CombineLatestOperator = (function () {
+ function CombineLatestOperator(project) {
+ this.project = project;
+ }
+ CombineLatestOperator.prototype.call = function (subscriber, source) {
+ return source.subscribe(new CombineLatestSubscriber(subscriber, this.project));
+ };
+ return CombineLatestOperator;
+}());
+exports.CombineLatestOperator = CombineLatestOperator;
+/**
+ * We need this JSDoc comment for affecting ESDoc.
+ * @ignore
+ * @extends {Ignored}
+ */
+var CombineLatestSubscriber = (function (_super) {
+ __extends(CombineLatestSubscriber, _super);
+ function CombineLatestSubscriber(destination, project) {
+ _super.call(this, destination);
+ this.project = project;
+ this.active = 0;
+ this.values = [];
+ this.observables = [];
+ }
+ CombineLatestSubscriber.prototype._next = function (observable) {
+ this.values.push(none);
+ this.observables.push(observable);
+ };
+ CombineLatestSubscriber.prototype._complete = function () {
+ var observables = this.observables;
+ var len = observables.length;
+ if (len === 0) {
+ this.destination.complete();
+ }
+ else {
+ this.active = len;
+ this.toRespond = len;
+ for (var i = 0; i < len; i++) {
+ var observable = observables[i];
+ this.add(subscribeToResult_1.subscribeToResult(this, observable, observable, i));
+ }
+ }
+ };
+ CombineLatestSubscriber.prototype.notifyComplete = function (unused) {
+ if ((this.active -= 1) === 0) {
+ this.destination.complete();
+ }
+ };
+ CombineLatestSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
+ var values = this.values;
+ var oldVal = values[outerIndex];
+ var toRespond = !this.toRespond
+ ? 0
+ : oldVal === none ? --this.toRespond : this.toRespond;
+ values[outerIndex] = innerValue;
+ if (toRespond === 0) {
+ if (this.project) {
+ this._tryProject(values);
+ }
+ else {
+ this.destination.next(values.slice());
+ }
+ }
+ };
+ CombineLatestSubscriber.prototype._tryProject = function (values) {
+ var result;
+ try {
+ result = this.project.apply(this, values);
+ }
+ catch (err) {
+ this.destination.error(err);
+ return;
+ }
+ this.destination.next(result);
+ };
+ return CombineLatestSubscriber;
+}(OuterSubscriber_1.OuterSubscriber));
+exports.CombineLatestSubscriber = CombineLatestSubscriber;
+
+},{"../OuterSubscriber":31,"../observable/ArrayObservable":93,"../util/isArray":227,"../util/subscribeToResult":238}],165:[function(require,module,exports){
+"use strict";
+var concat_1 = require('../observable/concat');
+/* tslint:enable:max-line-length */
+/**
+ * Creates an output Observable which sequentially emits all values from every
+ * given input Observable after the current Observable.
+ *
+ * <span class="informal">Concatenates multiple Observables together by
+ * sequentially emitting their values, one Observable after the other.</span>
+ *
+ * <img src="./img/concat.png" width="100%">
+ *
+ * Joins this Observable with multiple other Observables by subscribing to them
+ * one at a time, starting with the source, and merging their results into the
+ * output Observable. Will wait for each Observable to complete before moving
+ * on to the next.
+ *
+ * @example <caption>Concatenate a timer counting from 0 to 3 with a synchronous sequence from 1 to 10</caption>
+ * var timer = Rx.Observable.interval(1000).take(4);
+ * var sequence = Rx.Observable.range(1, 10);
+ * var result = timer.concat(sequence);
+ * result.subscribe(x => console.log(x));
+ *
+ * // results in:
+ * // 1000ms-> 0 -1000ms-> 1 -1000ms-> 2 -1000ms-> 3 -immediate-> 1 ... 10
+ *
+ * @example <caption>Concatenate 3 Observables</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 result = timer1.concat(timer2, timer3);
+ * result.subscribe(x => console.log(x));
+ *
+ * // results in the following:
+ * // (Prints to console sequentially)
+ * // -1000ms-> 0 -1000ms-> 1 -1000ms-> ... 9
+ * // -2000ms-> 0 -2000ms-> 1 -2000ms-> ... 5
+ * // -500ms-> 0 -500ms-> 1 -500ms-> ... 9
+ *
+ * @see {@link concatAll}
+ * @see {@link concatMap}
+ * @see {@link concatMapTo}
+ *
+ * @param {ObservableInput} other An input Observable to concatenate after the source
+ * Observable. More than one input Observables may be given as argument.
+ * @param {Scheduler} [scheduler=null] An optional IScheduler to schedule each
+ * Observable subscription on.
+ * @return {Observable} All values of each passed Observable merged into a
+ * single Observable, in order, in serial fashion.
+ * @method concat
+ * @owner Observable
+ */
+function concat() {
+ var observables = [];
+ for (var _i = 0; _i < arguments.length; _i++) {
+ observables[_i - 0] = arguments[_i];
+ }
+ return function (source) { return source.lift.call(concat_1.concat.apply(void 0, [source].concat(observables))); };
+}
+exports.concat = concat;
+
+},{"../observable/concat":105}],166:[function(require,module,exports){
+"use strict";
+var mergeAll_1 = require('./mergeAll');
+/**
+ * Converts a higher-order Observable into a first-order Observable by
+ * concatenating the inner Observables in order.
+ *
+ * <span class="informal">Flattens an Observable-of-Observables by putting one
+ * inner Observable after the other.</span>
+ *
+ * <img src="./img/concatAll.png" width="100%">
+ *
+ * Joins every Observable emitted by the source (a higher-order Observable), in
+ * a serial fashion. It subscribes to each inner Observable only after the
+ * previous inner Observable has completed, and merges all of their values into
+ * the returned observable.
+ *
+ * __Warning:__ If the source Observable emits Observables quickly and
+ * endlessly, and the inner Observables it emits generally complete slower than
+ * the source emits, you can run into memory issues as the incoming Observables
+ * collect in an unbounded buffer.
+ *
+ * Note: `concatAll` is equivalent to `mergeAll` with concurrency parameter set
+ * to `1`.
+ *
+ * @example <caption>For each click event, tick every second from 0 to 3, with no concurrency</caption>
+ * var clicks = Rx.Observable.fromEvent(document, 'click');
+ * var higherOrder = clicks.map(ev => Rx.Observable.interval(1000).take(4));
+ * var firstOrder = higherOrder.concatAll();
+ * firstOrder.subscribe(x => console.log(x));
+ *
+ * // Results in the following:
+ * // (results are not concurrent)
+ * // For every click on the "document" it will emit values 0 to 3 spaced
+ * // on a 1000ms interval
+ * // one click = 1000ms-> 0 -1000ms-> 1 -1000ms-> 2 -1000ms-> 3
+ *
+ * @see {@link combineAll}
+ * @see {@link concat}
+ * @see {@link concatMap}
+ * @see {@link concatMapTo}
+ * @see {@link exhaust}
+ * @see {@link mergeAll}
+ * @see {@link switch}
+ * @see {@link zipAll}
+ *
+ * @return {Observable} An Observable emitting values from all the inner
+ * Observables concatenated.
+ * @method concatAll
+ * @owner Observable
+ */
+function concatAll() {
+ return mergeAll_1.mergeAll(1);
+}
+exports.concatAll = concatAll;
+
+},{"./mergeAll":179}],167:[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');
+/**
+ * Emits a value from the source Observable only after a particular time span
+ * has passed without another source emission.
+ *
+ * <span class="informal">It's like {@link delay}, but passes only the most
+ * recent value from each burst of emissions.</span>
+ *
+ * <img src="./img/debounceTime.png" width="100%">
+ *
+ * `debounceTime` delays values emitted by the source Observable, but drops
+ * previous pending delayed emissions if a new value arrives on the source
+ * Observable. This operator keeps track of the most recent value from the
+ * source Observable, and emits that only when `dueTime` enough time has passed
+ * without any other value appearing on the source Observable. If a new value
+ * appears before `dueTime` silence occurs, the previous value will be dropped
+ * and will not be emitted on the output Observable.
+ *
+ * This is a rate-limiting operator, because it is impossible for more than one
+ * value to be emitted in any time window of duration `dueTime`, but it is also
+ * a delay-like operator since output emissions do not occur at the same time as
+ * they did on the source Observable. Optionally takes a {@link IScheduler} for
+ * managing timers.
+ *
+ * @example <caption>Emit the most recent click after a burst of clicks</caption>
+ * var clicks = Rx.Observable.fromEvent(document, 'click');
+ * var result = clicks.debounceTime(1000);
+ * result.subscribe(x => console.log(x));
+ *
+ * @see {@link auditTime}
+ * @see {@link debounce}
+ * @see {@link delay}
+ * @see {@link sampleTime}
+ * @see {@link throttleTime}
+ *
+ * @param {number} dueTime The timeout duration in milliseconds (or the time
+ * unit determined internally by the optional `scheduler`) for the window of
+ * time required to wait for emission silence before emitting the most recent
+ * source value.
+ * @param {Scheduler} [scheduler=async] The {@link IScheduler} to use for
+ * managing the timers that handle the timeout for each value.
+ * @return {Observable} An Observable that delays the emissions of the source
+ * Observable by the specified `dueTime`, and may drop some values if they occur
+ * too frequently.
+ * @method debounceTime
+ * @owner Observable
+ */
+function debounceTime(dueTime, scheduler) {
+ if (scheduler === void 0) { scheduler = async_1.async; }
+ return function (source) { return source.lift(new DebounceTimeOperator(dueTime, scheduler)); };
+}
+exports.debounceTime = debounceTime;
+var DebounceTimeOperator = (function () {
+ function DebounceTimeOperator(dueTime, scheduler) {
+ this.dueTime = dueTime;
+ this.scheduler = scheduler;
+ }
+ DebounceTimeOperator.prototype.call = function (subscriber, source) {
+ return source.subscribe(new DebounceTimeSubscriber(subscriber, this.dueTime, this.scheduler));
+ };
+ return DebounceTimeOperator;
+}());
+/**
+ * We need this JSDoc comment for affecting ESDoc.
+ * @ignore
+ * @extends {Ignored}
+ */
+var DebounceTimeSubscriber = (function (_super) {
+ __extends(DebounceTimeSubscriber, _super);
+ function DebounceTimeSubscriber(destination, dueTime, scheduler) {
+ _super.call(this, destination);
+ this.dueTime = dueTime;
+ this.scheduler = scheduler;
+ this.debouncedSubscription = null;
+ this.lastValue = null;
+ this.hasValue = false;
+ }
+ DebounceTimeSubscriber.prototype._next = function (value) {
+ this.clearDebounce();
+ this.lastValue = value;
+ this.hasValue = true;
+ this.add(this.debouncedSubscription = this.scheduler.schedule(dispatchNext, this.dueTime, this));
+ };
+ DebounceTimeSubscriber.prototype._complete = function () {
+ this.debouncedNext();
+ this.destination.complete();
+ };
+ DebounceTimeSubscriber.prototype.debouncedNext = function () {
+ this.clearDebounce();
+ if (this.hasValue) {
+ this.destination.next(this.lastValue);
+ this.lastValue = null;
+ this.hasValue = false;
+ }
+ };
+ DebounceTimeSubscriber.prototype.clearDebounce = function () {
+ var debouncedSubscription = this.debouncedSubscription;
+ if (debouncedSubscription !== null) {
+ this.remove(debouncedSubscription);
+ debouncedSubscription.unsubscribe();
+ this.debouncedSubscription = null;
+ }
+ };
+ return DebounceTimeSubscriber;
+}(Subscriber_1.Subscriber));
+function dispatchNext(subscriber) {
+ subscriber.debouncedNext();
+}
+
+},{"../Subscriber":36,"../scheduler/async":213}],168:[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 */
+/**
+ * Emits a given value if the source Observable completes without emitting any
+ * `next` value, otherwise mirrors the source Observable.
+ *
+ * <span class="informal">If the source Observable turns out to be empty, then
+ * this operator will emit a default value.</span>
+ *
+ * <img src="./img/defaultIfEmpty.png" width="100%">
+ *
+ * `defaultIfEmpty` emits the values emitted by the source Observable or a
+ * specified default value if the source Observable is empty (completes without
+ * having emitted any `next` value).
+ *
+ * @example <caption>If no clicks happen in 5 seconds, then emit "no clicks"</caption>
+ * var clicks = Rx.Observable.fromEvent(document, 'click');
+ * var clicksBeforeFive = clicks.takeUntil(Rx.Observable.interval(5000));
+ * var result = clicksBeforeFive.defaultIfEmpty('no clicks');
+ * result.subscribe(x => console.log(x));
+ *
+ * @see {@link empty}
+ * @see {@link last}
+ *
+ * @param {any} [defaultValue=null] The default value used if the source
+ * Observable is empty.
+ * @return {Observable} An Observable that emits either the specified
+ * `defaultValue` if the source Observable emits no items, or the values emitted
+ * by the source Observable.
+ * @method defaultIfEmpty
+ * @owner Observable
+ */
+function defaultIfEmpty(defaultValue) {
+ if (defaultValue === void 0) { defaultValue = null; }
+ return function (source) { return source.lift(new DefaultIfEmptyOperator(defaultValue)); };
+}
+exports.defaultIfEmpty = defaultIfEmpty;
+var DefaultIfEmptyOperator = (function () {
+ function DefaultIfEmptyOperator(defaultValue) {
+ this.defaultValue = defaultValue;
+ }
+ DefaultIfEmptyOperator.prototype.call = function (subscriber, source) {
+ return source.subscribe(new DefaultIfEmptySubscriber(subscriber, this.defaultValue));
+ };
+ return DefaultIfEmptyOperator;
+}());
+/**
+ * We need this JSDoc comment for affecting ESDoc.
+ * @ignore
+ * @extends {Ignored}
+ */
+var DefaultIfEmptySubscriber = (function (_super) {
+ __extends(DefaultIfEmptySubscriber, _super);
+ function DefaultIfEmptySubscriber(destination, defaultValue) {
+ _super.call(this, destination);
+ this.defaultValue = defaultValue;
+ this.isEmpty = true;
+ }
+ DefaultIfEmptySubscriber.prototype._next = function (value) {
+ this.isEmpty = false;
+ this.destination.next(value);
+ };
+ DefaultIfEmptySubscriber.prototype._complete = function () {
+ if (this.isEmpty) {
+ this.destination.next(this.defaultValue);
+ }
+ this.destination.complete();
+ };
+ return DefaultIfEmptySubscriber;
+}(Subscriber_1.Subscriber));
+
+},{"../Subscriber":36}],169:[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 Notification_1 = require('../Notification');
+/**
+ * Delays the emission of items from the source Observable by a given timeout or
+ * until a given Date.
+ *
+ * <span class="informal">Time shifts each item by some specified amount of
+ * milliseconds.</span>
+ *
+ * <img src="./img/delay.png" width="100%">
+ *
+ * If the delay argument is a Number, this operator time shifts the source
+ * Observable by that amount of time expressed in milliseconds. The relative
+ * time intervals between the values are preserved.
+ *
+ * If the delay argument is a Date, this operator time shifts the start of the
+ * Observable execution until the given date occurs.
+ *
+ * @example <caption>Delay each click by one second</caption>
+ * var clicks = Rx.Observable.fromEvent(document, 'click');
+ * var delayedClicks = clicks.delay(1000); // each click emitted after 1 second
+ * delayedClicks.subscribe(x => console.log(x));
+ *
+ * @example <caption>Delay all clicks until a future date happens</caption>
+ * var clicks = Rx.Observable.fromEvent(document, 'click');
+ * var date = new Date('March 15, 2050 12:00:00'); // in the future
+ * var delayedClicks = clicks.delay(date); // click emitted only after that date
+ * delayedClicks.subscribe(x => console.log(x));
+ *
+ * @see {@link debounceTime}
+ * @see {@link delayWhen}
+ *
+ * @param {number|Date} delay The delay duration in milliseconds (a `number`) or
+ * a `Date` until which the emission of the source items is delayed.
+ * @param {Scheduler} [scheduler=async] The IScheduler to use for
+ * managing the timers that handle the time-shift for each item.
+ * @return {Observable} An Observable that delays the emissions of the source
+ * Observable by the specified timeout or Date.
+ * @method delay
+ * @owner Observable
+ */
+function delay(delay, scheduler) {
+ if (scheduler === void 0) { scheduler = async_1.async; }
+ var absoluteDelay = isDate_1.isDate(delay);
+ var delayFor = absoluteDelay ? (+delay - scheduler.now()) : Math.abs(delay);
+ return function (source) { return source.lift(new DelayOperator(delayFor, scheduler)); };
+}
+exports.delay = delay;
+var DelayOperator = (function () {
+ function DelayOperator(delay, scheduler) {
+ this.delay = delay;
+ this.scheduler = scheduler;
+ }
+ DelayOperator.prototype.call = function (subscriber, source) {
+ return source.subscribe(new DelaySubscriber(subscriber, this.delay, this.scheduler));
+ };
+ return DelayOperator;
+}());
+/**
+ * We need this JSDoc comment for affecting ESDoc.
+ * @ignore
+ * @extends {Ignored}
+ */
+var DelaySubscriber = (function (_super) {
+ __extends(DelaySubscriber, _super);
+ function DelaySubscriber(destination, delay, scheduler) {
+ _super.call(this, destination);
+ this.delay = delay;
+ this.scheduler = scheduler;
+ this.queue = [];
+ this.active = false;
+ this.errored = false;
+ }
+ DelaySubscriber.dispatch = function (state) {
+ var source = state.source;
+ var queue = source.queue;
+ var scheduler = state.scheduler;
+ var destination = state.destination;
+ while (queue.length > 0 && (queue[0].time - scheduler.now()) <= 0) {
+ queue.shift().notification.observe(destination);
+ }
+ if (queue.length > 0) {
+ var delay_1 = Math.max(0, queue[0].time - scheduler.now());
+ this.schedule(state, delay_1);
+ }
+ else {
+ source.active = false;
+ }
+ };
+ DelaySubscriber.prototype._schedule = function (scheduler) {
+ this.active = true;
+ this.add(scheduler.schedule(DelaySubscriber.dispatch, this.delay, {
+ source: this, destination: this.destination, scheduler: scheduler
+ }));
+ };
+ DelaySubscriber.prototype.scheduleNotification = function (notification) {
+ if (this.errored === true) {
+ return;
+ }
+ var scheduler = this.scheduler;
+ var message = new DelayMessage(scheduler.now() + this.delay, notification);
+ this.queue.push(message);
+ if (this.active === false) {
+ this._schedule(scheduler);
+ }
+ };
+ 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;