import { reset } from '../data-utils'
import { parseData } from '../data-function'
import type { IFuncType } from '@opentiny/tiny-engine-dsl-vue'
export function useMethods({ getContext, setContext }) {
const methods: Record<string, IFuncType> = {}
const getMethods = () => methods
const setMethods = (data: Record<string, IFuncType> = {}, clear = false) => {
if (clear) {
reset(methods)
}
Object.assign(
methods,
Object.fromEntries(
Object.keys(data).map((key) => {
return [key, parseData(data[key], {}, getContext())]
})
)
)
setContext(methods)
}
return {
methods,
getMethods,
setMethods
}
}