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.

forkJoin.js 3.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 Observable_1 = require("../Observable");
  17. var isArray_1 = require("../util/isArray");
  18. var empty_1 = require("./empty");
  19. var subscribeToResult_1 = require("../util/subscribeToResult");
  20. var OuterSubscriber_1 = require("../OuterSubscriber");
  21. var map_1 = require("../operators/map");
  22. function forkJoin() {
  23. var sources = [];
  24. for (var _i = 0; _i < arguments.length; _i++) {
  25. sources[_i] = arguments[_i];
  26. }
  27. var resultSelector;
  28. if (typeof sources[sources.length - 1] === 'function') {
  29. resultSelector = sources.pop();
  30. }
  31. if (sources.length === 1 && isArray_1.isArray(sources[0])) {
  32. sources = sources[0];
  33. }
  34. if (sources.length === 0) {
  35. return empty_1.EMPTY;
  36. }
  37. if (resultSelector) {
  38. return forkJoin(sources).pipe(map_1.map(function (args) { return resultSelector.apply(void 0, args); }));
  39. }
  40. return new Observable_1.Observable(function (subscriber) {
  41. return new ForkJoinSubscriber(subscriber, sources);
  42. });
  43. }
  44. exports.forkJoin = forkJoin;
  45. var ForkJoinSubscriber = (function (_super) {
  46. __extends(ForkJoinSubscriber, _super);
  47. function ForkJoinSubscriber(destination, sources) {
  48. var _this = _super.call(this, destination) || this;
  49. _this.sources = sources;
  50. _this.completed = 0;
  51. _this.haveValues = 0;
  52. var len = sources.length;
  53. _this.values = new Array(len);
  54. for (var i = 0; i < len; i++) {
  55. var source = sources[i];
  56. var innerSubscription = subscribeToResult_1.subscribeToResult(_this, source, null, i);
  57. if (innerSubscription) {
  58. _this.add(innerSubscription);
  59. }
  60. }
  61. return _this;
  62. }
  63. ForkJoinSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
  64. this.values[outerIndex] = innerValue;
  65. if (!innerSub._hasValue) {
  66. innerSub._hasValue = true;
  67. this.haveValues++;
  68. }
  69. };
  70. ForkJoinSubscriber.prototype.notifyComplete = function (innerSub) {
  71. var _a = this, destination = _a.destination, haveValues = _a.haveValues, values = _a.values;
  72. var len = values.length;
  73. if (!innerSub._hasValue) {
  74. destination.complete();
  75. return;
  76. }
  77. this.completed++;
  78. if (this.completed !== len) {
  79. return;
  80. }
  81. if (haveValues === len) {
  82. destination.next(values);
  83. }
  84. destination.complete();
  85. };
  86. return ForkJoinSubscriber;
  87. }(OuterSubscriber_1.OuterSubscriber));
  88. //# sourceMappingURL=forkJoin.js.map