Opal-Estate-Pro/node_modules/rxjs/_esm5/operators/shareReplay.js
2019-09-13 11:27:52 +07:00

45 lines
1.4 KiB
JavaScript
Executable File

/** PURE_IMPORTS_START .._ReplaySubject PURE_IMPORTS_END */
import { ReplaySubject } from '../ReplaySubject';
/**
* @method shareReplay
* @owner Observable
*/
export function shareReplay(bufferSize, windowTime, scheduler) {
return function (source) { return source.lift(shareReplayOperator(bufferSize, windowTime, scheduler)); };
}
function shareReplayOperator(bufferSize, windowTime, 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);
return function () {
refCount--;
innerSub.unsubscribe();
if (subscription && refCount === 0 && isComplete) {
subscription.unsubscribe();
}
};
};
}
;
//# sourceMappingURL=shareReplay.js.map