Home / File/ apiLifecycle.ts — vue Source File

apiLifecycle.ts — vue Source File

Architecture documentation for apiLifecycle.ts, a typescript file in the vue codebase. 5 imports, 0 dependents.

File typescript VueCore VDom 5 imports 6 functions

Entity Profile

Dependency Diagram

graph LR
  8df087fa_469a_a5bf_ab87_3d7db45481ea["apiLifecycle.ts"]
  85e1f909_7644_0ca7_f1dd_88c92922f129["debug.ts"]
  8df087fa_469a_a5bf_ab87_3d7db45481ea --> 85e1f909_7644_0ca7_f1dd_88c92922f129
  7427dd7d_5a1e_66d2_9e2c_3feb5fce3308["DebuggerEvent"]
  8df087fa_469a_a5bf_ab87_3d7db45481ea --> 7427dd7d_5a1e_66d2_9e2c_3feb5fce3308
  76672dd6_4e87_4468_a48b_f4da793fd211["index.ts"]
  8df087fa_469a_a5bf_ab87_3d7db45481ea --> 76672dd6_4e87_4468_a48b_f4da793fd211
  9f3b1774_ebd5_0845_1a85_868e0c1fd480["currentInstance.ts"]
  8df087fa_469a_a5bf_ab87_3d7db45481ea --> 9f3b1774_ebd5_0845_1a85_868e0c1fd480
  64c87498_c46a_6944_ab9d_8e45519852a8["component"]
  8df087fa_469a_a5bf_ab87_3d7db45481ea --> 64c87498_c46a_6944_ab9d_8e45519852a8
  style 8df087fa_469a_a5bf_ab87_3d7db45481ea fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { DebuggerEvent } from './debug'
import { Component } from 'types/component'
import { mergeLifecycleHook, warn } from '../core/util'
import { currentInstance } from './currentInstance'

function createLifeCycle<T extends (...args: any[]) => any = () => void>(
  hookName: string
) {
  return (fn: T, target: any = currentInstance) => {
    if (!target) {
      __DEV__ &&
        warn(
          `${formatName(
            hookName
          )} is called when there is no active component instance to be ` +
            `associated with. ` +
            `Lifecycle injection APIs can only be used during execution of setup().`
        )
      return
    }
    return injectHook(target, hookName, fn)
  }
}

function formatName(name: string) {
  if (name === 'beforeDestroy') {
    name = 'beforeUnmount'
  } else if (name === 'destroyed') {
    name = 'unmounted'
  }
  return `on${name[0].toUpperCase() + name.slice(1)}`
}

function injectHook(instance: Component, hookName: string, fn: () => void) {
  const options = instance.$options
  options[hookName] = mergeLifecycleHook(options[hookName], fn)
}

export const onBeforeMount = createLifeCycle('beforeMount')
export const onMounted = createLifeCycle('mounted')
export const onBeforeUpdate = createLifeCycle('beforeUpdate')
export const onUpdated = createLifeCycle('updated')
export const onBeforeUnmount = createLifeCycle('beforeDestroy')
export const onUnmounted = createLifeCycle('destroyed')
export const onActivated = createLifeCycle('activated')
export const onDeactivated = createLifeCycle('deactivated')
export const onServerPrefetch = createLifeCycle('serverPrefetch')

export const onRenderTracked =
  createLifeCycle<(e: DebuggerEvent) => any>('renderTracked')
export const onRenderTriggered =
  createLifeCycle<(e: DebuggerEvent) => any>('renderTriggered')

export type ErrorCapturedHook<TError = unknown> = (
  err: TError,
  instance: any,
  info: string
) => boolean | void

const injectErrorCapturedHook =
  createLifeCycle<ErrorCapturedHook<any>>('errorCaptured')

export function onErrorCaptured<TError = Error>(
  hook: ErrorCapturedHook<TError>,
  target: any = currentInstance
) {
  injectErrorCapturedHook(hook, target)
}

Domain

Subdomains

Frequently Asked Questions

What does apiLifecycle.ts do?
apiLifecycle.ts is a source file in the vue codebase, written in typescript. It belongs to the VueCore domain, VDom subdomain.
What functions are defined in apiLifecycle.ts?
apiLifecycle.ts defines 6 function(s): createLifeCycle, e, err, formatName, injectHook, onErrorCaptured.
What does apiLifecycle.ts depend on?
apiLifecycle.ts imports 5 module(s): DebuggerEvent, component, currentInstance.ts, debug.ts, index.ts.
Where is apiLifecycle.ts in the architecture?
apiLifecycle.ts is located at src/v3/apiLifecycle.ts (domain: VueCore, subdomain: VDom, directory: src/v3).

Analyze Your Own Codebase

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

Try Supermodel Free