UNPKG

ionic-angular

Version:

A powerful framework for building mobile and progressive web apps with JavaScript and Angular 2

1,412 lines (1,343 loc) 2.4 MB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : (factory((global.ionicBundle = global.ionicBundle || {}))); }(this, (function (exports) { 'use strict'; var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; function createCommonjsModule(fn, module) { return module = { exports: {} }, fn(module, module.exports), module.exports; } var root = createCommonjsModule(function (module, exports) { "use strict"; /** * window: browser in DOM main thread * self: browser in WebWorker * global: Node.js/other */ exports.root = (typeof window == 'object' && window.window === window && window || typeof self == 'object' && self.self === self && self || typeof commonjsGlobal == 'object' && commonjsGlobal.global === commonjsGlobal && commonjsGlobal); if (!exports.root) { throw new Error('RxJS could not find any global context (window, self, global)'); } }); function isFunction(x) { return typeof x === 'function'; } var isFunction_2 = isFunction; var isFunction_1 = { isFunction: isFunction_2 }; var isArray_1 = Array.isArray || (function (x) { return x && typeof x.length === 'number'; }); var isArray = { isArray: isArray_1 }; function isObject(x) { return x != null && typeof x === 'object'; } var isObject_2 = isObject; var isObject_1 = { isObject: isObject_2 }; // typeof any so that it we don't have to cast when comparing a result to the error object var errorObject_1 = { e: {} }; var errorObject = { errorObject: errorObject_1 }; var tryCatchTarget; function tryCatcher() { try { return tryCatchTarget.apply(this, arguments); } catch (e) { errorObject.errorObject.e = e; return errorObject.errorObject; } } function tryCatch(fn) { tryCatchTarget = fn; return tryCatcher; } var tryCatch_2 = tryCatch; var tryCatch_1 = { tryCatch: tryCatch_2 }; var __extends$3 = (commonjsGlobal && commonjsGlobal.__extends) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; /** * An error thrown when one or more errors have occurred during the * `unsubscribe` of a {@link Subscription}. */ var UnsubscriptionError = (function (_super) { __extends$3(UnsubscriptionError, _super); function UnsubscriptionError(errors) { _super.call(this); this.errors = errors; var err = Error.call(this, errors ? errors.length + " errors occurred during unsubscription:\n " + errors.map(function (err, i) { return ((i + 1) + ") " + err.toString()); }).join('\n ') : ''); this.name = err.name = 'UnsubscriptionError'; this.stack = err.stack; this.message = err.message; } return UnsubscriptionError; }(Error)); var UnsubscriptionError_2 = UnsubscriptionError; var UnsubscriptionError_1 = { UnsubscriptionError: UnsubscriptionError_2 }; /** * Represents a disposable resource, such as the execution of an Observable. A * Subscription has one important method, `unsubscribe`, that takes no argument * and just disposes the resource held by the subscription. * * Additionally, subscriptions may be grouped together through the `add()` * method, which will attach a child Subscription to the current Subscription. * When a Subscription is unsubscribed, all its children (and its grandchildren) * will be unsubscribed as well. * * @class Subscription */ var Subscription = (function () { /** * @param {function(): void} [unsubscribe] A function describing how to * perform the disposal of resources when the `unsubscribe` method is called. */ function Subscription(unsubscribe) { /** * A flag to indicate whether this Subscription has already been unsubscribed. * @type {boolean} */ this.closed = false; this._parent = null; this._parents = null; this._subscriptions = null; if (unsubscribe) { this._unsubscribe = unsubscribe; } } /** * Disposes the resources held by the subscription. May, for instance, cancel * an ongoing Observable execution or cancel any other type of work that * started when the Subscription was created. * @return {void} */ Subscription.prototype.unsubscribe = function () { var hasErrors = false; var errors; if (this.closed) { return; } var _a = this, _parent = _a._parent, _parents = _a._parents, _unsubscribe = _a._unsubscribe, _subscriptions = _a._subscriptions; this.closed = true; this._parent = null; this._parents = null; // null out _subscriptions first so any child subscriptions that attempt // to remove themselves from this subscription will noop this._subscriptions = null; var index = -1; var len = _parents ? _parents.length : 0; // if this._parent is null, then so is this._parents, and we // don't have to remove ourselves from any parent subscriptions. while (_parent) { _parent.remove(this); // if this._parents is null or index >= len, // then _parent is set to null, and the loop exits _parent = ++index < len && _parents[index] || null; } if (isFunction_1.isFunction(_unsubscribe)) { var trial = tryCatch_1.tryCatch(_unsubscribe).call(this); if (trial === errorObject.errorObject) { hasErrors = true; errors = errors || (errorObject.errorObject.e instanceof UnsubscriptionError_1.UnsubscriptionError ? flattenUnsubscriptionErrors(errorObject.errorObject.e.errors) : [errorObject.errorObject.e]); } } if (isArray.isArray(_subscriptions)) { index = -1; len = _subscriptions.length; while (++index < len) { var sub = _subscriptions[index]; if (isObject_1.isObject(sub)) { var trial = tryCatch_1.tryCatch(sub.unsubscribe).call(sub); if (trial === errorObject.errorObject) { hasErrors = true; errors = errors || []; var err = errorObject.errorObject.e; if (err instanceof UnsubscriptionError_1.UnsubscriptionError) { errors = errors.concat(flattenUnsubscriptionErrors(err.errors)); } else { errors.push(err); } } } } } if (hasErrors) { throw new UnsubscriptionError_1.UnsubscriptionError(errors); } }; /** * Adds a tear down to be called during the unsubscribe() of this * Subscription. * * If the tear down being added is a subscription that is already * unsubscribed, is the same reference `add` is being called on, or is * `Subscription.EMPTY`, it will not be added. * * If this subscription is already in an `closed` state, the passed * tear down logic will be executed immediately. * * @param {TeardownLogic} teardown The additional logic to execute on * teardown. * @return {Subscription} Returns the Subscription used or created to be * added to the inner subscriptions list. This Subscription can be used with * `remove()` to remove the passed teardown logic from the inner subscriptions * list. */ Subscription.prototype.add = function (teardown) { if (!teardown || (teardown === Subscription.EMPTY)) { return Subscription.EMPTY; } if (teardown === this) { return this; } var subscription = teardown; switch (typeof teardown) { case 'function': subscription = new Subscription(teardown); case 'object': if (subscription.closed || typeof subscription.unsubscribe !== 'function') { return subscription; } else if (this.closed) { subscription.unsubscribe(); return subscription; } else if (typeof subscription._addParent !== 'function' /* quack quack */) { var tmp = subscription; subscription = new Subscription(); subscription._subscriptions = [tmp]; } break; default: throw new Error('unrecognized teardown ' + teardown + ' added to Subscription.'); } var subscriptions = this._subscriptions || (this._subscriptions = []); subscriptions.push(subscription); subscription._addParent(this); return subscription; }; /** * Removes a Subscription from the internal list of subscriptions that will * unsubscribe during the unsubscribe process of this Subscription. * @param {Subscription} subscription The subscription to remove. * @return {void} */ Subscription.prototype.remove = function (subscription) { var subscriptions = this._subscriptions; if (subscriptions) { var subscriptionIndex = subscriptions.indexOf(subscription); if (subscriptionIndex !== -1) { subscriptions.splice(subscriptionIndex, 1); } } }; Subscription.prototype._addParent = function (parent) { var _a = this, _parent = _a._parent, _parents = _a._parents; if (!_parent || _parent === parent) { // If we don't have a parent, or the new parent is the same as the // current parent, then set this._parent to the new parent. this._parent = parent; } else if (!_parents) { // If there's already one parent, but not multiple, allocate an Array to // store the rest of the parent Subscriptions. this._parents = [parent]; } else if (_parents.indexOf(parent) === -1) { // Only add the new parent to the _parents list if it's not already there. _parents.push(parent); } }; Subscription.EMPTY = (function (empty) { empty.closed = true; return empty; }(new Subscription())); return Subscription; }()); var Subscription_2 = Subscription; function flattenUnsubscriptionErrors(errors) { return errors.reduce(function (errs, err) { return errs.concat((err instanceof UnsubscriptionError_1.UnsubscriptionError) ? err.errors : err); }, []); } var Subscription_1 = { Subscription: Subscription_2 }; var empty = { closed: true, next: function (value) { }, error: function (err) { throw err; }, complete: function () { } }; var Observer = { empty: empty }; var Symbol = root.root.Symbol; var $$rxSubscriber = (typeof Symbol === 'function' && typeof Symbol.for === 'function') ? Symbol.for('rxSubscriber') : '@@rxSubscriber'; var rxSubscriber = { $$rxSubscriber: $$rxSubscriber }; var __extends$2 = (commonjsGlobal && commonjsGlobal.__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 __()); }; /** * 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$2(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.empty; break; case 1: if (!destinationOrNext) { this.destination = Observer.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; } } Subscriber.prototype[rxSubscriber.$$rxSubscriber] = function () { return this; }; /** * 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.closed) { 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._unsubscribeAndRecycle = function () { var _a = this, _parent = _a._parent, _parents = _a._parents; this._parent = null; this._parents = null; this.unsubscribe(); this.closed = false; this.isStopped = false; this._parent = _parent; this._parents = _parents; return this; }; return Subscriber; }(Subscription_1.Subscription)); var Subscriber_2 = Subscriber; /** * We need this JSDoc comment for affecting ESDoc. * @ignore * @extends {Ignored} */ var SafeSubscriber = (function (_super) { __extends$2(SafeSubscriber, _super); function SafeSubscriber(_parentSubscriber, observerOrNext, error, complete) { _super.call(this); this._parentSubscriber = _parentSubscriber; 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 _parentSubscriber = this._parentSubscriber; if (!_parentSubscriber.syncErrorThrowable) { this.__tryOrUnsub(this._next, value); } else if (this.__tryOrSetError(_parentSubscriber, this._next, value)) { this.unsubscribe(); } } }; SafeSubscriber.prototype.error = function (err) { if (!this.isStopped) { var _parentSubscriber = this._parentSubscriber; if (this._error) { if (!_parentSubscriber.syncErrorThrowable) { this.__tryOrUnsub(this._error, err); this.unsubscribe(); } else { this.__tryOrSetError(_parentSubscriber, this._error, err); this.unsubscribe(); } } else if (!_parentSubscriber.syncErrorThrowable) { this.unsubscribe(); throw err; } else { _parentSubscriber.syncErrorValue = err; _parentSubscriber.syncErrorThrown = true; this.unsubscribe(); } } }; SafeSubscriber.prototype.complete = function () { if (!this.isStopped) { var _parentSubscriber = this._parentSubscriber; if (this._complete) { if (!_parentSubscriber.syncErrorThrowable) { this.__tryOrUnsub(this._complete); this.unsubscribe(); } else { this.__tryOrSetError(_parentSubscriber, this._complete); this.unsubscribe(); } } else { this.unsubscribe(); } } }; SafeSubscriber.prototype.__tryOrUnsub = function (fn, value) { try { fn.call(this._context, value); } catch (err) { this.unsubscribe(); throw err; } }; SafeSubscriber.prototype.__tryOrSetError = function (parent, fn, value) { try { fn.call(this._context, value); } catch (err) { parent.syncErrorValue = err; parent.syncErrorThrown = true; return true; } return false; }; SafeSubscriber.prototype._unsubscribe = function () { var _parentSubscriber = this._parentSubscriber; this._context = null; this._parentSubscriber = null; _parentSubscriber.unsubscribe(); }; return SafeSubscriber; }(Subscriber)); var Subscriber_1 = { Subscriber: Subscriber_2 }; function toSubscriber(nextOrObserver, error, complete) { if (nextOrObserver) { if (nextOrObserver instanceof Subscriber_1.Subscriber) { return nextOrObserver; } if (nextOrObserver[rxSubscriber.$$rxSubscriber]) { return nextOrObserver[rxSubscriber.$$rxSubscriber](); } } if (!nextOrObserver && !error && !complete) { return new Subscriber_1.Subscriber(Observer.empty); } return new Subscriber_1.Subscriber(nextOrObserver, error, complete); } var toSubscriber_2 = toSubscriber; var toSubscriber_1 = { toSubscriber: toSubscriber_2 }; function getSymbolObservable(context) { var $$observable; var Symbol = context.Symbol; if (typeof Symbol === 'function') { if (Symbol.observable) { $$observable = Symbol.observable; } else { $$observable = Symbol('observable'); Symbol.observable = $$observable; } } else { $$observable = '@@observable'; } return $$observable; } var getSymbolObservable_1 = getSymbolObservable; var $$observable = getSymbolObservable(root.root); var observable = { getSymbolObservable: getSymbolObservable_1, $$observable: $$observable }; /** * 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$$1 = new Observable(); observable$$1.source = this; observable$$1.operator = operator; return observable$$1; }; Observable.prototype.subscribe = function (observerOrNext, error, complete) { var operator = this.operator; var sink = toSubscriber_1.toSubscriber(observerOrNext, error, complete); if (operator) { operator.call(sink, this.source); } else { sink.add(this._trySubscribe(sink)); } if (sink.syncErrorThrowable) { sink.syncErrorThrowable = false; if (sink.syncErrorThrown) { throw sink.syncErrorValue; } } return sink; }; Observable.prototype._trySubscribe = function (sink) { try { return this._subscribe(sink); } catch (err) { sink.syncErrorThrown = true; sink.syncErrorValue = err; sink.error(err); } }; /** * @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.root.Rx && root.root.Rx.config && root.root.Rx.config.Promise) { PromiseCtor = root.root.Rx.config.Promise; } else if (root.root.Promise) { PromiseCtor = root.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` 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.$$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; }()); var Observable_2 = Observable; var Observable_1 = { Observable: Observable_2 }; var __extends$5 = (commonjsGlobal && commonjsGlobal.__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 __()); }; /** * We need this JSDoc comment for affecting ESDoc. * @extends {Ignored} * @hide true */ var ScalarObservable = (function (_super) { __extends$5(ScalarObservable, _super); function ScalarObservable(value, scheduler) { _super.call(this); this.value = value; this.scheduler = scheduler; this._isScalar = true; if (scheduler) { this._isScalar = false; } } ScalarObservable.create = function (value, scheduler) { return new ScalarObservable(value, scheduler); }; ScalarObservable.dispatch = function (state) { var done = state.done, value = state.value, subscriber = state.subscriber; if (done) { subscriber.complete(); return; } subscriber.next(value); if (subscriber.closed) { return; } state.done = true; this.schedule(state); }; ScalarObservable.prototype._subscribe = function (subscriber) { var value = this.value; var scheduler = this.scheduler; if (scheduler) { return scheduler.schedule(ScalarObservable.dispatch, 0, { done: false, value: value, subscriber: subscriber }); } else { subscriber.next(value); if (!subscriber.closed) { subscriber.complete(); } } }; return ScalarObservable; }(Observable_1.Observable)); var ScalarObservable_2 = ScalarObservable; var ScalarObservable_1 = { ScalarObservable: ScalarObservable_2 }; var __extends$6 = (commonjsGlobal && commonjsGlobal.__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 __()); }; /** * We need this JSDoc comment for affecting ESDoc. * @extends {Ignored} * @hide true */ var EmptyObservable = (function (_super) { __extends$6(EmptyObservable, _super); function EmptyObservable(scheduler) { _super.call(this); this.scheduler = scheduler; } /** * Creates an Observable that emits no items to the Observer and immediately * emits a complete notification. * * <span class="informal">Just emits 'complete', and nothing else. * </span> * * <img src="./img/empty.png" width="100%"> * * This static operator is useful for creating a simple Observable that only * emits the complete notification. It can be used for composing with other * Observables, such as in a {@link mergeMap}. * * @example <caption>Emit the number 7, then complete.</caption> * var result = Rx.Observable.empty().startWith(7); * result.subscribe(x => console.log(x)); * * @example <caption>Map and flatten only odd numbers to the sequence 'a', 'b', 'c'</caption> * var interval = Rx.Observable.interval(1000); * var result = interval.mergeMap(x => * x % 2 === 1 ? Rx.Observable.of('a', 'b', 'c') : Rx.Observable.empty() * ); * result.subscribe(x => console.log(x)); * * // Results in the following to the console: * // x is equal to the count on the interval eg(0,1,2,3,...) * // x will occur every 1000ms * // if x % 2 is equal to 1 print abc * // if x % 2 is not equal to 1 nothing will be output * * @see {@link create} * @see {@link never} * @see {@link of} * @see {@link throw} * * @param {Scheduler} [scheduler] A {@link IScheduler} to use for scheduling * the emission of the complete notification. * @return {Observable} An "empty" Observable: emits only the complete * notification. * @static true * @name empty * @owner Observable */ EmptyObservable.create = function (scheduler) { return new EmptyObservable(scheduler); }; EmptyObservable.dispatch = function (arg) { var subscriber = arg.subscriber; subscriber.complete(); }; EmptyObservable.prototype._subscribe = function (subscriber) { var scheduler = this.scheduler; if (scheduler) { return scheduler.schedule(EmptyObservable.dispatch, 0, { subscriber: subscriber }); } else { subscriber.complete(); } }; return EmptyObservable; }(Observable_1.Observable)); var EmptyObservable_2 = EmptyObservable; var EmptyObservable_1 = { EmptyObservable: EmptyObservable_2 }; function isScheduler(value) { return value && typeof value.schedule === 'function'; } var isScheduler_2 = isScheduler; var isScheduler_1 = { isScheduler: isScheduler_2 }; var __extends$4 = (commonjsGlobal && commonjsGlobal.__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 __()); }; /** * We need this JSDoc comment for affecting ESDoc. * @extends {Ignored} * @hide true */ var ArrayObservable = (function (_super) { __extends$4(ArrayObservable, _super); function ArrayObservable(array, scheduler) { _super.call(this); this.array = array; this.scheduler = scheduler; if (!scheduler && array.length === 1) { this._isScalar = true; this.value = array[0]; } } ArrayObservable.create = function (array, scheduler) { return new ArrayObservable(array, scheduler); }; /** * Creates an Observable that emits some values you specify as arguments, * immediately one after the other, and then emits a complete notification. * * <span class="informal">Emits the arguments you provide, then completes. * </span> * * <img src="./img/of.png" width="100%"> * * This static operator is useful for creating a simple Observable that only * emits the arguments given, and the complete notification thereafter. It can * be used for composing with other Observables, such as with {@link concat}. * By default, it uses a `null` IScheduler, which means the `next` * notifications are sent synchronously, although with a different IScheduler * it is possible to determine when those notifications will be delivered. * * @example <caption>Emit 10, 20, 30, then 'a', 'b', 'c', then start ticking every second.</caption> * var numbers = Rx.Observable.of(10, 20, 30); * var letters = Rx.Observable.of('a', 'b', 'c'); * var interval = Rx.Observable.interval(1000); * var result = numbers.concat(letters).concat(interval); * result.subscribe(x => console.log(x)); * * @see {@link create} * @see {@link empty} * @see {@link never} * @see {@link throw} * * @param {...T} values Arguments that represent `next` values to be emitted. * @param {Scheduler} [scheduler] A {@link IScheduler} to use for scheduling * the emissions of the `next` notifications. * @return {Observable<T>} An Observable that emits each given input value. * @static true * @name of * @owner Observable */ ArrayObservable.of = function () { var array = []; for (var _i = 0; _i < arguments.length; _i++) { array[_i - 0] = arguments[_i]; } var scheduler = array[array.length - 1]; if (isScheduler_1.isScheduler(scheduler)) { array.pop(); } else { scheduler = null; } var len = array.length; if (len > 1) { return new ArrayObservable(array, scheduler); } else if (len === 1) { return new ScalarObservable_1.ScalarObservable(array[0], scheduler); } else { return new EmptyObservable_1.EmptyObservable(scheduler); } }; ArrayObservable.dispatch = function (state) { var array = state.array, index = state.index, count = state.count, subscriber = state.subscriber; if (index >= count) { subscriber.complete(); return; } subscriber.next(array[index]); if (subscriber.closed) { return; } state.index = index + 1; this.schedule(state); }; ArrayObservable.prototype._subscribe = function (subscriber) { var index = 0; var array = this.array; var count = array.length; var scheduler = this.scheduler; if (scheduler) { return scheduler.schedule(ArrayObservable.dispatch, 0, { array: array, index: index, count: count, subscriber: subscriber }); } else { for (var i = 0; i < count && !subscriber.closed; i++) { subscriber.next(array[i]); } subscriber.complete(); } }; return ArrayObservable; }(Observable_1.Observable)); var ArrayObservable_2 = ArrayObservable; var ArrayObservable_1 = { ArrayObservable: ArrayObservable_2 }; var __extends$8 = (commonjsGlobal && commonjsGlobal.__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 __()); }; /** * We need this JSDoc comment for affecting ESDoc. * @ignore * @extends {Ignored} */ var OuterSubscriber = (function (_super) { __extends$8(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)); var OuterSubscriber_2 = OuterSubscriber; var OuterSubscriber_1 = { OuterSubscriber: OuterSubscriber_2 }; function isPromise$1(value) { return value && typeof value.subscribe !== 'function' && typeof value.then === 'function'; } var isPromise_2 = isPromise$1; var isPromise_1 = { isPromise: isPromise_2 }; function symbolIteratorPonyfill(root$$1) { var Symbol = root$$1.Symbol; if (typeof Symbol === 'function') { if (!Symbol.iterator) { Symbol.iterator = Symbol('iterator polyfill'); } return Symbol.iterator; } else { // [for Mozilla Gecko 27-35:](https://mzl.la/2ewE1zC) var Set_1 = root$$1.Set; if (Set_1 && typeof new Set_1()['@@iterator'] === 'function') { return '@@iterator'; } var Map_1 = root$$1.Map; // required for compatability with es6-shim if (Map_1) { var keys = Object.getOwnPropertyNames(Map_1.prototype); for (var i = 0; i < keys.length; ++i) { var key = keys[i]; // according to spec, Map.prototype[@@iterator] and Map.orototype.entries must be equal. if (key !== 'entries' && key !== 'size' && Map_1.prototype[key] === Map_1.prototype['entries']) { return key; } } } return '@@iterator'; } } var symbolIteratorPonyfill_1 = symbolIteratorPonyfill; var $$iterator = symbolIteratorPonyfill(root.root); var iterator = { symbolIteratorPonyfill: symbolIteratorPonyfill_1, $$iterator: $$iterator }; var __extends$9 = (commonjsGlobal && commonjsGlobal.__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 __()); }; /** * We need this JSDoc comment for affecting ESDoc. * @ignore * @extends {Ignored} */ var InnerSubscriber = (function (_super) { __extends$9(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)); var InnerSubscriber_2 = InnerSubscriber; var InnerSubscriber_1 = { InnerSubscriber: InnerSubscriber_2 }; function subscribeToResult(outerSubscriber, result, outerValue, outerIndex) { var destination = new InnerSubscriber_1.InnerSubscriber(outerSubscriber, outerValue, outerIndex); if (destination.closed) { return null; } if (result instanceof Observable_1.Observable) { if (result._isScalar) { destination.next(result.value); destination.complete(); return null; } else { return result.subscribe(destination); } } else if (isArray.isArray(result)) { for (var i = 0, len = result.length; i < len && !destination.closed; i++) { destination.next(result[i]); } if (!destination.closed) { destination.complete(); } } else if (isPromise_1.isPromise(result)) { result.then(function (value) { if (!destination.closed) { destination.next(value); destination.complete(); } }, function (err) { return destination.error(err); }) .then(null, function (err) { // Escaping the Promise trap: globally throw unhandled errors root.root.setTimeout(function () { throw err; }); }); return destination; } else if (result && typeof result[iterator.$$iterator] === 'function') { var iterator$$1 = result[iterator.$$iterator](); do { var item = iterator$$1.next(); if (item.done) { destination.complete(); break; } destination.next(item.value); if (destination.closed) { break; } } while (true); } else if (result && typeof result[observable.$$observable] === 'function') { var obs = result[observable.$$observable](); if (typeof obs.subscribe !== 'function') { destination.error(new TypeError('Provided object does not correctly implement Symbol.observable')); } else { return obs.subscribe(new InnerSubscriber_1.InnerSubscriber(outerSubscriber, outerValue, outerIndex)); } } else { var value = isObject_1.isObject(result) ? 'an invalid object' : "'" + result + "'"; var msg = ("You provided " + value + " where a stream was expected.") + ' You can provide an Observable, Promise, Array, or Iterable.'; destination.error(new TypeError(msg)); } return null; } var subscribeToResult_2 = subscribeToResult; var subscribeToResult_1 = { subscribeToResult: subscribeToResult_2 }; var __extends$7 = (commonjsGlobal && commonjsGlobal.__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 __()); }; /** * 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 this.lift(new MergeAllOperator(concurrent)); } var mergeAll_2 = mergeAll; var MergeAllOperator = (function () { function MergeAllOperator(concurrent) { this.concurrent = concurrent; } MergeAllOperator.prototype.call = function (observer, source) { return source.subscribe(new MergeAllSubscriber(observer, this.concurrent)); }; return MergeAllOperator; }()); var MergeAllOperator_1 = MergeAllOperator; /** * We need this JSDoc comment for affecting ESDoc. * @ignore * @extends {Ignored} */ var MergeAllSubscriber = (function (_super) { __extends$7(MergeAllSubscriber, _super); function MergeAllSubscriber(destination, concurrent) { _super.call(this, destination); this.concurrent = concurrent; this.hasCompleted = false; this.buffer = []; this.active = 0; } MergeAllSubscriber.prototype._next = function (observable) { if (this.active < this.concurrent) { this.active++; this.add(subscribeToResult_1.subscribeToResult(this, observable)); } else { this.buffer.push(observable); } }; MergeAllSubscriber.prototype._complete = function () { this.hasCompleted = true; if (this.active === 0 && this.buffer.length === 0) { this.destination.complete(); } }; MergeAllSubscriber.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 MergeAllSubscriber; }(OuterSubscriber_1.OuterSubscriber)); var MergeAllSubscriber_1 = MergeAllSubscriber; var mergeAll_1 = { mergeAll: mergeAll_2, MergeAllOperator: MergeAllOperator_1, MergeAllSubscriber: MergeAllSubscriber_1 }; /* tslint:disable: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 (either the source or an * Observable given as argument), 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 = clicks.merge(timer); * clicksOrTimer.subscribe(x => console.log(x)); * * @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 = timer1.merge(timer2, timer3, concurrent); * merged.subscribe(x => console.log(x)); * * @see {@link mergeAll} * @see {@link mergeMap} * @see {@link mergeMapTo} * @see {@link mergeScan} * * @param {Observable} other An input Observable to merge with the source * Observable. More than one input Observables may be given as argument. * @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. * @method merge * @owner Observable */ function merge$2() { var observables = []; for (var _i = 0; _i < arguments.length; _i++) { observables[_i - 0] = arguments[_i]; } return this.lift.call(mergeStatic.apply(void 0, [this].concat(observables))); } var merge_2$1 = merge$2; /* tslint:enable:max-line-length */ /** * Creates an output Observable which concurrently emits all values from every * giv