@@ -6,53 +6,6 @@ import { useObservable } from "../internal/useObservable"
66import { SUSPENSE } from "../SUSPENSE"
77import { takeUntilComplete } from "../internal/take-until-complete"
88
9- class NestedMap < K extends [ ] , V extends Object > {
10- private root : Map < K , any >
11- constructor ( ) {
12- this . root = new Map ( )
13- }
14-
15- get ( keys : K [ ] ) : V | undefined {
16- let current : any = this . root
17- for ( let i = 0 ; i < keys . length ; i ++ ) {
18- current = current . get ( keys [ i ] )
19- if ( ! current ) return undefined
20- }
21- return current
22- }
23-
24- set ( keys : K [ ] , value : V ) : void {
25- let current : Map < K , any > = this . root
26- let i
27- for ( i = 0 ; i < keys . length - 1 ; i ++ ) {
28- let nextCurrent = current . get ( keys [ i ] )
29- if ( ! nextCurrent ) {
30- nextCurrent = new Map < K , any > ( )
31- current . set ( keys [ i ] , nextCurrent )
32- }
33- current = nextCurrent
34- }
35- current . set ( keys [ i ] , value )
36- }
37-
38- delete ( keys : K [ ] ) : void {
39- const maps : Map < K , any > [ ] = [ this . root ]
40- let current : Map < K , any > = this . root
41-
42- for ( let i = 0 ; i < keys . length - 1 ; i ++ ) {
43- maps . push ( ( current = current . get ( keys [ i ] ) ) )
44- }
45-
46- let mapIdx = maps . length - 1
47- maps [ mapIdx ] . delete ( keys [ mapIdx ] )
48-
49- while ( -- mapIdx > - 1 && maps [ mapIdx ] . get ( keys [ mapIdx ] ) . size === 0 ) {
50- maps [ mapIdx ] . delete ( keys [ mapIdx ] )
51- }
52- }
53- }
54-
55- const emptyInput = [ 0 ]
569/**
5710 * Accepts: A factory function that returns an Observable.
5811 *
@@ -87,7 +40,10 @@ export default function connectFactoryObservable<A extends [], O>(
8740 const getSharedObservables$ = (
8841 input : A ,
8942 ) : [ Observable < O > , BehaviorObservable < O > ] => {
90- const keys = input . length > 0 ? input : ( emptyInput as A )
43+ for ( let i = input . length - 1 ; input [ i ] === undefined && i > - 1 ; i -- ) {
44+ input . splice ( - 1 )
45+ }
46+ const keys = ( [ input . length , ...input ] as any ) as A
9147 const cachedVal = cache . get ( keys )
9248
9349 if ( cachedVal !== undefined ) {
@@ -117,3 +73,49 @@ export default function connectFactoryObservable<A extends [], O>(
11773 ( ...input : A ) => getSharedObservables$ ( input ) [ 0 ] ,
11874 ]
11975}
76+
77+ class NestedMap < K extends [ ] , V extends Object > {
78+ private root : Map < K , any >
79+ constructor ( ) {
80+ this . root = new Map ( )
81+ }
82+
83+ get ( keys : K [ ] ) : V | undefined {
84+ let current : any = this . root
85+ for ( let i = 0 ; i < keys . length ; i ++ ) {
86+ current = current . get ( keys [ i ] )
87+ if ( ! current ) return undefined
88+ }
89+ return current
90+ }
91+
92+ set ( keys : K [ ] , value : V ) : void {
93+ let current : Map < K , any > = this . root
94+ let i
95+ for ( i = 0 ; i < keys . length - 1 ; i ++ ) {
96+ let nextCurrent = current . get ( keys [ i ] )
97+ if ( ! nextCurrent ) {
98+ nextCurrent = new Map < K , any > ( )
99+ current . set ( keys [ i ] , nextCurrent )
100+ }
101+ current = nextCurrent
102+ }
103+ current . set ( keys [ i ] , value )
104+ }
105+
106+ delete ( keys : K [ ] ) : void {
107+ const maps : Map < K , any > [ ] = [ this . root ]
108+ let current : Map < K , any > = this . root
109+
110+ for ( let i = 0 ; i < keys . length - 1 ; i ++ ) {
111+ maps . push ( ( current = current . get ( keys [ i ] ) ) )
112+ }
113+
114+ let mapIdx = maps . length - 1
115+ maps [ mapIdx ] . delete ( keys [ mapIdx ] )
116+
117+ while ( -- mapIdx > - 1 && maps [ mapIdx ] . get ( keys [ mapIdx ] ) . size === 0 ) {
118+ maps [ mapIdx ] . delete ( keys [ mapIdx ] )
119+ }
120+ }
121+ }
0 commit comments