@@ -7,12 +7,12 @@ import type { GenericObject } from "./types";
77 */
88export class GlobalQueryManager {
99 private static instance : GlobalQueryManager ;
10- private updates : Map < string , { value : any ; mode : "push" | "replace" } > =
11- new Map ( ) ;
10+ private updates : Map < string , { value : any ; mode : "push" | "replace" } > = new Map ( ) ;
1211 private processingPromise : Promise < void > | null = null ;
1312 private router : any = null ;
1413 private currentQuery : Record < string , any > = { } ;
1514 private initialQueryHandled = false ;
15+ private instances = new Map < symbol , string [ ] > ( ) ;
1616
1717 private constructor ( ) { }
1818
@@ -31,6 +31,27 @@ export class GlobalQueryManager {
3131 }
3232 }
3333
34+ registerInstance ( instanceId : symbol , schemaKeys : string [ ] ) {
35+ this . instances . set ( instanceId , schemaKeys ) ;
36+ }
37+
38+ unregisterInstance ( instanceId : symbol ) {
39+ const keys = this . instances . get ( instanceId ) ;
40+ if ( ! keys ) return ;
41+
42+ this . instances . delete ( instanceId ) ;
43+ for ( const key of keys ) {
44+ if ( ! this . isKeyOwnedByInstance ( key ) ) delete this . currentQuery [ key ] ;
45+ }
46+ }
47+
48+ isKeyOwnedByInstance ( key : string ) {
49+ for ( const [ instanceId , keys ] of this . instances . entries ( ) )
50+ if ( keys . includes ( key ) ) return true ;
51+ return false ;
52+ }
53+
54+
3455 enqueue ( key : string , value : any , mode : "push" | "replace" = "replace" ) {
3556 this . updates . set ( key , { value, mode } ) ;
3657
@@ -126,4 +147,9 @@ export class GlobalQueryManager {
126147 this . enqueue ( key , undefined , mode ) ;
127148 } ) ;
128149 }
150+
151+ static cleanup ( ) {
152+ // @ts -expect-error
153+ GlobalQueryManager . instance = null ;
154+ }
129155}
0 commit comments