-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path3people.ts
More file actions
31 lines (26 loc) Β· 710 Bytes
/
Copy path3people.ts
File metadata and controls
31 lines (26 loc) Β· 710 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { MaybeRefOrGetter, isRef, ref, toValue, watch } from "vue"
interface UseClonedOptions {
manual?: boolean
clone?: (source: any) => any
deep?: boolean
immediate?: boolean
}
export const useCloned = (data: MaybeRefOrGetter, options?: UseClonedOptions) => {
const {
manual = false,
clone = (source: any) => ({ ...source }),
deep = true,
immediate = true
} = options || {}
const cloned = ref({})
const sync = () => {
// toValueλ getterλ μ²λ¦¬ν΄μ€λ€
cloned.value = clone(toValue(data))
}
if (!manual && (isRef(data) || typeof data === 'function')) {
watch(data, sync, { deep, immediate })
} else {
sync()
}
return { cloned, sync }
}