import { getCurrentRowData } from '@/lib/calculate'; import { findKey } from 'lodash'; import { useWatchSyncValue } from '@/lib/composables/watch-sync-value'; import { StoreState } from '@/lib/store/types'; import { CellValue } from '@/lib/types'; import { UnwrapRef } from '@vue/composition-api'; export const useWatchRowData = ( rowId: string, state: StoreState, defaultValue: T, config: | undefined | [string | string[], (rowData: Record) => T] | ((rowData: Record) => T), inputHandler?: (value: UnwrapRef) => void, immediate = true, ) => { const currentRow2DData = state.index.data2D[rowId]; const columnId2Field = state.index.columnId2Field; const dataGetter = () => getCurrentRowData(currentRow2DData, columnId2Field); const dataWatcher = (key: string) => { const id = findKey(columnId2Field, (columnKey) => columnKey === key); return () => currentRow2DData.fieldData?.[id]?.value; }; return useWatchSyncValue( defaultValue, config, dataWatcher, dataGetter, inputHandler, immediate, ); };