import { SetupContext } from '@vue/composition-api' ; import ConsoleScope from '@/scopes/console' ; import { MalVal , MalError , isFunc , isSymbol , getMeta , MalMap , MalFunc , MalType , createList as L , } from '@/mal/types' ; import { printExp } from '@/mal' ; import DialogCommand from '@/components/dialogs/DialogCommand.vue' ; import { getMapValue } from '@/mal/utils' ; import { printer } from '@/mal/printer' ; import { NonReactive , nonReactive } from '@/utils' ; export default function useDialogCommand ( context ) { const { $modal } = context . root ; ConsoleScope . def ( 'show-command-dialog' , ( f ) => { if ( f === undefined || ! isSymbol ( f ) ) { throw new MalError ( `${ printExp ( f ) } is not a symbol` ) ; } const fn = ConsoleScope . var ( f . value ) ; const meta = getMeta ( fn ) ; const paramsDesc = getMapValue ( meta , 'params' , MalType . Vector ) as MalMap [ ] | null ; let initialParams = getMapValue ( meta , 'initial-params' ) as MalFunc | MalVal [ ] | null ; if ( ! paramsDesc || ! initialParams ) { printer . error ( 'NO initial parmas' ) ; return null ; } if ( isFunc ( initialParams ) ) { initialParams = initialParams ( ) as MalVal [ ] ; } const exp = nonReactive ( L ( f , ... initialParams ) ) ; $modal . show ( DialogCommand , { exp , fn , } , { } ) ; return null ; } ) ; }