const RPCCache = new WeakMap < object , object > ( ) ; param isBackground param name param impl param ref export async function getLocalImplementation < T extends object > ( isBackground , name , impl , ref ) { if ( ! isBackground ) return { } ; const isUpdate = RPCCache . has ( ref ) ; const localImpl = RPCCache . get ( ref ) || ( { } as any ) ; RPCCache . set ( ref , localImpl ) ; const result = await impl ( ) ; for ( const key in localImpl ) { if ( ! Reflect . has ( result , key ) ) { delete localImpl [ key ] ; isUpdate && console . log ( `[HMR] ${ name }.${ key } removed.` ) ; } else if ( result [ key ] !== localImpl [ key ] ) { isUpdate && console . log ( `[HMR] ${ name }.${ key } updated.` ) ; } } for ( const key in result ) { if ( key === 'then' ) console . error ( '!!! Do not use "then" as your method name !!!' ) ; if ( ! Reflect . has ( localImpl , key ) ) isUpdate && console . log ( `[HMR] ${ name }.${ key } added.` ) ; Object . defineProperty ( localImpl , key , { configurable : true , enumerable : true , value : result [ key ] } ) ; } return localImpl ; } export async function getLocalImplementationExotic < T extends object > ( isBackground , name , impl , ref ) { if ( ! isBackground ) return { } ; RPCCache . set ( ref , await impl ( ) ) ; return new Proxy ( { } , { get ( _ , key ) { if ( key === 'then' ) return ; return RPCCache . get ( ref ) ?. [ key ] ; } , } ) ; }