1- import { Observable , defer } from "rxjs"
1+ import { Observable } from "rxjs"
22import shareLatest from "../internal/share-latest"
33import reactEnhancer from "../internal/react-enhancer"
44import { BehaviorObservable } from "../internal/BehaviorObservable"
@@ -30,11 +30,14 @@ export default function connectFactoryObservable<A extends [], O>(
3030 ( ...args : A ) => Exclude < O , typeof SUSPENSE > ,
3131 ( ...args : A ) => Observable < O > ,
3232] {
33- const cache = new NestedMap < A , [ Observable < O > , BehaviorObservable < O > ] > ( )
33+ const cache = new NestedMap <
34+ A ,
35+ [ BehaviorObservable < O > , BehaviorObservable < O > ]
36+ > ( )
3437
3538 const getSharedObservables$ = (
3639 input : A ,
37- ) : [ Observable < O > , BehaviorObservable < O > ] => {
40+ ) : [ BehaviorObservable < O > , BehaviorObservable < O > ] => {
3841 for ( let i = input . length - 1 ; input [ i ] === undefined && i > - 1 ; i -- ) {
3942 input . splice ( - 1 )
4043 }
@@ -53,17 +56,21 @@ export default function connectFactoryObservable<A extends [], O>(
5356 } ,
5457 )
5558
56- const reactObservable$ = reactEnhancer ( sharedObservable$ )
57-
58- const publicShared$ : Observable < O > = defer ( ( ) => {
59+ const publicShared$ = new Observable < O > ( ( subscriber ) => {
5960 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$ )
6572
66- const result : [ Observable < O > , BehaviorObservable < O > ] = [
73+ const result : [ BehaviorObservable < O > , BehaviorObservable < O > ] = [
6774 publicShared$ ,
6875 reactObservable$ ,
6976 ]
0 commit comments