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
  d9e5faa1_4c9d_b2bf_9290_ab75e74e7a14["_update()"]
  4036798a_19ff_2efe_d369_f25854a46611["updateDirectives()"]
  4036798a_19ff_2efe_d369_f25854a46611 -->|calls| d9e5faa1_4c9d_b2bf_9290_ab75e74e7a14
  567835e8_9ddc_72aa_a76a_eaa073ab13ad["normalizeDirectives()"]
  d9e5faa1_4c9d_b2bf_9290_ab75e74e7a14 -->|calls| 567835e8_9ddc_72aa_a76a_eaa073ab13ad
  20bda32c_a499_5eb2_2234_b07d26db30bb["callHook()"]
  d9e5faa1_4c9d_b2bf_9290_ab75e74e7a14 -->|calls| 20bda32c_a499_5eb2_2234_b07d26db30bb
  style d9e5faa1_4c9d_b2bf_9290_ab75e74e7a14 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