Skip to content

Commit 2780e17

Browse files
committed
chore(core): decrease bundle-size
1 parent 14398b3 commit 2780e17

File tree

5 files changed

+23
-15
lines changed

5 files changed

+23
-15
lines changed

packages/core/src/Subscribe.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ export const Subscribe: React.FC<{
1818
useEffect(() => {
1919
const subscription = source$.subscribe()
2020
setMounted(1)
21-
return () => subscription.unsubscribe()
21+
return () => {
22+
subscription.unsubscribe()
23+
}
2224
}, [source$])
2325
return <>{mounted ? children : fallback}</>
2426
}

packages/core/src/internal/react-enhancer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { BehaviorObservable } from "./BehaviorObservable"
33
import { EMPTY_VALUE } from "./empty-value"
44

55
const reactEnhancer = <T>(source$: BehaviorObservable<T>): (() => T) => {
6-
let promise: Promise<T | void> | undefined
6+
let promise: Promise<T | void> | null
77
let error: any = EMPTY_VALUE
88

99
return (): T => {
@@ -46,11 +46,11 @@ const reactEnhancer = <T>(source$: BehaviorObservable<T>): (() => T) => {
4646
subscription.unsubscribe()
4747
}
4848
}).finally(() => {
49-
promise = undefined
49+
promise = null
5050
})
5151

5252
if (value !== EMPTY_VALUE) {
53-
promise = undefined
53+
promise = null
5454
return value
5555
}
5656

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ const shareLatest = <T>(
77
shouldComplete = true,
88
teardown = noop,
99
): BehaviorObservable<T> => {
10-
let subject: Subject<T> | undefined
11-
let subscription: Subscription | undefined | null
10+
let subject: Subject<T> | null
11+
let subscription: Subscription | null
1212
let refCount = 0
1313
let currentValue: T = EMPTY_VALUE
1414

@@ -25,16 +25,16 @@ const shareLatest = <T>(
2525
},
2626
(err) => {
2727
const _subject = subject
28-
subscription = undefined
29-
subject = undefined
28+
subscription = null
29+
subject = null
3030
_subject!.error(err)
3131
},
3232
() => {
33-
subscription = undefined
33+
subscription = null
3434
shouldComplete && subject!.complete()
3535
},
3636
)
37-
if (subscription.closed) subscription = undefined
37+
if (subscription.closed) subscription = null
3838
} else {
3939
innerSub = subject.subscribe(subscriber)
4040
if (currentValue !== EMPTY_VALUE) {
@@ -51,8 +51,8 @@ const shareLatest = <T>(
5151
subscription.unsubscribe()
5252
}
5353
teardown()
54-
subject = undefined
55-
subscription = undefined
54+
subject = null
55+
subscription = null
5656
}
5757
}
5858
}) as BehaviorObservable<T>

packages/core/src/internal/useObservable.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ export const useObservable = <O>(
2121
})
2222
}
2323

24-
let subscription = source$.subscribe((val) => (syncVal = val), onError)
24+
let subscription = source$.subscribe((val) => {
25+
syncVal = val
26+
}, onError)
2527
if (err !== EMPTY_VALUE) return
2628

2729
const set = (val: O | (() => O)) => {
@@ -37,7 +39,9 @@ export const useObservable = <O>(
3739
}, onError)
3840
t.unsubscribe()
3941

40-
return () => subscription.unsubscribe()
42+
return () => {
43+
subscription.unsubscribe()
44+
}
4145
}, keys)
4246

4347
return state as Exclude<O, typeof SUSPENSE>

packages/core/src/useSubscribe.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import { useEffect } from "react"
1313
export const useSubscribe = <T>(source$: Observable<T>) => {
1414
useEffect(() => {
1515
const subscription = source$.subscribe()
16-
return () => subscription.unsubscribe()
16+
return () => {
17+
subscription.unsubscribe()
18+
}
1719
}, [source$])
1820
}

0 commit comments

Comments
 (0)