Skip to content

Commit

Permalink
keep memory of last value seen
Browse files Browse the repository at this point in the history
  • Loading branch information
GrandSchtroumpf committed Jul 21, 2021
1 parent c9dcb86 commit abf6ff0
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions projects/akita-ng-fire/src/lib/utils/share-delay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,19 @@ export function shareWithDelay<T>(delay: number = 100): MonoTypeOperatorFunction
let refCount = 0;
let hasError = false;
let isComplete = false;
let lastValue: T;
function operation(this: Subscriber<T>, source: Observable<T>) {
refCount++;
let innerSub: Subscription | undefined;
if (!subject || hasError) {
hasError = false;
subject = new ReplaySubject<T>(1, Infinity);
if (lastValue) subject.next(lastValue);
innerSub = subject.subscribe(this);
subscription = source.subscribe({
next(value) {
subject?.next(value);
lastValue = value;
},
error(err) {
hasError = true;
Expand Down

0 comments on commit abf6ff0

Please sign in to comment.