Home / Function/ enter() — vue Function Reference

enter() — vue Function Reference

Architecture documentation for the enter() function in transition.ts from the vue codebase.

Entity Profile

Dependency Diagram

graph TD
  ba54cdc9_f934_43fb_f1d2_3319595d4c1d["enter()"]
  3c48df22_8120_1441_419e_fb53854bac7a["default.bind()"]
  3c48df22_8120_1441_419e_fb53854bac7a -->|calls| ba54cdc9_f934_43fb_f1d2_3319595d4c1d
  7252c3d1_00b4_fa7a_aff5_325056c580fa["default.update()"]
  7252c3d1_00b4_fa7a_aff5_325056c580fa -->|calls| ba54cdc9_f934_43fb_f1d2_3319595d4c1d
  8f16788c_1671_91c0_0620_97749b409e40["_enter()"]
  8f16788c_1671_91c0_0620_97749b409e40 -->|calls| ba54cdc9_f934_43fb_f1d2_3319595d4c1d
  5b855538_2046_796e_16f9_7327a61399cb["isDef()"]
  ba54cdc9_f934_43fb_f1d2_3319595d4c1d -->|calls| 5b855538_2046_796e_16f9_7327a61399cb
  15b015fc_372e_005b_54dc_67a7bfbde5be["resolveTransition()"]
  ba54cdc9_f934_43fb_f1d2_3319595d4c1d -->|calls| 15b015fc_372e_005b_54dc_67a7bfbde5be
  299f2646_f776_9b7d_1179_7b9087b1e66c["isUndef()"]
  ba54cdc9_f934_43fb_f1d2_3319595d4c1d -->|calls| 299f2646_f776_9b7d_1179_7b9087b1e66c
  b6885901_8acd_8c4a_af15_cbd768bcd57b["isFunction()"]
  ba54cdc9_f934_43fb_f1d2_3319595d4c1d -->|calls| b6885901_8acd_8c4a_af15_cbd768bcd57b
  f5c3f348_7420_2758_1e07_011bdc52d282["toNumber()"]
  ba54cdc9_f934_43fb_f1d2_3319595d4c1d -->|calls| f5c3f348_7420_2758_1e07_011bdc52d282
  3d975ef8_6070_36a5_82f8_9180576e2ca1["isObject()"]
  ba54cdc9_f934_43fb_f1d2_3319595d4c1d -->|calls| 3d975ef8_6070_36a5_82f8_9180576e2ca1
  487bc2a1_c3e0_3929_69c5_7a7737ce683e["checkDuration()"]
  ba54cdc9_f934_43fb_f1d2_3319595d4c1d -->|calls| 487bc2a1_c3e0_3929_69c5_7a7737ce683e
  ef3b1734_589d_ca16_c8a8_f015ea1202b6["getHookArgumentsLength()"]
  ba54cdc9_f934_43fb_f1d2_3319595d4c1d -->|calls| ef3b1734_589d_ca16_c8a8_f015ea1202b6
  a8e0e452_e7c0_9fb5_f4fe_58e890a49204["once()"]
  ba54cdc9_f934_43fb_f1d2_3319595d4c1d -->|calls| a8e0e452_e7c0_9fb5_f4fe_58e890a49204
  d0ac78d7_5041_1236_9a5b_88482b24b402["removeTransitionClass()"]
  ba54cdc9_f934_43fb_f1d2_3319595d4c1d -->|calls| d0ac78d7_5041_1236_9a5b_88482b24b402
  5da207be_c15b_b75c_a486_6bdb569d90ee["addTransitionClass()"]
  ba54cdc9_f934_43fb_f1d2_3319595d4c1d -->|calls| 5da207be_c15b_b75c_a486_6bdb569d90ee
  style ba54cdc9_f934_43fb_f1d2_3319595d4c1d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/platforms/web/runtime/modules/transition.ts lines 25–167

