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.

exhaustMap.js 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 exhaustMap(project, resultSelector) {
  22. if (resultSelector) {
  23. return function (source) { return source.pipe(exhaustMap(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) {
  26. return source.lift(new ExhauseMapOperator(project));
  27. };
  28. }
  29. exports.exhaustMap = exhaustMap;
  30. var ExhauseMapOperator = (function () {
  31. function ExhauseMapOperator(project) {
  32. this.project = project;
  33. }
  34. ExhauseMapOperator.prototype.call = function (subscriber, source) {
  35. return source.subscribe(new ExhaustMapSubscriber(subscriber, this.project));
  36. };
  37. return ExhauseMapOperator;
  38. }());
  39. var ExhaustMapSubscriber = (function (_super) {
  40. __extends(ExhaustMapSubscriber, _super);
  41. function ExhaustMapSubscriber(destination, project) {
  42. var _this = _super.call(this, destination) || this;
  43. _this.project = project;
  44. _this.hasSubscription = false;
  45. _this.hasCompleted = false;
  46. _this.index = 0;
  47. return _this;
  48. }
  49. ExhaustMapSubscriber.prototype._next = function (value) {
  50. if (!this.hasSubscription) {
  51. this.tryNext(value);
  52. }
  53. };
  54. ExhaustMapSubscriber.prototype.tryNext = function (value) {
  55. var result;
  56. var index = this.index++;
  57. try {
  58. result = this.project(value, index);
  59. }
  60. catch (err) {
  61. this.destination.error(err);
  62. return;
  63. }
  64. this.hasSubscription = true;
  65. this._innerSub(result, value, index);
  66. };
  67. ExhaustMapSubscriber.prototype._innerSub = function (result, value, index) {
  68. var innerSubscriber = new InnerSubscriber_1.InnerSubscriber(this, undefined, undefined);
  69. var destination = this.destination;
  70. destination.add(innerSubscriber);
  71. subscribeToResult_1.subscribeToResult(this, result, value, index, innerSubscriber);
  72. };
  73. ExhaustMapSubscriber.prototype._complete = function () {
  74. this.hasCompleted = true;
  75. if (!this.hasSubscription) {
  76. this.destination.complete();
  77. }
  78. this.unsubscribe();
  79. };
  80. ExhaustMapSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
  81. this.destination.next(innerValue);
  82. };
  83. ExhaustMapSubscriber.prototype.notifyError = function (err) {
  84. this.destination.error(err);
  85. };
  86. ExhaustMapSubscriber.prototype.notifyComplete = function (innerSub) {
  87. var destination = this.destination;
  88. destination.remove(innerSub);
  89. this.hasSubscription = false;
  90. if (this.hasCompleted) {
  91. this.destination.complete();
  92. }
  93. };
  94. return ExhaustMapSubscriber;
  95. }(OuterSubscriber_1.OuterSubscriber));
  96. //# sourceMappingURL=exhaustMap.js.map