import { ManagedDialogDefine } from "./types"; type ArgOf = F extends (arg: infer A) => any ? A : never; type WithoutCancel = Omit; type TransShowParam any>> = { [K in keyof T]: { type: K, props: WithoutCancel> } }[keyof T]; type TransCloseParam any>> = keyof T type UserInterface any>> ={ showDialog:(info:TransShowParam)=>void, closeDialog:(dialogType:TransCloseParam)=>void } type ShowDialogFunction = (info:{type:string,props:Object})=>void type CloseDialogFunction = (type:string)=>void type InitDialogDefine = (define:ManagedDialogDefine) =>void export const dialogManagerInternal = { showDialog : undefined as undefined | ShowDialogFunction, closeDialog : undefined as undefined | CloseDialogFunction, dialogDefine : undefined as undefined | ManagedDialogDefine, initDialogDefine :undefined as undefined | InitDialogDefine } export function initDialogManager(dialogDefine:T):UserInterface{ dialogManagerInternal.dialogDefine = dialogDefine; if(dialogManagerInternal.initDialogDefine){ dialogManagerInternal.initDialogDefine(dialogDefine) } const showDialog =(info:{type:string,props:Object})=>{ if(dialogManagerInternal.showDialog === undefined) return; dialogManagerInternal.showDialog(info) } const closeDialog = (type:string)=>{ if(dialogManagerInternal.closeDialog === undefined) return; dialogManagerInternal.closeDialog(type) } return {showDialog,closeDialog} as UserInterface } // const ttt = { // "pollLog":function({}:{onCancel: () => void, id:number} ){}, // "liveData":function({}:{onCancel: () => void, p1:number, p2:string} ){} // } as const; // const xxx = initDialogManager(ttt) // xxx.showDialog({type:"liveData",props:{p1:1,p2:"s"}})