switchMap.js 1.4 KB

12345678910111213141516171819202122232425262728
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.switchMap = void 0;
  4. var innerFrom_1 = require("../observable/innerFrom");
  5. var lift_1 = require("../util/lift");
  6. var OperatorSubscriber_1 = require("./OperatorSubscriber");
  7. function switchMap(project, resultSelector) {
  8. return lift_1.operate(function (source, subscriber) {
  9. var innerSubscriber = null;
  10. var index = 0;
  11. var isComplete = false;
  12. var checkComplete = function () { return isComplete && !innerSubscriber && subscriber.complete(); };
  13. source.subscribe(OperatorSubscriber_1.createOperatorSubscriber(subscriber, function (value) {
  14. innerSubscriber === null || innerSubscriber === void 0 ? void 0 : innerSubscriber.unsubscribe();
  15. var innerIndex = 0;
  16. var outerIndex = index++;
  17. innerFrom_1.innerFrom(project(value, outerIndex)).subscribe((innerSubscriber = OperatorSubscriber_1.createOperatorSubscriber(subscriber, function (innerValue) { return subscriber.next(resultSelector ? resultSelector(value, innerValue, outerIndex, innerIndex++) : innerValue); }, function () {
  18. innerSubscriber = null;
  19. checkComplete();
  20. })));
  21. }, function () {
  22. isComplete = true;
  23. checkComplete();
  24. }));
  25. });
  26. }
  27. exports.switchMap = switchMap;
  28. //# sourceMappingURL=switchMap.js.map