1 import { OuterSubscriber } from '../OuterSubscriber';
2 import { subscribeToResult } from '../util/subscribeToResult';
3 export function withLatestFrom(...args) {
6 if (typeof args[args.length - 1] === 'function') {
9 const observables = args;
10 return source.lift(new WithLatestFromOperator(observables, project));
13 class WithLatestFromOperator {
14 constructor(observables, project) {
15 this.observables = observables;
16 this.project = project;
18 call(subscriber, source) {
19 return source.subscribe(new WithLatestFromSubscriber(subscriber, this.observables, this.project));
22 class WithLatestFromSubscriber extends OuterSubscriber {
23 constructor(destination, observables, project) {
25 this.observables = observables;
26 this.project = project;
28 const len = observables.length;
29 this.values = new Array(len);
30 for (let i = 0; i < len; i++) {
31 this.toRespond.push(i);
33 for (let i = 0; i < len; i++) {
34 let observable = observables[i];
35 this.add(subscribeToResult(this, observable, observable, i));
38 notifyNext(outerValue, innerValue, outerIndex, innerIndex, innerSub) {
39 this.values[outerIndex] = innerValue;
40 const toRespond = this.toRespond;
41 if (toRespond.length > 0) {
42 const found = toRespond.indexOf(outerIndex);
44 toRespond.splice(found, 1);
51 if (this.toRespond.length === 0) {
52 const args = [value, ...this.values];
54 this._tryProject(args);
57 this.destination.next(args);
64 result = this.project.apply(this, args);
67 this.destination.error(err);
70 this.destination.next(result);
73 //# sourceMappingURL=withLatestFrom.js.map