@@ -4,13 +4,14 @@ import { getCachedModule, ExposedScalprumModule, getAppData, processManifest, ge
44export type ModuleDefinition = {
55 scope : string ;
66 module : string ;
7+ importName ?: string ;
78 processor ?: ( item : any ) => string [ ] ;
89} ;
910
10- export function useLoadModule (
11- { scope, module, processor } : ModuleDefinition ,
11+ export function useLoadModule < T > (
12+ { scope, module, importName , processor } : ModuleDefinition ,
1213 defaultState : any ,
13- ) : [ ExposedScalprumModule | undefined , Error | undefined ] {
14+ ) : [ ExposedScalprumModule < T > | undefined , Error | undefined ] {
1415 const { manifestLocation } = getAppData ( scope ) ;
1516 const [ data , setData ] = useState < ExposedScalprumModule > ( defaultState ) ;
1617 const [ error , setError ] = useState < Error > ( ) ;
@@ -24,7 +25,7 @@ export function useLoadModule(
2425 processManifest ( manifestLocation , scope , module , processor )
2526 . then ( async ( ) => {
2627 const Module : ExposedScalprumModule = await pluginStore . getExposedModule ( scope , module ) ;
27- setData ( ( ) => Module ) ;
28+ setData ( ( ) => Module [ importName || 'default' ] ) ;
2829 } )
2930 . catch ( ( e ) => {
3031 setError ( ( ) => e ) ;
@@ -33,7 +34,7 @@ export function useLoadModule(
3334 } else {
3435 try {
3536 pluginStore . getExposedModule < ExposedScalprumModule > ( scope , module ) . then ( ( Module ) => {
36- setData ( ( ) => Module ) ;
37+ setData ( ( ) => Module [ importName || 'default' ] ) ;
3738 } ) ;
3839 } catch ( e ) {
3940 setError ( ( ) => e as Error ) ;
0 commit comments