📄 useCloned¶
📊 Analysis Summary¶
| Metric | Count |
|---|---|
| 🔧 Functions | 3 |
| 📦 Imports | 8 |
| 🟢 Vue Composition API | 2 |
| 📐 Interfaces | 2 |
| 📑 Type Aliases | 1 |
📚 Table of Contents¶
🛠️ File Location:¶
📂 packages/core/useCloned/index.ts
📦 Imports¶
| Name | Source |
|---|---|
MaybeRefOrGetter |
vue |
Ref |
vue |
WatchOptions |
vue |
deepRef |
vue |
isRef |
vue |
shallowRef |
vue |
toValue |
vue |
watch |
vue |
Vue Composition API¶
| Name | Type | Reactive Variables | Composables |
|---|---|---|---|
watch |
watch | none | none |
watch |
watch | none | none |
Functions¶
cloneFnJSON(source: T): T¶
Parameters:
sourceT
Returns: T
Calls:
JSON.parseJSON.stringify
useCloned(source: MaybeRefOrGetter<T>, options: UseClonedOptions<T>): UseClonedReturn<T>¶
Parameters:
sourceMaybeRefOrGetter<T>optionsUseClonedOptions<T>
Returns: UseClonedReturn<T>
Calls:
deepRef (from vue)shallowRef (from vue)watch (from vue)clonetoValue (from vue)isRef (from vue)sync
Internal Comments:
Code
export function useCloned<T>(
source: MaybeRefOrGetter<T>,
options: UseClonedOptions<T> = {},
): UseClonedReturn<T> {
const cloned = deepRef({} as T) as Ref<T>
const isModified = shallowRef<boolean>(false)
let _lastSync = false
const {
manual,
clone = cloneFnJSON,
// watch options
deep = true,
immediate = true,
} = options
watch(cloned, () => {
if (_lastSync) {
_lastSync = false
return
}
isModified.value = true
}, {
deep: true,
flush: 'sync',
})
function sync() {
_lastSync = true
isModified.value = false
cloned.value = clone(toValue(source))
}
if (!manual && (isRef(source) || typeof source === 'function')) {
watch(source, sync, {
...options,
deep,
immediate,
})
}
else {
sync()
}
return { cloned, isModified, sync }
}
Internal helpers¶
Declared inside another function in this file.
sync(): void¶
Returns: void
Calls:
clonetoValue (from vue)
Code
Interfaces¶
UseClonedOptions<T = any>¶
Interface Code
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
clone |
(source: T) => T |
✓ | not shown |
manual |
boolean |
✓ | not shown |
UseClonedReturn<T>¶
Interface Code
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
cloned |
Ref<T> |
✗ | not shown |
isModified |
Ref<boolean> |
✗ | not shown |
sync |
() => void |
✗ | not shown |
Type Aliases¶
CloneFn<F, T = F>¶
Generated by Syntax Scribe