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IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACxB,CAAC;QAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;YACrB,wEAAwE;YACxE,8CAA8C;YAC9C,IAAI,CAAC,QAAQ,GAAG,CAAC,MAAM,CAAC,CAAC;QAC3B,CAAC;QAAC,IAAI,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;YAC3C,0EAA0E;YAC1E,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACxB,CAAC;IACH,CAAC;IAzLa,kBAAK,GAAiB,CAAC,UAAS,KAAU;QACtD,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC;QACpB,MAAM,CAAC,KAAK,CAAC;IACf,CAAC,CAAC,IAAI,YAAY,EAAE,CAAC,CAAC,CAAC;IAuLzB,mBAAC;AAAD,CAAC,AA3LD,IA2LC;AA3LY,oBAAY,eA2LxB,CAAA;AAED,qCAAqC,MAAa;IACjD,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,UAAC,IAAI,EAAE,GAAG,IAAK,OAAA,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,YAAY,yCAAmB,CAAC,GAAG,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,EAApE,CAAoE,EAAE,EAAE,CAAC,CAAC;AAC/G,CAAC","sourcesContent":["import { isArray } from './util/isArray';\nimport { isObject } from './util/isObject';\nimport { isFunction } from './util/isFunction';\nimport { tryCatch } from './util/tryCatch';\nimport { errorObject } from './util/errorObject';\nimport { UnsubscriptionError } from './util/UnsubscriptionError';\n\nexport interface AnonymousSubscription {\n unsubscribe(): void;\n}\n\nexport type TeardownLogic = AnonymousSubscription | Function | void;\n\nexport interface ISubscription extends AnonymousSubscription {\n unsubscribe(): void;\n readonly closed: boolean;\n}\n\n/**\n * Represents a disposable resource, such as the execution of an Observable. A\n * Subscription has one important method, `unsubscribe`, that takes no argument\n * and just disposes the resource held by the subscription.\n *\n * Additionally, subscriptions may be grouped together through the `add()`\n * method, which will attach a child Subscription to the current Subscription.\n * When a Subscription is unsubscribed, all its children (and its grandchildren)\n * will be unsubscribed as well.\n *\n * @class Subscription\n */\nexport class Subscription implements ISubscription {\n public static EMPTY: Subscription = (function(empty: any){\n empty.closed = true;\n return empty;\n }(new Subscription()));\n\n /**\n * A flag to indicate whether this Subscription has already been unsubscribed.\n * @type {boolean}\n */\n public closed: boolean = false;\n\n protected _parent: Subscription = null;\n protected _parents: Subscription[] = null;\n private _subscriptions: ISubscription[] = null;\n\n /**\n * @param {function(): void} [unsubscribe] A function describing how to\n * perform the disposal of resources when the `unsubscribe` method is called.\n */\n constructor(unsubscribe?: () => void) {\n if (unsubscribe) {\n (<any> this)._unsubscribe = unsubscribe;\n }\n }\n\n /**\n * Disposes the resources held by the subscription. May, for instance, cancel\n * an ongoing Observable execution or cancel any other type of work that\n * started when the Subscription was created.\n * @return {void}\n */\n unsubscribe(): void {\n let hasErrors = false;\n let errors: any[];\n\n if (this.closed) {\n return;\n }\n\n let { _parent, _parents, _unsubscribe, _subscriptions } = (<any> this);\n\n this.closed = true;\n this._parent = null;\n this._parents = null;\n // null out _subscriptions first so any child subscriptions that attempt\n // to remove themselves from this subscription will noop\n this._subscriptions = null;\n\n let index = -1;\n let len = _parents ? _parents.length : 0;\n\n // if this._parent is null, then so is this._parents, and we\n // don't have to remove ourselves from any parent subscriptions.\n while (_parent) {\n _parent.remove(this);\n // if this._parents is null or index >= len,\n // then _parent is set to null, and the loop exits\n _parent = ++index < len && _parents[index] || null;\n }\n\n if (isFunction(_unsubscribe)) {\n let trial = tryCatch(_unsubscribe).call(this);\n if (trial === errorObject) {\n hasErrors = true;\n errors = errors || (\n errorObject.e instanceof UnsubscriptionError ?\n flattenUnsubscriptionErrors(errorObject.e.errors) : [errorObject.e]\n );\n }\n }\n\n if (isArray(_subscriptions)) {\n\n index = -1;\n len = _subscriptions.length;\n\n while (++index < len) {\n const sub = _subscriptions[index];\n if (isObject(sub)) {\n let trial = tryCatch(sub.unsubscribe).call(sub);\n if (trial === errorObject) {\n hasErrors = true;\n errors = errors || [];\n let err = errorObject.e;\n if (err instanceof UnsubscriptionError) {\n errors = errors.concat(flattenUnsubscriptionErrors(err.errors));\n } else {\n errors.push(err);\n }\n }\n }\n }\n }\n\n if (hasErrors) {\n throw new UnsubscriptionError(errors);\n }\n }\n\n /**\n * Adds a tear down to be called during the unsubscribe() of this\n * Subscription.\n *\n * If the tear down being added is a subscription that is already\n * unsubscribed, is the same reference `add` is being called on, or is\n * `Subscription.EMPTY`, it will not be added.\n *\n * If this subscription is already in an `closed` state, the passed\n * tear down logic will be executed immediately.\n *\n * @param {TeardownLogic} teardown The additional logic to execute on\n * teardown.\n * @return {Subscription} Returns the Subscription used or created to be\n * added to the inner subscriptions list. This Subscription can be used with\n * `remove()` to remove the passed teardown logic from the inner subscriptions\n * list.\n */\n add(teardown: TeardownLogic): Subscription {\n if (!teardown || (teardown === Subscription.EMPTY)) {\n return Subscription.EMPTY;\n }\n\n if (teardown === this) {\n return this;\n }\n\n let subscription = (<Subscription> teardown);\n\n switch (typeof teardown) {\n case 'function':\n subscription = new Subscription(<(() => void) > teardown);\n case 'object':\n if (subscription.closed || typeof subscription.unsubscribe !== 'function') {\n return subscription;\n } else if (this.closed) {\n subscription.unsubscribe();\n return subscription;\n } else if (typeof subscription._addParent !== 'function' /* quack quack */) {\n const tmp = subscription;\n subscription = new Subscription();\n subscription._subscriptions = [tmp];\n }\n break;\n default:\n throw new Error('unrecognized teardown ' + teardown + ' added to Subscription.');\n }\n\n const subscriptions = this._subscriptions || (this._subscriptions = []);\n\n subscriptions.push(subscription);\n subscription._addParent(this);\n\n return subscription;\n }\n\n /**\n * Removes a Subscription from the internal list of subscriptions that will\n * unsubscribe during the unsubscribe process of this Subscription.\n * @param {Subscription} subscription The subscription to remove.\n * @return {void}\n */\n remove(subscription: Subscription): void {\n const subscriptions = this._subscriptions;\n if (subscriptions) {\n const subscriptionIndex = subscriptions.indexOf(subscription);\n if (subscriptionIndex !== -1) {\n subscriptions.splice(subscriptionIndex, 1);\n }\n }\n }\n\n private _addParent(parent: Subscription) {\n let { _parent, _parents } = this;\n if (!_parent || _parent === parent) {\n // If we don't have a parent, or the new parent is the same as the\n // current parent, then set this._parent to the new parent.\n this._parent = parent;\n } else if (!_parents) {\n // If there's already one parent, but not multiple, allocate an Array to\n // store the rest of the parent Subscriptions.\n this._parents = [parent];\n } else if (_parents.indexOf(parent) === -1) {\n // Only add the new parent to the _parents list if it's not already there.\n _parents.push(parent);\n }\n }\n}\n\nfunction flattenUnsubscriptionErrors(errors: any[]) {\n return errors.reduce((errs, err) => errs.concat((err instanceof UnsubscriptionError) ? err.errors : err), []);\n}\n"]}