import { Ref , computed , SetupContext } from '@vue/composition-api' ; import { MalVal , getEvaluated , MalSeq , MalSymbol , isVector , cloneExp , } from '@/mal/types' ; import { reverseEval } from '@/mal/utils' ; import { NonReactive , nonReactive } from '@/utils' ; /**
 * Refs and event handles for MalInputVec2, Rect2d, Mat2d
 */ export default function useNumericVectorUpdator ( exp , context ) { const isValueSeparated = computed ( ( ) => isVector ( exp . value . value ) ) ; const nonReactiveValues = computed ( ( ) => { if ( ! isValueSeparated . value ) { return [ ] ; } else { return Array . from ( exp . value . value as MalSeq ) . map ( nonReactive ) ; } } ) ; const evaluated = computed ( ( ) => getEvaluated ( exp . value . value ) as number [ ] ) ; function onInputElement ( i , v ) { if ( ! isValueSeparated . value ) { return ; } const newExp = cloneExp ( exp . value . value as MalSeq ) ; newExp [ i ] = v . value ; context . emit ( 'input' , nonReactive ( newExp ) ) ; } function onInputEvaluatedElement ( i , v ) { const value = cloneExp ( exp . value . value as MalSeq ) ; value [ i ] = v ; const newExp = reverseEval ( value , exp . value . value ) ; context . emit ( 'input' , nonReactive ( newExp ) ) ; } return { nonReactiveValues , isValueSeparated , evaluated , onInputElement , onInputEvaluatedElement , } ; }