| 175 | * @returns Stop watching function |
| 176 | */ |
| 177 | export function useWatchDataPath( |
| 178 | path: string, |
| 179 | callback: (newValue: DataValue | null, oldValue: DataValue | null) => void, |
| 180 | ): () => void { |
| 181 | const context = inject<DataBindingContext | null>(DATA_BINDING_CONTEXT_KEY, null); |
| 182 | |
| 183 | if (!context) { |
| 184 | console.warn('useWatchDataPath: No data binding context found'); |
| 185 | return () => {}; |
| 186 | } |
| 187 | |
| 188 | const stopWatch = watch( |
| 189 | () => getData(context.dataModel.value, path), |
| 190 | (newValue, oldValue) => { |
| 191 | callback(newValue, oldValue); |
| 192 | }, |
| 193 | { deep: true }, |
| 194 | ); |
| 195 | |
| 196 | return stopWatch; |
| 197 | } |