wishthis/node_modules/rxjs/dist/esm/internal/operators/switchMap.js
2022-04-07 09:06:43 +02:00

24 lines
No EOL
1.1 KiB
JavaScript

import { innerFrom } from '../observable/innerFrom';
import { operate } from '../util/lift';
import { createOperatorSubscriber } from './OperatorSubscriber';
export function switchMap(project, resultSelector) {
return operate((source, subscriber) => {
let innerSubscriber = null;
let index = 0;
let isComplete = false;
const checkComplete = () => isComplete && !innerSubscriber && subscriber.complete();
source.subscribe(createOperatorSubscriber(subscriber, (value) => {
innerSubscriber === null || innerSubscriber === void 0 ? void 0 : innerSubscriber.unsubscribe();
let innerIndex = 0;
const outerIndex = index++;
innerFrom(project(value, outerIndex)).subscribe((innerSubscriber = createOperatorSubscriber(subscriber, (innerValue) => subscriber.next(resultSelector ? resultSelector(value, innerValue, outerIndex, innerIndex++) : innerValue), () => {
innerSubscriber = null;
checkComplete();
})));
}, () => {
isComplete = true;
checkComplete();
}));
});
}
//# sourceMappingURL=switchMap.js.map