Skip to content

Commit edbae59

Browse files
committed
fix(core/shareLatest): recursive sync subscriptions
1 parent 5e9be40 commit edbae59

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

packages/core/src/internal/share-latest.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const shareLatest = <T>(
1010
teardown = noop,
1111
): BehaviorObservable<T> => {
1212
let subject: Subject<T> | undefined
13-
let subscription: Subscription | undefined
13+
let subscription: Subscription | undefined | null
1414
let refCount = 0
1515
let currentValue: T = EMPTY_VALUE
1616

@@ -20,6 +20,7 @@ const shareLatest = <T>(
2020
if (!subject) {
2121
subject = new Subject<T>()
2222
innerSub = subject.subscribe(subscriber)
23+
subscription = null
2324
subscription = source$.subscribe(
2425
(value) => {
2526
subject!.next((currentValue = value))
@@ -40,7 +41,7 @@ const shareLatest = <T>(
4041
innerSub = subject.subscribe(subscriber)
4142
if (currentValue !== EMPTY_VALUE) {
4243
subscriber.next(currentValue)
43-
if (!subscription) {
44+
if (subscription === undefined) {
4445
subscriber.next(COMPLETE as any)
4546
}
4647
}
@@ -59,8 +60,8 @@ const shareLatest = <T>(
5960
subject = undefined
6061
if (subscription) {
6162
subscription.unsubscribe()
62-
subscription = undefined
6363
}
64+
subscription = undefined
6465
}
6566
}
6667
}) as BehaviorObservable<T>

0 commit comments

Comments
 (0)