Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / rxjs / _esm5 / internal / operators / shareReplay.js
1 /** PURE_IMPORTS_START _ReplaySubject PURE_IMPORTS_END */
2 import { ReplaySubject } from '../ReplaySubject';
3 export function shareReplay(configOrBufferSize, windowTime, scheduler) {
4     var config;
5     if (configOrBufferSize && typeof configOrBufferSize === 'object') {
6         config = configOrBufferSize;
7     }
8     else {
9         config = {
10             bufferSize: configOrBufferSize,
11             windowTime: windowTime,
12             refCount: false,
13             scheduler: scheduler
14         };
15     }
16     return function (source) { return source.lift(shareReplayOperator(config)); };
17 }
18 function shareReplayOperator(_a) {
19     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;
20     var subject;
21     var refCount = 0;
22     var subscription;
23     var hasError = false;
24     var isComplete = false;
25     return function shareReplayOperation(source) {
26         refCount++;
27         var innerSub;
28         if (!subject || hasError) {
29             hasError = false;
30             subject = new ReplaySubject(bufferSize, windowTime, scheduler);
31             innerSub = subject.subscribe(this);
32             subscription = source.subscribe({
33                 next: function (value) { subject.next(value); },
34                 error: function (err) {
35                     hasError = true;
36                     subject.error(err);
37                 },
38                 complete: function () {
39                     isComplete = true;
40                     subscription = undefined;
41                     subject.complete();
42                 },
43             });
44         }
45         else {
46             innerSub = subject.subscribe(this);
47         }
48         this.add(function () {
49             refCount--;
50             innerSub.unsubscribe();
51             if (subscription && !isComplete && useRefCount && refCount === 0) {
52                 subscription.unsubscribe();
53                 subscription = undefined;
54                 subject = undefined;
55             }
56         });
57     };
58 }
59 //# sourceMappingURL=shareReplay.js.map