mirror of
https://github.com/troisjs/trois.git
synced 2024-11-24 04:12:02 +08:00
bindObjectProps
This commit is contained in:
parent
b377d0f1da
commit
f109069d9f
13
src/tools.ts
13
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
|
type OptionSetter = (dst: any, key: string, value: any) => void
|
||||||
|
|
||||||
@ -27,6 +27,17 @@ export function bindObjectProp(
|
|||||||
return watch(r, (value) => { applyObjectProps(dst, value, setter) })
|
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<string, unknown>, prop: Record<string, unknown>): void {
|
export function setFromProp(o: Record<string, unknown>, prop: Record<string, unknown>): void {
|
||||||
if (prop instanceof Object) {
|
if (prop instanceof Object) {
|
||||||
Object.entries(prop).forEach(([key, value]) => {
|
Object.entries(prop).forEach(([key, value]) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user