Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

switchMap.js 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. "use strict";
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = function (d, b) {
  4. extendStatics = Object.setPrototypeOf ||
  5. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  6. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  7. return extendStatics(d, b);
  8. }
  9. return function (d, b) {
  10. extendStatics(d, b);
  11. function __() { this.constructor = d; }
  12. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  13. };
  14. })();
  15. Object.defineProperty(exports, "__esModule", { value: true });
  16. var OuterSubscriber_1 = require("../OuterSubscriber");
  17. var InnerSubscriber_1 = require("../InnerSubscriber");
  18. var subscribeToResult_1 = require("../util/subscribeToResult");
  19. var map_1 = require("./map");
  20. var from_1 = require("../observable/from");
  21. function switchMap(project, resultSelector) {
  22. if (typeof resultSelector === 'function') {
  23. return function (source) { return source.pipe(switchMap(function (a, i) { return from_1.from(project(a, i)).pipe(map_1.map(function (b, ii) { return resultSelector(a, b, i, ii); })); })); };
  24. }
  25. return function (source) { return source.lift(new SwitchMapOperator(project)); };
  26. }
  27. exports.switchMap = switchMap;
  28. var SwitchMapOperator = (function () {
  29. function SwitchMapOperator(project) {
  30. this.project = project;
  31. }
  32. SwitchMapOperator.prototype.call = function (subscriber, source) {
  33. return source.subscribe(new SwitchMapSubscriber(subscriber, this.project));
  34. };
  35. return SwitchMapOperator;
  36. }());
  37. var SwitchMapSubscriber = (function (_super) {
  38. __extends(SwitchMapSubscriber, _super);
  39. function SwitchMapSubscriber(destination, project) {
  40. var _this = _super.call(this, destination) || this;
  41. _this.project = project;
  42. _this.index = 0;
  43. return _this;
  44. }
  45. SwitchMapSubscriber.prototype._next = function (value) {
  46. var result;
  47. var index = this.index++;
  48. try {
  49. result = this.project(value, index);
  50. }
  51. catch (error) {
  52. this.destination.error(error);
  53. return;
  54. }
  55. this._innerSub(result, value, index);
  56. };
  57. SwitchMapSubscriber.prototype._innerSub = function (result, value, index) {
  58. var innerSubscription = this.innerSubscription;
  59. if (innerSubscription) {
  60. innerSubscription.unsubscribe();
  61. }
  62. var innerSubscriber = new InnerSubscriber_1.InnerSubscriber(this, undefined, undefined);
  63. var destination = this.destination;
  64. destination.add(innerSubscriber);
  65. this.innerSubscription = subscribeToResult_1.subscribeToResult(this, result, value, index, innerSubscriber);
  66. };
  67. SwitchMapSubscriber.prototype._complete = function () {
  68. var innerSubscription = this.innerSubscription;
  69. if (!innerSubscription || innerSubscription.closed) {
  70. _super.prototype._complete.call(this);
  71. }
  72. this.unsubscribe();
  73. };
  74. SwitchMapSubscriber.prototype._unsubscribe = function () {
  75. this.innerSubscription = null;
  76. };
  77. SwitchMapSubscriber.prototype.notifyComplete = function (innerSub) {
  78. var destination = this.destination;
  79. destination.remove(innerSub);
  80. this.innerSubscription = null;
  81. if (this.isStopped) {
  82. _super.prototype._complete.call(this);
  83. }
  84. };
  85. SwitchMapSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
  86. this.destination.next(innerValue);
  87. };
  88. return SwitchMapSubscriber;
  89. }(OuterSubscriber_1.OuterSubscriber));
  90. //# sourceMappingURL=switchMap.js.map