diff --git a/src/tools.ts b/src/tools.ts index 218d4f7..2fa5619 100644 --- a/src/tools.ts +++ b/src/tools.ts @@ -1,4 +1,4 @@ -import { toRef, watch, WatchStopHandle } from 'vue' +import { ref, toRef, watch, WatchStopHandle } from 'vue' type OptionSetter = (dst: any, key: string, value: any) => void @@ -27,6 +27,17 @@ export function bindObjectProp( return watch(r, (value) => { applyObjectProps(dst, value, setter) }) } +export function bindObjectProps( + src: any, + dst: any, + apply = true, + setter?: OptionSetter +): WatchStopHandle { + if (apply) applyObjectProps(dst, src, setter) + const r = ref(src) + return watch(r, (value) => { applyObjectProps(dst, value, setter) }, { deep: true }) +} + export function setFromProp(o: Record, prop: Record): void { if (prop instanceof Object) { Object.entries(prop).forEach(([key, value]) => {