withLatestFrom.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. "use strict";
  2. var __read = (this && this.__read) || function (o, n) {
  3. var m = typeof Symbol === "function" && o[Symbol.iterator];
  4. if (!m) return o;
  5. var i = m.call(o), r, ar = [], e;
  6. try {
  7. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  8. }
  9. catch (error) { e = { error: error }; }
  10. finally {
  11. try {
  12. if (r && !r.done && (m = i["return"])) m.call(i);
  13. }
  14. finally { if (e) throw e.error; }
  15. }
  16. return ar;
  17. };
  18. var __spreadArray = (this && this.__spreadArray) || function (to, from) {
  19. for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
  20. to[j] = from[i];
  21. return to;
  22. };
  23. Object.defineProperty(exports, "__esModule", { value: true });
  24. exports.withLatestFrom = void 0;
  25. var lift_1 = require("../util/lift");
  26. var OperatorSubscriber_1 = require("./OperatorSubscriber");
  27. var innerFrom_1 = require("../observable/innerFrom");
  28. var identity_1 = require("../util/identity");
  29. var noop_1 = require("../util/noop");
  30. var args_1 = require("../util/args");
  31. function withLatestFrom() {
  32. var inputs = [];
  33. for (var _i = 0; _i < arguments.length; _i++) {
  34. inputs[_i] = arguments[_i];
  35. }
  36. var project = args_1.popResultSelector(inputs);
  37. return lift_1.operate(function (source, subscriber) {
  38. var len = inputs.length;
  39. var otherValues = new Array(len);
  40. var hasValue = inputs.map(function () { return false; });
  41. var ready = false;
  42. var _loop_1 = function (i) {
  43. innerFrom_1.innerFrom(inputs[i]).subscribe(OperatorSubscriber_1.createOperatorSubscriber(subscriber, function (value) {
  44. otherValues[i] = value;
  45. if (!ready && !hasValue[i]) {
  46. hasValue[i] = true;
  47. (ready = hasValue.every(identity_1.identity)) && (hasValue = null);
  48. }
  49. }, noop_1.noop));
  50. };
  51. for (var i = 0; i < len; i++) {
  52. _loop_1(i);
  53. }
  54. source.subscribe(OperatorSubscriber_1.createOperatorSubscriber(subscriber, function (value) {
  55. if (ready) {
  56. var values = __spreadArray([value], __read(otherValues));
  57. subscriber.next(project ? project.apply(void 0, __spreadArray([], __read(values))) : values);
  58. }
  59. }));
  60. });
  61. }
  62. exports.withLatestFrom = withLatestFrom;
  63. //# sourceMappingURL=withLatestFrom.js.map