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/_esm5/internal/operators/shareReplay.js

55 lines
2 KiB
JavaScript
Raw Normal View History

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