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.

withLatestFrom.js 3.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 subscribeToResult_1 = require("../util/subscribeToResult");
  18. function withLatestFrom() {
  19. var args = [];
  20. for (var _i = 0; _i < arguments.length; _i++) {
  21. args[_i] = arguments[_i];
  22. }
  23. return function (source) {
  24. var project;
  25. if (typeof args[args.length - 1] === 'function') {
  26. project = args.pop();
  27. }
  28. var observables = args;
  29. return source.lift(new WithLatestFromOperator(observables, project));
  30. };
  31. }
  32. exports.withLatestFrom = withLatestFrom;
  33. var WithLatestFromOperator = (function () {
  34. function WithLatestFromOperator(observables, project) {
  35. this.observables = observables;
  36. this.project = project;
  37. }
  38. WithLatestFromOperator.prototype.call = function (subscriber, source) {
  39. return source.subscribe(new WithLatestFromSubscriber(subscriber, this.observables, this.project));
  40. };
  41. return WithLatestFromOperator;
  42. }());
  43. var WithLatestFromSubscriber = (function (_super) {
  44. __extends(WithLatestFromSubscriber, _super);
  45. function WithLatestFromSubscriber(destination, observables, project) {
  46. var _this = _super.call(this, destination) || this;
  47. _this.observables = observables;
  48. _this.project = project;
  49. _this.toRespond = [];
  50. var len = observables.length;
  51. _this.values = new Array(len);
  52. for (var i = 0; i < len; i++) {
  53. _this.toRespond.push(i);
  54. }
  55. for (var i = 0; i < len; i++) {
  56. var observable = observables[i];
  57. _this.add(subscribeToResult_1.subscribeToResult(_this, observable, observable, i));
  58. }
  59. return _this;
  60. }
  61. WithLatestFromSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
  62. this.values[outerIndex] = innerValue;
  63. var toRespond = this.toRespond;
  64. if (toRespond.length > 0) {
  65. var found = toRespond.indexOf(outerIndex);
  66. if (found !== -1) {
  67. toRespond.splice(found, 1);
  68. }
  69. }
  70. };
  71. WithLatestFromSubscriber.prototype.notifyComplete = function () {
  72. };
  73. WithLatestFromSubscriber.prototype._next = function (value) {
  74. if (this.toRespond.length === 0) {
  75. var args = [value].concat(this.values);
  76. if (this.project) {
  77. this._tryProject(args);
  78. }
  79. else {
  80. this.destination.next(args);
  81. }
  82. }
  83. };
  84. WithLatestFromSubscriber.prototype._tryProject = function (args) {
  85. var result;
  86. try {
  87. result = this.project.apply(this, args);
  88. }
  89. catch (err) {
  90. this.destination.error(err);
  91. return;
  92. }
  93. this.destination.next(result);
  94. };
  95. return WithLatestFromSubscriber;
  96. }(OuterSubscriber_1.OuterSubscriber));
  97. //# sourceMappingURL=withLatestFrom.js.map