Debian Codegraph @

node/rxjs/dist/esm/internal/operators/withLatestFrom.js

raw
1 import { operate } from '../util/lift';
2 import { createOperatorSubscriber } from './OperatorSubscriber';
3 import { innerFrom } from '../observable/innerFrom';
4 import { identity } from '../util/identity';
5 import { noop } from '../util/noop';
6 import { popResultSelector } from '../util/args';
7 export function withLatestFrom(...inputs) {
8 const project = popResultSelector(inputs);
9 return operate((source, subscriber) => {
10 const len = inputs.length;
11 const otherValues = new Array(len);
12 let hasValue = inputs.map(() => false);
13 let ready = false;
14 for (let i = 0; i < len; i++) {
15 innerFrom(inputs[i]).subscribe(createOperatorSubscriber(subscriber, (value) => {
16 otherValues[i] = value;
17 if (!ready && !hasValue[i]) {
18 hasValue[i] = true;
19 (ready = hasValue.every(identity)) && (hasValue = null);
20 }
21 }, noop));
22 }
23 source.subscribe(createOperatorSubscriber(subscriber, (value) => {
24 if (ready) {
25 const values = [value, ...otherValues];
26 subscriber.next(project ? project(...values) : values);
27 }
28 }));
29 });
30 }
31 //# sourceMappingURL=withLatestFrom.js.map