Skip to content

Commit 266d597

Browse files
committed
chore(core): avoid using rxjs/operators
1 parent 75ba112 commit 266d597

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

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

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Observable, noop } from "rxjs"
2-
import { take, filter, tap } from "rxjs/operators"
32
import { SUSPENSE } from "../SUSPENSE"
43
import { BehaviorObservable, Action } from "./BehaviorObservable"
54
import { EMPTY_VALUE } from "./empty-value"
@@ -67,29 +66,32 @@ const reactEnhancer = <T>(source$: Observable<T>): BehaviorObservable<T> => {
6766
let value:
6867
| typeof EMPTY_VALUE
6968
| { type: Action.Value; payload: T } = EMPTY_VALUE
69+
7070
promise = {
7171
type: Action.Suspense,
72-
payload: result
73-
.pipe(
74-
filter((x) => x !== (SUSPENSE as any)),
75-
take(1),
76-
tap({
77-
next(v) {
72+
payload: new Promise<T>((res) => {
73+
const subscription = result.subscribe(
74+
(v) => {
75+
if (v !== (SUSPENSE as any)) {
7876
value = { type: Action.Value, payload: v }
79-
},
80-
error(e) {
81-
error = { type: Action.Error, payload: e }
82-
timeoutToken = setTimeout(() => {
83-
error = EMPTY_VALUE
84-
}, 50)
85-
},
86-
}),
77+
subscription && subscription.unsubscribe()
78+
res(v)
79+
}
80+
},
81+
(e) => {
82+
error = { type: Action.Error, payload: e }
83+
timeoutToken = setTimeout(() => {
84+
error = EMPTY_VALUE
85+
}, 50)
86+
res()
87+
},
8788
)
88-
.toPromise()
89-
.catch(() => {})
90-
.finally(() => {
91-
promise = undefined
92-
}),
89+
if (value !== EMPTY_VALUE || error !== EMPTY_VALUE) {
90+
subscription.unsubscribe()
91+
}
92+
}).finally(() => {
93+
promise = undefined
94+
}),
9395
}
9496

9597
if (value !== EMPTY_VALUE) {

0 commit comments

Comments
 (0)