Home / Function/ registerRef() — vue Function Reference

registerRef() — vue Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  929b2960_01b4_a2f3_80ea_6c6432422d9d["registerRef()"]
  1b2870ce_f4b6_02ff_e22c_d894ac27f198["default.create()"]
  1b2870ce_f4b6_02ff_e22c_d894ac27f198 -->|calls| 929b2960_01b4_a2f3_80ea_6c6432422d9d
  c2aa06df_e982_bf95_390c_b244927649f7["default.update()"]
  c2aa06df_e982_bf95_390c_b244927649f7 -->|calls| 929b2960_01b4_a2f3_80ea_6c6432422d9d
  ea45b520_6cb2_85f0_9ebe_22ea354d900d["default.destroy()"]
  ea45b520_6cb2_85f0_9ebe_22ea354d900d -->|calls| 929b2960_01b4_a2f3_80ea_6c6432422d9d
  2da82d37_d0a8_bdfd_86ba_26432270288e["createPatchFunction()"]
  2da82d37_d0a8_bdfd_86ba_26432270288e -->|calls| 929b2960_01b4_a2f3_80ea_6c6432422d9d
  0e8bc21e_ce42_dee3_5589_a01d0fb30ae2["setSetupRef()"]
  929b2960_01b4_a2f3_80ea_6c6432422d9d -->|calls| 0e8bc21e_ce42_dee3_5589_a01d0fb30ae2
  style 929b2960_01b4_a2f3_80ea_6c6432422d9d 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