UNPKG

@reactivex/rxjs

Version:

Reactive Extensions for modern JavaScript

1,200 lines (1,186 loc) 559 kB
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}(g.Rx || (g.Rx = {})).KitchenSink = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[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 Subject_1 = require('./Subject'); /** * @class AsyncSubject<T> */ var AsyncSubject = (function (_super) { __extends(AsyncSubject, _super); function AsyncSubject() { _super.apply(this, arguments); this.value = null; this.hasNext = false; } AsyncSubject.prototype._subscribe = function (subscriber) { if (this.hasCompleted && this.hasNext) { subscriber.next(this.value); } return _super.prototype._subscribe.call(this, subscriber); }; AsyncSubject.prototype._next = function (value) { this.value = value; this.hasNext = true; }; AsyncSubject.prototype._complete = function () { var index = -1; var observers = this.observers; var len = observers.length; // optimization to block our SubjectSubscriptions from // splicing themselves out of the observers list one by one. this.isUnsubscribed = true; if (this.hasNext) { while (++index < len) { var o = observers[index]; o.next(this.value); o.complete(); } } else { while (++index < len) { observers[index].complete(); } } this.isUnsubscribed = false; this.unsubscribe(); }; return AsyncSubject; }(Subject_1.Subject)); exports.AsyncSubject = AsyncSubject; },{"./Subject":12}],2:[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 Subject_1 = require('./Subject'); var throwError_1 = require('./util/throwError'); var ObjectUnsubscribedError_1 = require('./util/ObjectUnsubscribedError'); /** * @class BehaviorSubject<T> */ var BehaviorSubject = (function (_super) { __extends(BehaviorSubject, _super); function BehaviorSubject(_value) { _super.call(this); this._value = _value; } BehaviorSubject.prototype.getValue = function () { if (this.hasErrored) { throwError_1.throwError(this.errorValue); } else if (this.isUnsubscribed) { throwError_1.throwError(new ObjectUnsubscribedError_1.ObjectUnsubscribedError()); } else { return this._value; } }; Object.defineProperty(BehaviorSubject.prototype, "value", { get: function () { return this.getValue(); }, enumerable: true, configurable: true }); BehaviorSubject.prototype._subscribe = function (subscriber) { var subscription = _super.prototype._subscribe.call(this, subscriber); if (subscription && !subscription.isUnsubscribed) { subscriber.next(this._value); } return subscription; }; BehaviorSubject.prototype._next = function (value) { _super.prototype._next.call(this, this._value = value); }; BehaviorSubject.prototype._error = function (err) { this.hasErrored = true; _super.prototype._error.call(this, this.errorValue = err); }; return BehaviorSubject; }(Subject_1.Subject)); exports.BehaviorSubject = BehaviorSubject; },{"./Subject":12,"./util/ObjectUnsubscribedError":302,"./util/throwError":317}],3:[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'); /** * We need this JSDoc comment for affecting ESDoc. * @ignore * @extends {Ignored} */ var InnerSubscriber = (function (_super) { __extends(InnerSubscriber, _super); function InnerSubscriber(parent, outerValue, outerIndex) { _super.call(this); this.parent = parent; this.outerValue = outerValue; this.outerIndex = outerIndex; this.index = 0; } InnerSubscriber.prototype._next = function (value) { this.parent.notifyNext(this.outerValue, value, this.outerIndex, this.index++, this); }; InnerSubscriber.prototype._error = function (error) { this.parent.notifyError(error, this); this.unsubscribe(); }; InnerSubscriber.prototype._complete = function () { this.parent.notifyComplete(this); this.unsubscribe(); }; return InnerSubscriber; }(Subscriber_1.Subscriber)); exports.InnerSubscriber = InnerSubscriber; },{"./Subscriber":14}],4:[function(require,module,exports){ "use strict"; var Observable_1 = require('./Observable'); /** * Represents a push-based event or value that an {@link Observable} can emit. * This class is particularly useful for operators that manage notifications, * like {@link materialize}, {@link dematerialize}, {@link observeOn}, and * others. Besides wrapping the actual delivered value, it also annotates it * with metadata of, for instance, what type of push message it is (`next`, * `error`, or `complete`). * * @see {@link materialize} * @see {@link dematerialize} * @see {@link observeOn} * * @class Notification<T> */ var Notification = (function () { function Notification(kind, value, exception) { this.kind = kind; this.value = value; this.exception = exception; this.hasValue = kind === 'N'; } /** * Delivers to the given `observer` the value wrapped by this Notification. * @param {Observer} observer * @return */ Notification.prototype.observe = function (observer) { switch (this.kind) { case 'N': return observer.next && observer.next(this.value); case 'E': return observer.error && observer.error(this.exception); case 'C': return observer.complete && observer.complete(); } }; /** * Given some {@link Observer} callbacks, deliver the value represented by the * current Notification to the correctly corresponding callback. * @param {function(value: T): void} next An Observer `next` callback. * @param {function(err: any): void} [error] An Observer `error` callback. * @param {function(): void} [complete] An Observer `complete` callback. * @return {any} */ Notification.prototype.do = function (next, error, complete) { var kind = this.kind; switch (kind) { case 'N': return next && next(this.value); case 'E': return error && error(this.exception); case 'C': return complete && complete(); } }; /** * Takes an Observer or its individual callback functions, and calls `observe` * or `do` methods accordingly. * @param {Observer|function(value: T): void} nextOrObserver An Observer or * the `next` callback. * @param {function(err: any): void} [error] An Observer `error` callback. * @param {function(): void} [complete] An Observer `complete` callback. * @return {any} */ Notification.prototype.accept = function (nextOrObserver, error, complete) { if (nextOrObserver && typeof nextOrObserver.next === 'function') { return this.observe(nextOrObserver); } else { return this.do(nextOrObserver, error, complete); } }; /** * Returns a simple Observable that just delivers the notification represented * by this Notification instance. * @return {any} */ Notification.prototype.toObservable = function () { var kind = this.kind; switch (kind) { case 'N': return Observable_1.Observable.of(this.value); case 'E': return Observable_1.Observable.throw(this.exception); case 'C': return Observable_1.Observable.empty(); } }; /** * A shortcut to create a Notification instance of the type `next` from a * given value. * @param {T} value The `next` value. * @return {Notification<T>} The "next" Notification representing the * argument. */ Notification.createNext = function (value) { if (typeof value !== 'undefined') { return new Notification('N', value); } return this.undefinedValueNotification; }; /** * A shortcut to create a Notification instance of the type `error` from a * given error. * @param {any} [err] The `error` exception. * @return {Notification<T>} The "error" Notification representing the * argument. */ Notification.createError = function (err) { return new Notification('E', undefined, err); }; /** * A shortcut to create a Notification instance of the type `complete`. * @return {Notification<any>} The valueless "complete" Notification. */ Notification.createComplete = function () { return this.completeNotification; }; Notification.completeNotification = new Notification('C'); Notification.undefinedValueNotification = new Notification('N', undefined); return Notification; }()); exports.Notification = Notification; },{"./Observable":5}],5:[function(require,module,exports){ "use strict"; var root_1 = require('./util/root'); var observable_1 = require('./symbol/observable'); var toSubscriber_1 = require('./util/toSubscriber'); /** * A representation of any set of values over any amount of time. This the most basic building block * of RxJS. * * @class Observable<T> */ var Observable = (function () { /** * @constructor * @param {Function} subscribe the function that is called when the Observable is * initially subscribed to. This function is given a Subscriber, to which new values * can be `next`ed, or an `error` method can be called to raise an error, or * `complete` can be called to notify of a successful completion. */ function Observable(subscribe) { this._isScalar = false; if (subscribe) { this._subscribe = subscribe; } } /** * Creates a new Observable, with this Observable as the source, and the passed * operator defined as the new observable's operator. * @method lift * @param {Operator} operator the operator defining the operation to take on the observable * @return {Observable} a new observable with the Operator applied */ Observable.prototype.lift = function (operator) { var observable = new Observable(); observable.source = this; observable.operator = operator; return observable; }; /** * Registers handlers for handling emitted values, error and completions from the observable, and * executes the observable's subscriber function, which will take action to set up the underlying data stream * @method subscribe * @param {PartialObserver|Function} observerOrNext (optional) either an observer defining all functions to be called, * or the first of three possible handlers, which is the handler for each value emitted from the observable. * @param {Function} error (optional) a handler for a terminal event resulting from an error. If no error handler is provided, * the error will be thrown as unhandled * @param {Function} complete (optional) a handler for a terminal event resulting from successful completion. * @return {ISubscription} a subscription reference to the registered handlers */ Observable.prototype.subscribe = function (observerOrNext, error, complete) { var operator = this.operator; var sink = toSubscriber_1.toSubscriber(observerOrNext, error, complete); sink.add(operator ? operator.call(sink, this) : this._subscribe(sink)); if (sink.syncErrorThrowable) { sink.syncErrorThrowable = false; if (sink.syncErrorThrown) { throw sink.syncErrorValue; } } return sink; }; /** * @method forEach * @param {Function} next a handler for each value emitted by the observable * @param {PromiseConstructor} [PromiseCtor] a constructor function used to instantiate the Promise * @return {Promise} a promise that either resolves on observable completion or * rejects with the handled error */ Observable.prototype.forEach = function (next, PromiseCtor) { var _this = this; if (!PromiseCtor) { if (root_1.root.Rx && root_1.root.Rx.config && root_1.root.Rx.config.Promise) { PromiseCtor = root_1.root.Rx.config.Promise; } else if (root_1.root.Promise) { PromiseCtor = root_1.root.Promise; } } if (!PromiseCtor) { throw new Error('no Promise impl found'); } return new PromiseCtor(function (resolve, reject) { var subscription = _this.subscribe(function (value) { if (subscription) { // if there is a subscription, then we can surmise // the next handling is asynchronous. Any errors thrown // need to be rejected explicitly and unsubscribe must be // called manually try { next(value); } catch (err) { reject(err); subscription.unsubscribe(); } } else { // if there is NO subscription, then we're getting a nexted // value synchronously during subscription. We can just call it. // If it errors, Observable's `subscribe` imple will ensure the // unsubscription logic is called, then synchronously rethrow the error. // After that, Promise will trap the error and send it // down the rejection path. next(value); } }, reject, resolve); }); }; Observable.prototype._subscribe = function (subscriber) { return this.source.subscribe(subscriber); }; /** * An interop point defined by the es7-observable spec https://github.com/zenparsing/es-observable * @method Symbol.observable * @return {Observable} this instance of the observable */ Observable.prototype[observable_1.$$observable] = function () { return this; }; // HACK: Since TypeScript inherits static properties too, we have to // fight against TypeScript here so Subject can have a different static create signature /** * Creates a new cold Observable by calling the Observable constructor * @static true * @owner Observable * @method create * @param {Function} subscribe? the subscriber function to be passed to the Observable constructor * @return {Observable} a new cold observable */ Observable.create = function (subscribe) { return new Observable(subscribe); }; return Observable; }()); exports.Observable = Observable; },{"./symbol/observable":289,"./util/root":315,"./util/toSubscriber":318}],6:[function(require,module,exports){ "use strict"; exports.empty = { isUnsubscribed: true, next: function (value) { }, error: function (err) { throw err; }, complete: function () { } }; },{}],7:[function(require,module,exports){ "use strict"; var Subscriber_1 = require('./Subscriber'); var Operator = (function () { function Operator() { } Operator.prototype.call = function (subscriber, source) { return source._subscribe(new Subscriber_1.Subscriber(subscriber)); }; return Operator; }()); exports.Operator = Operator; },{"./Subscriber":14}],8:[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'); /** * We need this JSDoc comment for affecting ESDoc. * @ignore * @extends {Ignored} */ var OuterSubscriber = (function (_super) { __extends(OuterSubscriber, _super); function OuterSubscriber() { _super.apply(this, arguments); } OuterSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) { this.destination.next(innerValue); }; OuterSubscriber.prototype.notifyError = function (error, innerSub) { this.destination.error(error); }; OuterSubscriber.prototype.notifyComplete = function (innerSub) { this.destination.complete(); }; return OuterSubscriber; }(Subscriber_1.Subscriber)); exports.OuterSubscriber = OuterSubscriber; },{"./Subscriber":14}],9:[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 Subject_1 = require('./Subject'); var queue_1 = require('./scheduler/queue'); var observeOn_1 = require('./operator/observeOn'); /** * @class ReplaySubject<T> */ var ReplaySubject = (function (_super) { __extends(ReplaySubject, _super); function ReplaySubject(bufferSize, windowTime, scheduler) { if (bufferSize === void 0) { bufferSize = Number.POSITIVE_INFINITY; } if (windowTime === void 0) { windowTime = Number.POSITIVE_INFINITY; } _super.call(this); this.events = []; this.scheduler = scheduler; this.bufferSize = bufferSize < 1 ? 1 : bufferSize; this._windowTime = windowTime < 1 ? 1 : windowTime; } ReplaySubject.prototype._next = function (value) { var now = this._getNow(); this.events.push(new ReplayEvent(now, value)); this._trimBufferThenGetEvents(now); _super.prototype._next.call(this, value); }; ReplaySubject.prototype._subscribe = function (subscriber) { var events = this._trimBufferThenGetEvents(this._getNow()); var scheduler = this.scheduler; if (scheduler) { subscriber.add(subscriber = new observeOn_1.ObserveOnSubscriber(subscriber, scheduler)); } var index = -1; var len = events.length; while (++index < len && !subscriber.isUnsubscribed) { subscriber.next(events[index].value); } return _super.prototype._subscribe.call(this, subscriber); }; ReplaySubject.prototype._getNow = function () { return (this.scheduler || queue_1.queue).now(); }; ReplaySubject.prototype._trimBufferThenGetEvents = function (now) { var bufferSize = this.bufferSize; var _windowTime = this._windowTime; var events = this.events; var eventsCount = events.length; var spliceCount = 0; // Trim events that fall out of the time window. // Start at the front of the list. Break early once // we encounter an event that falls within the window. while (spliceCount < eventsCount) { if ((now - events[spliceCount].time) < _windowTime) { break; } spliceCount += 1; } if (eventsCount > bufferSize) { spliceCount = Math.max(spliceCount, eventsCount - bufferSize); } if (spliceCount > 0) { events.splice(0, spliceCount); } return events; }; return ReplaySubject; }(Subject_1.Subject)); exports.ReplaySubject = ReplaySubject; var ReplayEvent = (function () { function ReplayEvent(time, value) { this.time = time; this.value = value; } return ReplayEvent; }()); },{"./Subject":12,"./operator/observeOn":232,"./scheduler/queue":287}],10:[function(require,module,exports){ "use strict"; function __export(m) { for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; } __export(require('./Rx')); // statics require('./add/observable/if'); require('./add/observable/using'); // Operators require('./add/operator/distinct'); require('./add/operator/distinctKey'); require('./add/operator/distinctUntilKeyChanged'); require('./add/operator/elementAt'); require('./add/operator/exhaust'); require('./add/operator/exhaustMap'); require('./add/operator/find'); require('./add/operator/findIndex'); require('./add/operator/isEmpty'); require('./add/operator/max'); require('./add/operator/mergeScan'); require('./add/operator/min'); require('./add/operator/pairwise'); require('./add/operator/timeInterval'); require('./add/operator/timestamp'); var timeInterval_1 = require('./operator/timeInterval'); exports.TimeInterval = timeInterval_1.TimeInterval; var timestamp_1 = require('./operator/timestamp'); exports.Timestamp = timestamp_1.Timestamp; var TestScheduler_1 = require('./testing/TestScheduler'); exports.TestScheduler = TestScheduler_1.TestScheduler; var VirtualTimeScheduler_1 = require('./scheduler/VirtualTimeScheduler'); exports.VirtualTimeScheduler = VirtualTimeScheduler_1.VirtualTimeScheduler; },{"./Rx":11,"./add/observable/if":27,"./add/observable/using":36,"./add/operator/distinct":60,"./add/operator/distinctKey":61,"./add/operator/distinctUntilKeyChanged":63,"./add/operator/elementAt":65,"./add/operator/exhaust":67,"./add/operator/exhaustMap":68,"./add/operator/find":72,"./add/operator/findIndex":73,"./add/operator/isEmpty":77,"./add/operator/max":83,"./add/operator/mergeScan":88,"./add/operator/min":89,"./add/operator/pairwise":92,"./add/operator/timeInterval":123,"./add/operator/timestamp":126,"./operator/timeInterval":264,"./operator/timestamp":267,"./scheduler/VirtualTimeScheduler":284,"./testing/TestScheduler":295}],11:[function(require,module,exports){ "use strict"; /* tslint:disable:no-unused-variable */ // Subject imported before Observable to bypass circular dependency issue since // Subject extends Observable and Observable references Subject in it's // definition var Subject_1 = require('./Subject'); exports.Subject = Subject_1.Subject; /* tslint:enable:no-unused-variable */ var Observable_1 = require('./Observable'); exports.Observable = Observable_1.Observable; // statics /* tslint:disable:no-use-before-declare */ require('./add/observable/bindCallback'); require('./add/observable/bindNodeCallback'); require('./add/observable/combineLatest'); require('./add/observable/concat'); require('./add/observable/defer'); require('./add/observable/empty'); require('./add/observable/forkJoin'); require('./add/observable/from'); require('./add/observable/fromEvent'); require('./add/observable/fromEventPattern'); require('./add/observable/fromPromise'); require('./add/observable/interval'); require('./add/observable/merge'); require('./add/observable/race'); require('./add/observable/never'); require('./add/observable/of'); require('./add/observable/range'); require('./add/observable/throw'); require('./add/observable/timer'); require('./add/observable/zip'); //operators require('./add/operator/buffer'); require('./add/operator/bufferCount'); require('./add/operator/bufferTime'); require('./add/operator/bufferToggle'); require('./add/operator/bufferWhen'); require('./add/operator/cache'); require('./add/operator/catch'); require('./add/operator/combineAll'); require('./add/operator/combineLatest'); require('./add/operator/concat'); require('./add/operator/concatAll'); require('./add/operator/concatMap'); require('./add/operator/concatMapTo'); require('./add/operator/count'); require('./add/operator/dematerialize'); require('./add/operator/debounce'); require('./add/operator/debounceTime'); require('./add/operator/defaultIfEmpty'); require('./add/operator/delay'); require('./add/operator/delayWhen'); require('./add/operator/distinctUntilChanged'); require('./add/operator/do'); require('./add/operator/expand'); require('./add/operator/filter'); require('./add/operator/finally'); require('./add/operator/first'); require('./add/operator/groupBy'); require('./add/operator/ignoreElements'); require('./add/operator/audit'); require('./add/operator/auditTime'); require('./add/operator/last'); require('./add/operator/let'); require('./add/operator/every'); require('./add/operator/map'); require('./add/operator/mapTo'); require('./add/operator/materialize'); require('./add/operator/merge'); require('./add/operator/mergeAll'); require('./add/operator/mergeMap'); require('./add/operator/mergeMapTo'); require('./add/operator/multicast'); require('./add/operator/observeOn'); require('./add/operator/partition'); require('./add/operator/pluck'); require('./add/operator/publish'); require('./add/operator/publishBehavior'); require('./add/operator/publishReplay'); require('./add/operator/publishLast'); require('./add/operator/race'); require('./add/operator/reduce'); require('./add/operator/repeat'); require('./add/operator/retry'); require('./add/operator/retryWhen'); require('./add/operator/sample'); require('./add/operator/sampleTime'); require('./add/operator/scan'); require('./add/operator/share'); require('./add/operator/single'); require('./add/operator/skip'); require('./add/operator/skipUntil'); require('./add/operator/skipWhile'); require('./add/operator/startWith'); require('./add/operator/subscribeOn'); require('./add/operator/switch'); require('./add/operator/switchMap'); require('./add/operator/switchMapTo'); require('./add/operator/take'); require('./add/operator/takeLast'); require('./add/operator/takeUntil'); require('./add/operator/takeWhile'); require('./add/operator/throttle'); require('./add/operator/throttleTime'); require('./add/operator/timeout'); require('./add/operator/timeoutWith'); require('./add/operator/toArray'); require('./add/operator/toPromise'); require('./add/operator/window'); require('./add/operator/windowCount'); require('./add/operator/windowTime'); require('./add/operator/windowToggle'); require('./add/operator/windowWhen'); require('./add/operator/withLatestFrom'); require('./add/operator/zip'); require('./add/operator/zipAll'); /* tslint:disable:no-unused-variable */ var Operator_1 = require('./Operator'); exports.Operator = Operator_1.Operator; var Subscription_1 = require('./Subscription'); exports.Subscription = Subscription_1.Subscription; var Subscriber_1 = require('./Subscriber'); exports.Subscriber = Subscriber_1.Subscriber; var AsyncSubject_1 = require('./AsyncSubject'); exports.AsyncSubject = AsyncSubject_1.AsyncSubject; var ReplaySubject_1 = require('./ReplaySubject'); exports.ReplaySubject = ReplaySubject_1.ReplaySubject; var BehaviorSubject_1 = require('./BehaviorSubject'); exports.BehaviorSubject = BehaviorSubject_1.BehaviorSubject; var ConnectableObservable_1 = require('./observable/ConnectableObservable'); exports.ConnectableObservable = ConnectableObservable_1.ConnectableObservable; var Notification_1 = require('./Notification'); exports.Notification = Notification_1.Notification; var EmptyError_1 = require('./util/EmptyError'); exports.EmptyError = EmptyError_1.EmptyError; var ArgumentOutOfRangeError_1 = require('./util/ArgumentOutOfRangeError'); exports.ArgumentOutOfRangeError = ArgumentOutOfRangeError_1.ArgumentOutOfRangeError; var ObjectUnsubscribedError_1 = require('./util/ObjectUnsubscribedError'); exports.ObjectUnsubscribedError = ObjectUnsubscribedError_1.ObjectUnsubscribedError; var UnsubscriptionError_1 = require('./util/UnsubscriptionError'); exports.UnsubscriptionError = UnsubscriptionError_1.UnsubscriptionError; var asap_1 = require('./scheduler/asap'); var async_1 = require('./scheduler/async'); var queue_1 = require('./scheduler/queue'); var rxSubscriber_1 = require('./symbol/rxSubscriber'); var observable_1 = require('./symbol/observable'); var iterator_1 = require('./symbol/iterator'); /* tslint:enable:no-unused-variable */ /** * @typedef {Object} Rx.Scheduler * @property {Scheduler} queue Schedules on a queue in the current event frame * (trampoline scheduler). Use this for iteration operations. * @property {Scheduler} asap Schedules on the micro task queue, which uses the * fastest transport mechanism available, either Node.js' `process.nextTick()` * or Web Worker MessageChannel or setTimeout or others. Use this for * asynchronous conversions. * @property {Scheduler} async Schedules work with `setInterval`. Use this for * time-based operations. */ var Scheduler = { asap: asap_1.asap, async: async_1.async, queue: queue_1.queue }; exports.Scheduler = Scheduler; /** * @typedef {Object} Rx.Symbol * @property {Symbol|string} rxSubscriber A symbol to use as a property name to * retrieve an "Rx safe" Observer from an object. "Rx safety" can be defined as * an object that has all of the traits of an Rx Subscriber, including the * ability to add and remove subscriptions to the subscription chain and * guarantees involving event triggering (can't "next" after unsubscription, * etc). * @property {Symbol|string} observable A symbol to use as a property name to * retrieve an Observable as defined by the [ECMAScript "Observable" spec](https://github.com/zenparsing/es-observable). * @property {Symbol|string} iterator The ES6 symbol to use as a property name * to retrieve an iterator from an object. */ var Symbol = { rxSubscriber: rxSubscriber_1.$$rxSubscriber, observable: observable_1.$$observable, iterator: iterator_1.$$iterator }; exports.Symbol = Symbol; },{"./AsyncSubject":1,"./BehaviorSubject":2,"./Notification":4,"./Observable":5,"./Operator":7,"./ReplaySubject":9,"./Subject":12,"./Subscriber":14,"./Subscription":15,"./add/observable/bindCallback":16,"./add/observable/bindNodeCallback":17,"./add/observable/combineLatest":18,"./add/observable/concat":19,"./add/observable/defer":20,"./add/observable/empty":21,"./add/observable/forkJoin":22,"./add/observable/from":23,"./add/observable/fromEvent":24,"./add/observable/fromEventPattern":25,"./add/observable/fromPromise":26,"./add/observable/interval":28,"./add/observable/merge":29,"./add/observable/never":30,"./add/observable/of":31,"./add/observable/race":32,"./add/observable/range":33,"./add/observable/throw":34,"./add/observable/timer":35,"./add/observable/zip":37,"./add/operator/audit":38,"./add/operator/auditTime":39,"./add/operator/buffer":40,"./add/operator/bufferCount":41,"./add/operator/bufferTime":42,"./add/operator/bufferToggle":43,"./add/operator/bufferWhen":44,"./add/operator/cache":45,"./add/operator/catch":46,"./add/operator/combineAll":47,"./add/operator/combineLatest":48,"./add/operator/concat":49,"./add/operator/concatAll":50,"./add/operator/concatMap":51,"./add/operator/concatMapTo":52,"./add/operator/count":53,"./add/operator/debounce":54,"./add/operator/debounceTime":55,"./add/operator/defaultIfEmpty":56,"./add/operator/delay":57,"./add/operator/delayWhen":58,"./add/operator/dematerialize":59,"./add/operator/distinctUntilChanged":62,"./add/operator/do":64,"./add/operator/every":66,"./add/operator/expand":69,"./add/operator/filter":70,"./add/operator/finally":71,"./add/operator/first":74,"./add/operator/groupBy":75,"./add/operator/ignoreElements":76,"./add/operator/last":78,"./add/operator/let":79,"./add/operator/map":80,"./add/operator/mapTo":81,"./add/operator/materialize":82,"./add/operator/merge":84,"./add/operator/mergeAll":85,"./add/operator/mergeMap":86,"./add/operator/mergeMapTo":87,"./add/operator/multicast":90,"./add/operator/observeOn":91,"./add/operator/partition":93,"./add/operator/pluck":94,"./add/operator/publish":95,"./add/operator/publishBehavior":96,"./add/operator/publishLast":97,"./add/operator/publishReplay":98,"./add/operator/race":99,"./add/operator/reduce":100,"./add/operator/repeat":101,"./add/operator/retry":102,"./add/operator/retryWhen":103,"./add/operator/sample":104,"./add/operator/sampleTime":105,"./add/operator/scan":106,"./add/operator/share":107,"./add/operator/single":108,"./add/operator/skip":109,"./add/operator/skipUntil":110,"./add/operator/skipWhile":111,"./add/operator/startWith":112,"./add/operator/subscribeOn":113,"./add/operator/switch":114,"./add/operator/switchMap":115,"./add/operator/switchMapTo":116,"./add/operator/take":117,"./add/operator/takeLast":118,"./add/operator/takeUntil":119,"./add/operator/takeWhile":120,"./add/operator/throttle":121,"./add/operator/throttleTime":122,"./add/operator/timeout":124,"./add/operator/timeoutWith":125,"./add/operator/toArray":127,"./add/operator/toPromise":128,"./add/operator/window":129,"./add/operator/windowCount":130,"./add/operator/windowTime":131,"./add/operator/windowToggle":132,"./add/operator/windowWhen":133,"./add/operator/withLatestFrom":134,"./add/operator/zip":135,"./add/operator/zipAll":136,"./observable/ConnectableObservable":141,"./scheduler/asap":285,"./scheduler/async":286,"./scheduler/queue":287,"./symbol/iterator":288,"./symbol/observable":289,"./symbol/rxSubscriber":290,"./util/ArgumentOutOfRangeError":296,"./util/EmptyError":297,"./util/ObjectUnsubscribedError":302,"./util/UnsubscriptionError":303}],12:[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 Observable_1 = require('./Observable'); var Subscriber_1 = require('./Subscriber'); var Subscription_1 = require('./Subscription'); var SubjectSubscription_1 = require('./SubjectSubscription'); var rxSubscriber_1 = require('./symbol/rxSubscriber'); var throwError_1 = require('./util/throwError'); var ObjectUnsubscribedError_1 = require('./util/ObjectUnsubscribedError'); /** * @class Subject<T> */ var Subject = (function (_super) { __extends(Subject, _super); function Subject(destination, source) { _super.call(this); this.destination = destination; this.source = source; this.observers = []; this.isUnsubscribed = false; this.isStopped = false; this.hasErrored = false; this.dispatching = false; this.hasCompleted = false; this.source = source; } Subject.prototype.lift = function (operator) { var subject = new Subject(this.destination || this, this); subject.operator = operator; return subject; }; Subject.prototype.add = function (subscription) { return Subscription_1.Subscription.prototype.add.call(this, subscription); }; Subject.prototype.remove = function (subscription) { Subscription_1.Subscription.prototype.remove.call(this, subscription); }; Subject.prototype.unsubscribe = function () { Subscription_1.Subscription.prototype.unsubscribe.call(this); }; Subject.prototype._subscribe = function (subscriber) { if (this.source) { return this.source.subscribe(subscriber); } else { if (subscriber.isUnsubscribed) { return; } else if (this.hasErrored) { return subscriber.error(this.errorValue); } else if (this.hasCompleted) { return subscriber.complete(); } this.throwIfUnsubscribed(); var subscription = new SubjectSubscription_1.SubjectSubscription(this, subscriber); this.observers.push(subscriber); return subscription; } }; Subject.prototype._unsubscribe = function () { this.source = null; this.isStopped = true; this.observers = null; this.destination = null; }; Subject.prototype.next = function (value) { this.throwIfUnsubscribed(); if (this.isStopped) { return; } this.dispatching = true; this._next(value); this.dispatching = false; if (this.hasErrored) { this._error(this.errorValue); } else if (this.hasCompleted) { this._complete(); } }; Subject.prototype.error = function (err) { this.throwIfUnsubscribed(); if (this.isStopped) { return; } this.isStopped = true; this.hasErrored = true; this.errorValue = err; if (this.dispatching) { return; } this._error(err); }; Subject.prototype.complete = function () { this.throwIfUnsubscribed(); if (this.isStopped) { return; } this.isStopped = true; this.hasCompleted = true; if (this.dispatching) { return; } this._complete(); }; Subject.prototype.asObservable = function () { var observable = new SubjectObservable(this); return observable; }; Subject.prototype._next = function (value) { if (this.destination) { this.destination.next(value); } else { this._finalNext(value); } }; Subject.prototype._finalNext = function (value) { var index = -1; var observers = this.observers.slice(0); var len = observers.length; while (++index < len) { observers[index].next(value); } }; Subject.prototype._error = function (err) { if (this.destination) { this.destination.error(err); } else { this._finalError(err); } }; Subject.prototype._finalError = function (err) { var index = -1; var observers = this.observers; // optimization to block our SubjectSubscriptions from // splicing themselves out of the observers list one by one. this.observers = null; this.isUnsubscribed = true; if (observers) { var len = observers.length; while (++index < len) { observers[index].error(err); } } this.isUnsubscribed = false; this.unsubscribe(); }; Subject.prototype._complete = function () { if (this.destination) { this.destination.complete(); } else { this._finalComplete(); } }; Subject.prototype._finalComplete = function () { var index = -1; var observers = this.observers; // optimization to block our SubjectSubscriptions from // splicing themselves out of the observers list one by one. this.observers = null; this.isUnsubscribed = true; if (observers) { var len = observers.length; while (++index < len) { observers[index].complete(); } } this.isUnsubscribed = false; this.unsubscribe(); }; Subject.prototype.throwIfUnsubscribed = function () { if (this.isUnsubscribed) { throwError_1.throwError(new ObjectUnsubscribedError_1.ObjectUnsubscribedError()); } }; Subject.prototype[rxSubscriber_1.$$rxSubscriber] = function () { return new Subscriber_1.Subscriber(this); }; Subject.create = function (destination, source) { return new Subject(destination, source); }; return Subject; }(Observable_1.Observable)); exports.Subject = Subject; /** * We need this JSDoc comment for affecting ESDoc. * @ignore * @extends {Ignored} */ var SubjectObservable = (function (_super) { __extends(SubjectObservable, _super); function SubjectObservable(source) { _super.call(this); this.source = source; } return SubjectObservable; }(Observable_1.Observable)); },{"./Observable":5,"./SubjectSubscription":13,"./Subscriber":14,"./Subscription":15,"./symbol/rxSubscriber":290,"./util/ObjectUnsubscribedError":302,"./util/throwError":317}],13:[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'); /** * We need this JSDoc comment for affecting ESDoc. * @ignore * @extends {Ignored} */ var SubjectSubscription = (function (_super) { __extends(SubjectSubscription, _super); function SubjectSubscription(subject, observer) { _super.call(this); this.subject = subject; this.observer = observer; this.isUnsubscribed = false; } SubjectSubscription.prototype.unsubscribe = function () { if (this.isUnsubscribed) { return; } this.isUnsubscribed = true; var subject = this.subject; var observers = subject.observers; this.subject = null; if (!observers || observers.length === 0 || subject.isUnsubscribed) { return; } var subscriberIndex = observers.indexOf(this.observer); if (subscriberIndex !== -1) { observers.splice(subscriberIndex, 1); } }; return SubjectSubscription; }(Subscription_1.Subscription)); exports.SubjectSubscription = SubjectSubscription; },{"./Subscription":15}],14:[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 isFunction_1 = require('./util/isFunction'); var Subscription_1 = require('./Subscription'); var rxSubscriber_1 = require('./symbol/rxSubscriber'); var Observer_1 = require('./Observer'); /** * Implements the {@link Observer} interface and extends the * {@link Subscription} class. While the {@link Observer} is the public API for * consuming the values of an {@link Observable}, all Observers get converted to * a Subscriber, in order to provide Subscription-like capabilities such as * `unsubscribe`. Subscriber is a common type in RxJS, and crucial for * implementing operators, but it is rarely used as a public API. * * @class Subscriber<T> */ var Subscriber = (function (_super) { __extends(Subscriber, _super); /** * @param {Observer|function(value: T): void} [destinationOrNext] A partially * defined Observer or a `next` callback function. * @param {function(e: ?any): void} [error] The `error` callback of an * Observer. * @param {function(): void} [complete] The `complete` callback of an * Observer. */ function Subscriber(destinationOrNext, error, complete) { _super.call(this); this.syncErrorValue = null; this.syncErrorThrown = false; this.syncErrorThrowable = false; this.isStopped = false; switch (arguments.length) { case 0: this.destination = Observer_1.empty; break; case 1: if (!destinationOrNext) { this.destination = Observer_1.empty; break; } if (typeof destinationOrNext === 'object') { if (destinationOrNext instanceof Subscriber) { this.destination = destinationOrNext; this.destination.add(this); } else { this.syncErrorThrowable = true; this.destination = new SafeSubscriber(this, destinationOrNext); } break; } default: this.syncErrorThrowable = true; this.destination = new SafeSubscriber(this, destinationOrNext, error, complete); break; } } /** * A static factory for a Subscriber, given a (potentially partial) definition * of an Observer. * @param {function(x: ?T): void} [next] The `next` callback of an Observer. * @param {function(e: ?any): void} [error] The `error` callback of an * Observer. * @param {function(): void} [complete] The `complete` callback of an * Observer. * @return {Subscriber<T>} A Subscriber wrapping the (partially defined) * Observer represented by the given arguments. */ Subscriber.create = function (next, error, complete) { var subscriber = new Subscriber(next, error, complete); subscriber.syncErrorThrowable = false; return subscriber; }; /** * The {@link Observer} callback to receive notifications of type `next` from * the Observable, with a value. The Observable may call this method 0 or more * times. * @param {T} [value] The `next` value. * @return {void} */ Subscriber.prototype.next = function (value) { if (!this.isStopped) { this._next(value); } }; /** * The {@link Observer} callback to receive notifications of type `error` from * the Observable, with an attached {@link Error}. Notifies the Observer that * the Observable has experienced an error condition. * @param {any} [err] The `error` exception. * @return {void} */ Subscriber.prototype.error = function (err) { if (!this.isStopped) { this.isStopped = true; this._error(err); } }; /** * The {@link Observer} callback to receive a valueless notification of type * `complete` from the Observable. Notifies the Observer that the Observable * has finished sending push-based notifications. * @return {void} */ Subscriber.prototype.complete = function () { if (!this.isStopped) { this.isStopped = true; this._complete(); } }; Subscriber.prototype.unsubscribe = function () { if (this.isUnsubscribed) { return; } this.isStopped = true; _super.prototype.unsubscribe.call(this); }; Subscriber.prototype._next = function (value) { this.destination.next(value); }; Subscriber.prototype._error = function (err) { this.destination.error(err); this.unsubscribe(); }; Subscriber.prototype._complete = function () { this.destination.complete(); this.unsubscribe(); }; Subscriber.prototype[rxSubscriber_1.$$rxSubscriber] = function () { return this; }; return Subscriber; }(Subscription_1.Subscription)); exports.Subscriber = Subscriber; /** * We need this JSDoc comment for affecting ESDoc. * @ignore * @extends {Ignored} */ var SafeSubscriber = (function (_super) { __extends(SafeSubscriber, _super); function SafeSubscriber(_parent, observerOrNext, error, complete) { _super.call(this); this._parent = _parent; var next; var context = this; if (isFunction_1.isFunction(observerOrNext)) { next = observerOrNext; } else if (observerOrNext) { context = observerOrNext; next = observerOrNext.next; error = observerOrNext.error; complete = observerOrNext.complete; if (isFunction_1.isFunction(context.unsubscribe)) { this.add(context.unsubscribe.bind(context)); } context.unsubscribe = this.unsubscribe.bind(this); } this._context = context; this._next = next; this._error = error; this._complete = complete; } SafeSubscriber.prototype.next = function (value) { if (!this.isStopped && this._next) { var _parent = this._parent; if (!_parent.syncErrorThrowable) { this.__tryOrUnsub(this._next, value); } else if (this.__tryOrSetError(_parent, this._next, value)) { this.unsubscribe(); } } }; SafeSubscriber.prototype.error = function (err) { if (!this.isStopped) { var _parent = this._parent; if (this._error) { if (!_parent.syncErrorThrowable) { this.__tryOrUnsub(this._error, err); this.unsubscribe();