wishthis/node_modules/rxjs/dist/cjs/internal/operators/withLatestFrom.js
2022-06-08 12:36:39 +02:00

63 lines
No EOL
2.4 KiB
JavaScript

"use strict";
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
to[j] = from[i];
return to;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.withLatestFrom = void 0;
var lift_1 = require("../util/lift");
var OperatorSubscriber_1 = require("./OperatorSubscriber");
var innerFrom_1 = require("../observable/innerFrom");
var identity_1 = require("../util/identity");
var noop_1 = require("../util/noop");
var args_1 = require("../util/args");
function withLatestFrom() {
var inputs = [];
for (var _i = 0; _i < arguments.length; _i++) {
inputs[_i] = arguments[_i];
}
var project = args_1.popResultSelector(inputs);
return lift_1.operate(function (source, subscriber) {
var len = inputs.length;
var otherValues = new Array(len);
var hasValue = inputs.map(function () { return false; });
var ready = false;
var _loop_1 = function (i) {
innerFrom_1.innerFrom(inputs[i]).subscribe(OperatorSubscriber_1.createOperatorSubscriber(subscriber, function (value) {
otherValues[i] = value;
if (!ready && !hasValue[i]) {
hasValue[i] = true;
(ready = hasValue.every(identity_1.identity)) && (hasValue = null);
}
}, noop_1.noop));
};
for (var i = 0; i < len; i++) {
_loop_1(i);
}
source.subscribe(OperatorSubscriber_1.createOperatorSubscriber(subscriber, function (value) {
if (ready) {
var values = __spreadArray([value], __read(otherValues));
subscriber.next(project ? project.apply(void 0, __spreadArray([], __read(values))) : values);
}
}));
});
}
exports.withLatestFrom = withLatestFrom;
//# sourceMappingURL=withLatestFrom.js.map