switchMap.js 1.1 KB

123456789101112131415161718192021222324
  1. import { innerFrom } from '../observable/innerFrom';
  2. import { operate } from '../util/lift';
  3. import { createOperatorSubscriber } from './OperatorSubscriber';
  4. export function switchMap(project, resultSelector) {
  5. return operate((source, subscriber) => {
  6. let innerSubscriber = null;
  7. let index = 0;
  8. let isComplete = false;
  9. const checkComplete = () => isComplete && !innerSubscriber && subscriber.complete();
  10. source.subscribe(createOperatorSubscriber(subscriber, (value) => {
  11. innerSubscriber === null || innerSubscriber === void 0 ? void 0 : innerSubscriber.unsubscribe();
  12. let innerIndex = 0;
  13. const outerIndex = index++;
  14. innerFrom(project(value, outerIndex)).subscribe((innerSubscriber = createOperatorSubscriber(subscriber, (innerValue) => subscriber.next(resultSelector ? resultSelector(value, innerValue, outerIndex, innerIndex++) : innerValue), () => {
  15. innerSubscriber = null;
  16. checkComplete();
  17. })));
  18. }, () => {
  19. isComplete = true;
  20. checkComplete();
  21. }));
  22. });
  23. }
  24. //# sourceMappingURL=switchMap.js.map