Home / Function/ _update() — vue Function Reference

_update() — vue Function Reference

Architecture documentation for the _update() function in directives.ts from the vue codebase.

Entity Profile

Dependency Diagram

graph TD
  b91b554e_74a2_233a_0bd9_3f9cf7cb3052["_update()"]
  4529b9f4_4283_ae07_a64e_e5d420ede21e["updateDirectives()"]
  4529b9f4_4283_ae07_a64e_e5d420ede21e -->|calls| b91b554e_74a2_233a_0bd9_3f9cf7cb3052
  7d1db663_ac2f_906c_6f45_82393aeeb280["normalizeDirectives()"]
  b91b554e_74a2_233a_0bd9_3f9cf7cb3052 -->|calls| 7d1db663_ac2f_906c_6f45_82393aeeb280
  7fd87ce8_4e1d_b663_7a3b_59efd7c1e6dc["callHook()"]
  b91b554e_74a2_233a_0bd9_3f9cf7cb3052 -->|calls| 7fd87ce8_4e1d_b663_7a3b_59efd7c1e6dc
  style b91b554e_74a2_233a_0bd9_3f9cf7cb3052 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/core/vdom/modules/directives.ts lines 22–84

function _update(oldVnode, vnode) {
  const isCreate = oldVnode === emptyNode
  const isDestroy = vnode === emptyNode
  const oldDirs = normalizeDirectives(
    oldVnode.data.directives,
    oldVnode.context
  )
  const newDirs = normalizeDirectives(vnode.data.directives, vnode.context)

  const dirsWithInsert: any[] = []
  const dirsWithPostpatch: any[] = []

  let key, oldDir, dir
  for (key in newDirs) {
    oldDir = oldDirs[key]
    dir = newDirs[key]
    if (!oldDir) {
      // new directive, bind
      callHook(dir, 'bind', vnode, oldVnode)
      if (dir.def && dir.def.inserted) {
        dirsWithInsert.push(dir)
      }
    } else {
      // existing directive, update
      dir.oldValue = oldDir.value
      dir.oldArg = oldDir.arg
      callHook(dir, 'update', vnode, oldVnode)
      if (dir.def && dir.def.componentUpdated) {
        dirsWithPostpatch.push(dir)
      }
    }
  }

  if (dirsWithInsert.length) {
    const callInsert = () => {
      for (let i = 0; i < dirsWithInsert.length; i++) {
        callHook(dirsWithInsert[i], 'inserted', vnode, oldVnode)
      }
    }
    if (isCreate) {
      mergeVNodeHook(vnode, 'insert', callInsert)
    } else {
      callInsert()
    }
  }

  if (dirsWithPostpatch.length) {
    mergeVNodeHook(vnode, 'postpatch', () => {
      for (let i = 0; i < dirsWithPostpatch.length; i++) {
        callHook(dirsWithPostpatch[i], 'componentUpdated', vnode, oldVnode)
      }
    })
  }

  if (!isCreate) {
    for (key in oldDirs) {
      if (!newDirs[key]) {
        // no longer present, unbind
        callHook(oldDirs[key], 'unbind', oldVnode, oldVnode, isDestroy)
      }
    }
  }
}

Domain

Subdomains

Called By

Frequently Asked Questions

What does _update() do?
_update() is a function in the vue codebase.
What does _update() call?
_update() calls 2 function(s): callHook, normalizeDirectives.
What calls _update()?
_update() is called by 1 function(s): updateDirectives.

Analyze Your Own Codebase

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

Try Supermodel Free