{"ast":null,"code":"import { OuterSubscriber } from '../OuterSubscriber';\nimport { InnerSubscriber } from '../InnerSubscriber';\nimport { subscribeToResult } from '../util/subscribeToResult';\nimport { map } from './map';\nimport { from } from '../observable/from';\nexport function switchMap(project, resultSelector) {\n  if (typeof resultSelector === 'function') {\n    return source => source.pipe(switchMap((a, i) => from(project(a, i)).pipe(map((b, ii) => resultSelector(a, b, i, ii)))));\n  }\n\n  return source => source.lift(new SwitchMapOperator(project));\n}\n\nclass SwitchMapOperator {\n  constructor(project) {\n    this.project = project;\n  }\n\n  call(subscriber, source) {\n    return source.subscribe(new SwitchMapSubscriber(subscriber, this.project));\n  }\n\n}\n\nclass SwitchMapSubscriber extends OuterSubscriber {\n  constructor(destination, project) {\n    super(destination);\n    this.project = project;\n    this.index = 0;\n  }\n\n  _next(value) {\n    let result;\n    const index = this.index++;\n\n    try {\n      result = this.project(value, index);\n    } catch (error) {\n      this.destination.error(error);\n      return;\n    }\n\n    this._innerSub(result, value, index);\n  }\n\n  _innerSub(result, value, index) {\n    const innerSubscription = this.innerSubscription;\n\n    if (innerSubscription) {\n      innerSubscription.unsubscribe();\n    }\n\n    const innerSubscriber = new InnerSubscriber(this, value, index);\n    const destination = this.destination;\n    destination.add(innerSubscriber);\n    this.innerSubscription = subscribeToResult(this, result, undefined, undefined, innerSubscriber);\n\n    if (this.innerSubscription !== innerSubscriber) {\n      destination.add(this.innerSubscription);\n    }\n  }\n\n  _complete() {\n    const {\n      innerSubscription\n    } = this;\n\n    if (!innerSubscription || innerSubscription.closed) {\n      super._complete();\n    }\n\n    this.unsubscribe();\n  }\n\n  _unsubscribe() {\n    this.innerSubscription = null;\n  }\n\n  notifyComplete(innerSub) {\n    const destination = this.destination;\n    destination.remove(innerSub);\n    this.innerSubscription = null;\n\n    if (this.isStopped) {\n      super._complete();\n    }\n  }\n\n  notifyNext(outerValue, innerValue, outerIndex, innerIndex, innerSub) {\n    this.destination.next(innerValue);\n  }\n\n} //# sourceMappingURL=switchMap.js.map","map":null,"metadata":{},"sourceType":"module"}