55 ReceiverHandler ,
66 TypedVariable ,
77} from "@pulse-editor/shared-utils" ;
8- import { useEffect , useRef , useState } from "react" ;
8+ import { DependencyList , useEffect , useRef , useState } from "react" ;
99import useIMC from "../../lib/use-imc" ;
1010
1111/**
@@ -17,7 +17,8 @@ import useIMC from "../../lib/use-imc";
1717 * @param parameters Parameters of the command.
1818 * @param returns Return values of the command.
1919 * @param callbackHandler Callback handler function to handle the command.
20- * @param isExtReady Whether the extension is ready to receive commands.
20+ * @param deps Dependency list to re-register the action when changed.
21+ * @param isExtReady Whether the extension is ready to receive commands.
2122 * Useful for actions that need to wait for some certain app state to be ready.
2223 *
2324 */
@@ -28,7 +29,8 @@ export default function useRegisterAction(
2829 parameters ?: Record < string , TypedVariable > ;
2930 returns ?: Record < string , TypedVariable > ;
3031 } ,
31- callbackHandler ?: ( args : any ) => Promise < string | void > ,
32+ callbackHandler : ( args : any ) => Promise < any > ,
33+ deps : DependencyList ,
3234 isExtReady : boolean = true
3335) {
3436 const { isReady, imc } = useIMC ( getReceiverHandlerMap ( ) ) ;
@@ -85,8 +87,9 @@ export default function useRegisterAction(
8587 description : actionInfo . description ,
8688 parameters : actionInfo . parameters ?? { } ,
8789 returns : actionInfo . returns ?? { } ,
90+ handler : callbackHandler ,
8891 } ) ) ;
89- } , [ callbackHandler ] ) ;
92+ } , [ ... deps ] ) ;
9093
9194 async function executeAction ( args : any ) {
9295 if ( ! action . handler ) return ;
0 commit comments