From f109069d9fc4f857f7cb39018045c2fb4e124d7a Mon Sep 17 00:00:00 2001 From: Kevin Levron Date: Sun, 31 Oct 2021 22:06:34 +0100 Subject: [PATCH] bindObjectProps --- src/tools.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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]) => {