Home / Function/ registerRef() — vue Function Reference

registerRef() — vue Function Reference

Architecture documentation for the registerRef() function in template-ref.ts from the vue codebase.

Function typescript CoreInstance VDOM calls 1 called by 4

Entity Profile

Dependency Diagram

graph TD
  e92873d4_293f_9488_86af_ed0867a761e4["registerRef()"]
  054b0cff_a5a7_ee68_ba8d_735cc4723328["default.create()"]
  054b0cff_a5a7_ee68_ba8d_735cc4723328 -->|calls| e92873d4_293f_9488_86af_ed0867a761e4
  addea082_c35b_e414_c7a1_941768813d2f["default.update()"]
  addea082_c35b_e414_c7a1_941768813d2f -->|calls| e92873d4_293f_9488_86af_ed0867a761e4
  62faf42e_c288_1a40_7516_612aa432c89f["default.destroy()"]
  62faf42e_c288_1a40_7516_612aa432c89f -->|calls| e92873d4_293f_9488_86af_ed0867a761e4
  b5b9b2bc_af65_0b4d_18a8_d754e24c79b1["createPatchFunction()"]
  b5b9b2bc_af65_0b4d_18a8_d754e24c79b1 -->|calls| e92873d4_293f_9488_86af_ed0867a761e4
  19c9bd1a_8ded_bda9_cb68_e25948978596["setSetupRef()"]
  e92873d4_293f_9488_86af_ed0867a761e4 -->|calls| 19c9bd1a_8ded_bda9_cb68_e25948978596
  style e92873d4_293f_9488_86af_ed0867a761e4 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/core/vdom/modules/template-ref.ts lines 29–80

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}`)
    }
  }
}

Domain

Subdomains

Frequently Asked Questions

What does registerRef() do?
registerRef() is a function in the vue codebase.
What does registerRef() call?
registerRef() calls 1 function(s): setSetupRef.
What calls registerRef()?
registerRef() is called by 4 function(s): createPatchFunction, default.create, default.destroy, default.update.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free