File tree Expand file tree Collapse file tree 1 file changed +22
-20
lines changed
packages/core/src/internal Expand file tree Collapse file tree 1 file changed +22
-20
lines changed Original file line number Diff line number Diff line change 1
1
import { Observable , noop } from "rxjs"
2
- import { take , filter , tap } from "rxjs/operators"
3
2
import { SUSPENSE } from "../SUSPENSE"
4
3
import { BehaviorObservable , Action } from "./BehaviorObservable"
5
4
import { EMPTY_VALUE } from "./empty-value"
@@ -67,29 +66,32 @@ const reactEnhancer = <T>(source$: Observable<T>): BehaviorObservable<T> => {
67
66
let value :
68
67
| typeof EMPTY_VALUE
69
68
| { type : Action . Value ; payload : T } = EMPTY_VALUE
69
+
70
70
promise = {
71
71
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 ) ) {
78
76
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
+ } ,
87
88
)
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
+ } ) ,
93
95
}
94
96
95
97
if ( value !== EMPTY_VALUE ) {
You can’t perform that action at this time.
0 commit comments