export function enter(vnode: VNodeWithData, toggleDisplay?: () => void) {
  const el: any = vnode.elm

  // call leave callback now
  if (isDef(el._leaveCb)) {
    el._leaveCb.cancelled = true
    el._leaveCb()
  }

  const data = resolveTransition(vnode.data.transition)
  if (isUndef(data)) {
    return
  }

  /* istanbul ignore if */
  if (isDef(el._enterCb) || el.nodeType !== 1) {
    return
  }

  const {
    css,
    type,
    enterClass,
    enterToClass,
    enterActiveClass,
    appearClass,
    appearToClass,
    appearActiveClass,
    beforeEnter,
    enter,
    afterEnter,
    enterCancelled,
    beforeAppear,
    appear,
    afterAppear,
    appearCancelled,
    duration
  } = data

  // activeInstance will always be the <transition> component managing this
  // transition. One edge case to check is when the <transition> is placed
  // as the root node of a child component. In that case we need to check
  // <transition>'s parent for appear check.
  let context = activeInstance
  let transitionNode = activeInstance.$vnode
  while (transitionNode && transitionNode.parent) {
    context = transitionNode.context
    transitionNode = transitionNode.parent
  }

  const isAppear = !context._isMounted || !vnode.isRootInsert

  if (isAppear && !appear && appear !== '') {
    return
  }

  const startClass = isAppear && appearClass ? appearClass : enterClass
  const activeClass =
    isAppear && appearActiveClass ? appearActiveClass : enterActiveClass
  const toClass = isAppear && appearToClass ? appearToClass : enterToClass

  const beforeEnterHook = isAppear ? beforeAppear || beforeEnter : beforeEnter
  const enterHook = isAppear ? (isFunction(appear) ? appear : enter) : enter
  const afterEnterHook = isAppear ? afterAppear || afterEnter : afterEnter
  const enterCancelledHook = isAppear
    ? appearCancelled || enterCancelled
    : enterCancelled

  const explicitEnterDuration: any = toNumber(
    isObject(duration) ? duration.enter : duration
  )

  if (__DEV__ && explicitEnterDuration != null) {
    checkDuration(explicitEnterDuration, 'enter', vnode)
  }

  const expectsCSS = css !== false && !isIE9
  const userWantsControl = getHookArgumentsLength(enterHook)

  const cb = (el._enterCb = once(() => {
    if (expectsCSS) {
      removeTransitionClass(el, toClass)
      removeTransitionClass(el, activeClass)
    }
    // @ts-expect-error
    if (cb.cancelled) {
      if (expectsCSS) {
        removeTransitionClass(el, startClass)
      }
      enterCancelledHook && enterCancelledHook(el)
    } else {
      afterEnterHook && afterEnterHook(el)
    }
    el._enterCb = null
  }))

  if (!vnode.data.show) {
    // remove pending leave element on enter by injecting an insert hook
    mergeVNodeHook(vnode, 'insert', () => {
      const parent = el.parentNode
      const pendingNode =
        parent && parent._pending && parent._pending[vnode.key!]
      if (
        pendingNode &&
        pendingNode.tag === vnode.tag &&
        pendingNode.elm._leaveCb
      ) {
        pendingNode.elm._leaveCb()
      }
      enterHook && enterHook(el, cb)
    })
  }

  // start enter transition
  beforeEnterHook && beforeEnterHook(el)
  if (expectsCSS) {
    addTransitionClass(el, startClass)
    addTransitionClass(el, activeClass)
    nextFrame(() => {
      removeTransitionClass(el, startClass)
      // @ts-expect-error
      if (!cb.cancelled) {
        addTransitionClass(el, toClass)
        if (!userWantsControl) {
          if (isValidDuration(explicitEnterDuration)) {
            setTimeout(cb, explicitEnterDuration)
          } else {
            whenTransitionEnds(el, type, cb)
          }
        }
      }
    })
  }

  if (vnode.data.show) {
    toggleDisplay && toggleDisplay()
    enterHook && enterHook(el, cb)
  }

  if (!expectsCSS && !userWantsControl) {
    cb()
  }
}

Domain

Subdomains

Frequently Asked Questions

What does enter() do?
enter() is a function in the vue codebase.
What does enter() call?
enter() calls 14 function(s): addTransitionClass, checkDuration, getHookArgumentsLength, isDef, isFunction, isObject, isUndef, isValidDuration, and 6 more.
What calls enter()?
enter() is called by 3 function(s): _enter, default.bind, default.update.

Analyze Your Own Codebase

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

Try Supermodel Free