template-ref.ts — vue Source File
Architecture documentation for template-ref.ts, a typescript file in the vue codebase. 4 imports, 2 dependents.
Entity Profile
Dependency Diagram
graph LR b4d64c20_18f0_552d_559e_065753ef82cd["template-ref.ts"] 6d8f8976_7066_720b_0d45_45fe42921eaf["util"] b4d64c20_18f0_552d_559e_065753ef82cd --> 6d8f8976_7066_720b_0d45_45fe42921eaf ba925ef2_b0f4_efe3_c23d_fe293c46b2c1["vnode"] b4d64c20_18f0_552d_559e_065753ef82cd --> ba925ef2_b0f4_efe3_c23d_fe293c46b2c1 64c87498_c46a_6944_ab9d_8e45519852a8["component"] b4d64c20_18f0_552d_559e_065753ef82cd --> 64c87498_c46a_6944_ab9d_8e45519852a8 d970b406_3424_b00e_55dd_82e98ab5aac2["v3"] b4d64c20_18f0_552d_559e_065753ef82cd --> d970b406_3424_b00e_55dd_82e98ab5aac2 ffbd8cbb_fbc3_c5be_ca89_db209c2d38b1["index.ts"] ffbd8cbb_fbc3_c5be_ca89_db209c2d38b1 --> b4d64c20_18f0_552d_559e_065753ef82cd 020681fa_600e_5c84_6a4e_f1289077cc78["patch.ts"] 020681fa_600e_5c84_6a4e_f1289077cc78 --> b4d64c20_18f0_552d_559e_065753ef82cd style b4d64c20_18f0_552d_559e_065753ef82cd fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import {
remove,
isDef,
hasOwn,
isArray,
isFunction,
invokeWithErrorHandling,
warn
} from 'core/util'
import type { VNodeWithData } from 'types/vnode'
import { Component } from 'types/component'
import { isRef } from 'v3'
export default {
create(_: any, vnode: VNodeWithData) {
registerRef(vnode)
},
update(oldVnode: VNodeWithData, vnode: VNodeWithData) {
if (oldVnode.data.ref !== vnode.data.ref) {
registerRef(oldVnode, true)
registerRef(vnode)
}
},
destroy(vnode: VNodeWithData) {
registerRef(vnode, true)
}
}
export function registerRef(vnode: VNodeWithData, isRemoval?: boolean) {
const ref = vnode.data.ref
if (!isDef(ref)) return
const vm = vnode.context
const refValue = vnode.componentInstance || vnode.elm
const value = isRemoval ? null : refValue
const $refsValue = isRemoval ? undefined : refValue
if (isFunction(ref)) {
invokeWithErrorHandling(ref, vm, [value], vm, `template ref function`)
return
}
const isFor = vnode.data.refInFor
const _isString = typeof ref === 'string' || typeof ref === 'number'
const _isRef = isRef(ref)
const refs = vm.$refs
if (_isString || _isRef) {
if (isFor) {
const existing = _isString ? refs[ref] : ref.value
if (isRemoval) {
isArray(existing) && remove(existing, refValue)
} else {
if (!isArray(existing)) {
if (_isString) {
refs[ref] = [refValue]
setSetupRef(vm, ref, refs[ref])
} else {
ref.value = [refValue]
}
} else if (!existing.includes(refValue)) {
existing.push(refValue)
}
}
} else if (_isString) {
if (isRemoval && refs[ref] !== refValue) {
return
}
refs[ref] = $refsValue
setSetupRef(vm, ref, value)
} else if (_isRef) {
if (isRemoval && ref.value !== refValue) {
return
}
ref.value = value
} else if (__DEV__) {
warn(`Invalid template ref type: ${typeof ref}`)
}
}
}
function setSetupRef(
{ _setupState }: Component,
key: string | number,
val: any
) {
if (_setupState && hasOwn(_setupState, key as string)) {
if (isRef(_setupState[key])) {
_setupState[key].value = val
} else {
_setupState[key] = val
}
}
}
Domain
Subdomains
Dependencies
- component
- util
- v3
- vnode
Source
Frequently Asked Questions
What does template-ref.ts do?
template-ref.ts is a source file in the vue codebase, written in typescript. It belongs to the VueCore domain, GlobalAPI subdomain.
What functions are defined in template-ref.ts?
template-ref.ts defines 5 function(s): default.create, default.destroy, default.update, registerRef, setSetupRef.
What does template-ref.ts depend on?
template-ref.ts imports 4 module(s): component, util, v3, vnode.
What files import template-ref.ts?
template-ref.ts is imported by 2 file(s): index.ts, patch.ts.
Where is template-ref.ts in the architecture?
template-ref.ts is located at src/core/vdom/modules/template-ref.ts (domain: VueCore, subdomain: GlobalAPI, directory: src/core/vdom/modules).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free