This repository has been archived on 2024-07-27. You can view files and clone it, but cannot push or open issues or pull requests.
keksAccountGUI/node_modulesOLD/rxjs/_esm2015/internal/operators/shareReplay.js

52 lines
1.7 KiB
JavaScript
Raw Normal View History

2019-08-11 18:48:02 +00:00
import { ReplaySubject } from '../ReplaySubject';
export function shareReplay(configOrBufferSize, windowTime, scheduler) {
let config;
if (configOrBufferSize && typeof configOrBufferSize === 'object') {
config = configOrBufferSize;
}
else {
config = {
bufferSize: configOrBufferSize,
windowTime,
refCount: false,
scheduler
};
}
return (source) => source.lift(shareReplayOperator(config));
}
function shareReplayOperator({ bufferSize = Number.POSITIVE_INFINITY, windowTime = Number.POSITIVE_INFINITY, refCount: useRefCount, scheduler }) {
let subject;
let refCount = 0;
let subscription;
let hasError = false;
let isComplete = false;
return function shareReplayOperation(source) {
refCount++;
if (!subject || hasError) {
hasError = false;
subject = new ReplaySubject(bufferSize, windowTime, scheduler);
subscription = source.subscribe({
next(value) { subject.next(value); },
error(err) {
hasError = true;
subject.error(err);
},
complete() {
isComplete = true;
subject.complete();
},
});
}
const innerSub = subject.subscribe(this);
this.add(() => {
refCount--;
innerSub.unsubscribe();
if (subscription && !isComplete && useRefCount && refCount === 0) {
subscription.unsubscribe();
subscription = undefined;
subject = undefined;
}
});
};
}
//# sourceMappingURL=shareReplay.js.map