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OAAO,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;QACxB,2BAAM,EAAE,mCAAY,CAAa;QACzC,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAC1B,MAAM,CAAC,QAAQ,EAAE,CAAC;QAClB,YAAY,CAAC,WAAW,EAAE,CAAC;IAC7B,CAAC;IACH,6BAAC;AAAD,CAAC,AA5HD,CAA2C,iCAAe,GA4HzD","sourcesContent":["import { Operator } from '../Operator';\nimport { Subscriber } from '../Subscriber';\nimport { Observable } from '../Observable';\nimport { Subject } from '../Subject';\nimport { Subscription } from '../Subscription';\nimport { tryCatch } from '../util/tryCatch';\nimport { errorObject } from '../util/errorObject';\nimport { OuterSubscriber } from '../OuterSubscriber';\nimport { InnerSubscriber } from '../InnerSubscriber';\nimport { subscribeToResult } from '../util/subscribeToResult';\nimport { OperatorFunction } from '../interfaces';\n\n/**\n * Branch out the source Observable values as a nested Observable starting from\n * an emission from `openings` and ending when the output of `closingSelector`\n * emits.\n *\n * <span class=\"informal\">It's like {@link bufferToggle}, but emits a nested\n * Observable instead of an array.</span>\n *\n * <img src=\"./img/windowToggle.png\" width=\"100%\">\n *\n * Returns an Observable that emits windows of items it collects from the source\n * Observable. The output Observable emits windows that contain those items\n * emitted by the source Observable between the time when the `openings`\n * Observable emits an item and when the Observable returned by\n * `closingSelector` emits an item.\n *\n * @example <caption>Every other second, emit the click events from the next 500ms</caption>\n * var clicks = Rx.Observable.fromEvent(document, 'click');\n * var openings = Rx.Observable.interval(1000);\n * var result = clicks.windowToggle(openings, i =>\n * i % 2 ? Rx.Observable.interval(500) : Rx.Observable.empty()\n * ).mergeAll();\n * result.subscribe(x => console.log(x));\n *\n * @see {@link window}\n * @see {@link windowCount}\n * @see {@link windowTime}\n * @see {@link windowWhen}\n * @see {@link bufferToggle}\n *\n * @param {Observable<O>} openings An observable of notifications to start new\n * windows.\n * @param {function(value: O): Observable} closingSelector A function that takes\n * the value emitted by the `openings` observable and returns an Observable,\n * which, when it emits (either `next` or `complete`), signals that the\n * associated window should complete.\n * @return {Observable<Observable<T>>} An observable of windows, which in turn\n * are Observables.\n * @method windowToggle\n * @owner Observable\n */\nexport function windowToggle<T, O>(openings: Observable<O>,\n closingSelector: (openValue: O) => Observable<any>): OperatorFunction<T, Observable<T>> {\n return (source: Observable<T>) => source.lift(new WindowToggleOperator<T, O>(openings, closingSelector));\n}\n\nclass WindowToggleOperator<T, O> implements Operator<T, Observable<T>> {\n\n constructor(private openings: Observable<O>,\n private closingSelector: (openValue: O) => Observable<any>) {\n }\n\n call(subscriber: Subscriber<Observable<T>>, source: any): any {\n return source.subscribe(new WindowToggleSubscriber(\n subscriber, this.openings, this.closingSelector\n ));\n }\n}\n\ninterface WindowContext<T> {\n window: Subject<T>;\n subscription: Subscription;\n}\n\n/**\n * We need this JSDoc comment for affecting ESDoc.\n * @ignore\n * @extends {Ignored}\n */\nclass WindowToggleSubscriber<T, O> extends OuterSubscriber<T, any> {\n private contexts: WindowContext<T>[] = [];\n private openSubscription: Subscription;\n\n constructor(destination: Subscriber<Observable<T>>,\n private openings: Observable<O>,\n private closingSelector: (openValue: O) => Observable<any>) {\n super(destination);\n this.add(this.openSubscription = subscribeToResult(this, openings, openings));\n }\n\n protected _next(value: T) {\n const { contexts } = this;\n if (contexts) {\n const len = contexts.length;\n for (let i = 0; i < len; i++) {\n contexts[i].window.next(value);\n }\n }\n }\n\n protected _error(err: any) {\n\n const { contexts } = this;\n this.contexts = null;\n\n if (contexts) {\n const len = contexts.length;\n let index = -1;\n\n while (++index < len) {\n const context = contexts[index];\n context.window.error(err);\n context.subscription.unsubscribe();\n }\n }\n\n super._error(err);\n }\n\n protected _complete() {\n const { contexts } = this;\n this.contexts = null;\n if (contexts) {\n const len = contexts.length;\n let index = -1;\n while (++index < len) {\n const context = contexts[index];\n context.window.complete();\n context.subscription.unsubscribe();\n }\n }\n super._complete();\n }\n\n /** @deprecated internal use only */ _unsubscribe() {\n const { contexts } = this;\n this.contexts = null;\n if (contexts) {\n const len = contexts.length;\n let index = -1;\n while (++index < len) {\n const context = contexts[index];\n context.window.unsubscribe();\n context.subscription.unsubscribe();\n }\n }\n }\n\n notifyNext(outerValue: any, innerValue: any,\n outerIndex: number, innerIndex: number,\n innerSub: InnerSubscriber<T, any>): void {\n\n if (outerValue === this.openings) {\n\n const { closingSelector } = this;\n const closingNotifier = tryCatch(closingSelector)(innerValue);\n\n if (closingNotifier === errorObject) {\n return this.error(errorObject.e);\n } else {\n const window = new Subject<T>();\n const subscription = new Subscription();\n const context = { window, subscription };\n this.contexts.push(context);\n const innerSubscription = subscribeToResult(this, closingNotifier, context);\n\n if (innerSubscription.closed) {\n this.closeWindow(this.contexts.length - 1);\n } else {\n (<any> innerSubscription).context = context;\n subscription.add(innerSubscription);\n }\n\n this.destination.next(window);\n\n }\n } else {\n this.closeWindow(this.contexts.indexOf(outerValue));\n }\n }\n\n notifyError(err: any): void {\n this.error(err);\n }\n\n notifyComplete(inner: Subscription): void {\n if (inner !== this.openSubscription) {\n this.closeWindow(this.contexts.indexOf((<any> inner).context));\n }\n }\n\n private closeWindow(index: number): void {\n if (index === -1) {\n return;\n }\n\n const { contexts } = this;\n const context = contexts[index];\n const { window, subscription } = context;\n contexts.splice(index, 1);\n window.complete();\n subscription.unsubscribe();\n }\n}\n"]} |