1
- import { Observable , defer } from "rxjs"
1
+ import { Observable } from "rxjs"
2
2
import shareLatest from "../internal/share-latest"
3
3
import reactEnhancer from "../internal/react-enhancer"
4
4
import { BehaviorObservable } from "../internal/BehaviorObservable"
@@ -30,11 +30,14 @@ export default function connectFactoryObservable<A extends [], O>(
30
30
( ...args : A ) => Exclude < O , typeof SUSPENSE > ,
31
31
( ...args : A ) => Observable < O > ,
32
32
] {
33
- const cache = new NestedMap < A , [ Observable < O > , BehaviorObservable < O > ] > ( )
33
+ const cache = new NestedMap <
34
+ A ,
35
+ [ BehaviorObservable < O > , BehaviorObservable < O > ]
36
+ > ( )
34
37
35
38
const getSharedObservables$ = (
36
39
input : A ,
37
- ) : [ Observable < O > , BehaviorObservable < O > ] => {
40
+ ) : [ BehaviorObservable < O > , BehaviorObservable < O > ] => {
38
41
for ( let i = input . length - 1 ; input [ i ] === undefined && i > - 1 ; i -- ) {
39
42
input . splice ( - 1 )
40
43
}
@@ -53,17 +56,21 @@ export default function connectFactoryObservable<A extends [], O>(
53
56
} ,
54
57
)
55
58
56
- const reactObservable$ = reactEnhancer ( sharedObservable$ )
57
-
58
- const publicShared$ : Observable < O > = defer ( ( ) => {
59
+ const publicShared$ = new Observable < O > ( ( subscriber ) => {
59
60
const inCache = cache . get ( keys )
60
- if ( inCache ) {
61
- return inCache [ 0 ] === publicShared$ ? sharedObservable$ : inCache [ 0 ]
62
- }
63
- return getSharedObservables$ ( input ) [ 0 ]
64
- } )
61
+ const source$ = inCache
62
+ ? inCache [ 0 ] === publicShared$
63
+ ? sharedObservable$
64
+ : inCache [ 0 ]
65
+ : getSharedObservables$ ( input ) [ 0 ]
66
+
67
+ publicShared$ . getValue = source$ . getValue
68
+
69
+ return source$ . subscribe ( subscriber )
70
+ } ) as BehaviorObservable < O >
71
+ const reactObservable$ = reactEnhancer ( publicShared$ )
65
72
66
- const result : [ Observable < O > , BehaviorObservable < O > ] = [
73
+ const result : [ BehaviorObservable < O > , BehaviorObservable < O > ] = [
67
74
publicShared$ ,
68
75
reactObservable$ ,
69
76
]
0 commit comments