@@ -106,7 +106,10 @@ export function createApp(opts: { root: any; api?: Record<string, (...a: any[])
106106 const contexts = new Map < string , ReturnType < typeof createContext < Entry | undefined > > > ( ) ;
107107 const storeAccs = new WeakSet < object > ( ) ;
108108 const modules = new Map < unknown , Record < string , unknown > > ( ) ;
109- const hoistedBy = new Map < string , Acc [ ] > ( ) ; // an equation's hoisted awaits, re-asked with it by `refresh`
109+ // An equation's hoisted awaits, re-asked with it by `refresh`. They are emitted just before the equation and claimed
110+ // by its accessor when it registers, so a refresh reaches only its own instance's (never a disposed mount's).
111+ const hoistedBy = new Map < string , Acc [ ] > ( ) ;
112+ const hoistedOf = new WeakMap < Acc , Acc [ ] > ( ) ;
110113 const log : string [ ] = [ ] ;
111114 let currentEq : string | null = null ; let serverSeq = 0 ; let classSeq = 0 ;
112115 const jsErrors = new Map < string , unknown > ( ) ; // MO-8: one class per declared JS error, per app
@@ -142,7 +145,7 @@ export function createApp(opts: { root: any; api?: Record<string, (...a: any[])
142145 api : ( name : string ) => opts . api ? ( opts . api [ name ] ?? ( ( ) => { throw new Error ( `./api has no ${ name } ` ) ; } ) ) : ( ...a : unknown [ ] ) => flight ( `${ name } :${ a . map ( fmt ) . join ( "," ) } ` ) ,
143146
144147 // ---- the scenario harness's view of names (handler rows reach any live binding by name) ----
145- reg ( name : string , e : Entry ) { let l = registry . get ( name ) ; if ( ! l ) registry . set ( name , ( l = [ ] ) ) ; l . push ( e ) ; } ,
148+ reg ( name : string , e : Entry ) { let l = registry . get ( name ) ; if ( ! l ) registry . set ( name , ( l = [ ] ) ) ; l . push ( e ) ; const h = hoistedBy . get ( name ) ; if ( h && e . get ) { hoistedOf . set ( e . get , h ) ; hoistedBy . delete ( name ) ; } } ,
146149 lookup ( name : string ) : Entry { const l = registry . get ( name ) ; if ( ! l ?. length ) throw new Error ( `unbound ${ name } ` ) ; for ( let i = l . length - 1 ; i >= 0 ; i -- ) if ( l [ i ] . w ) return l [ i ] ; return l [ l . length - 1 ] ; } ,
147150 dget ( name : string , live = false ) { const e = app . lookup ( name ) ; return e . get ? ( live ? e . get ( ) : app . snapshot ( e . get ) ) : e . value ; } , // live: inside a probe (R-12), the read itself
148151 dset ( name : string , keys : ( string | number ) [ ] , v : unknown , guess = false ) { const w = app . lookup ( name ) . w ; if ( ! w ) throw new Error ( `W-1: write to non-source ${ name } ` ) ; if ( guess ) w . guess ( v , keys ) ; else if ( keys . length ) w . path ( keys , v ) ; else w . set ( v ) ; } ,
@@ -250,7 +253,7 @@ export function createApp(opts: { root: any; api?: Record<string, (...a: any[])
250253 until : ( p : ( ) => unknown ) => until ( p ) , // AC-6
251254 onSettled : ( f : ( ) => void ) => onSettled ( f ) , // EF-7
252255 onFlush : ( f : ( ) => void ) => onFlush ( f ) , // EF-8
253- refresh ( name : string , get : Acc ) { const key = lastKey . get ( name ) ; if ( key ) flights . delete ( key ) ; for ( const h of hoistedBy . get ( name ) ?? [ ] ) refresh ( h as any ) ; const t = truthOf . get ( get ) ?? get ; refresh ( ( storeAccs . has ( t ) ? t ( ) : t ) as any ) ; } ,
256+ refresh ( name : string , get : Acc ) { const key = lastKey . get ( name ) ; if ( key ) flights . delete ( key ) ; for ( const h of hoistedOf . get ( get ) ?? [ ] ) refresh ( h as any ) ; const t = truthOf . get ( get ) ?? get ; refresh ( ( storeAccs . has ( t ) ? t ( ) : t ) as any ) ; } ,
254257 affects : ( get : Acc ) => affects ( get as any ) ,
255258 preOr : ( v : unknown , init : ( ) => unknown ) => v === undefined ? init ( ) : v ,
256259
0 commit comments