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 CompilerSFC ScriptAnalyzer 5 imports 6 functions

Entity Profile

Dependency Diagram

graph LR
  1dba970c_2182_6fa4_46b1_6faf85d0d083["apiLifecycle.ts"]
  304b1edc_7b13_538e_3309_079eb06f0a14["debug.ts"]
  1dba970c_2182_6fa4_46b1_6faf85d0d083 --> 304b1edc_7b13_538e_3309_079eb06f0a14
  a26914a6_abfc_f937_4a47_7f06aef89b00["DebuggerEvent"]
  1dba970c_2182_6fa4_46b1_6faf85d0d083 --> a26914a6_abfc_f937_4a47_7f06aef89b00
  2a298df2_21b8_7e5a_c372_51ba50c9d92d["index.ts"]
  1dba970c_2182_6fa4_46b1_6faf85d0d083 --> 2a298df2_21b8_7e5a_c372_51ba50c9d92d
  08d717e5_b9dd_701c_e7a2_51d83681d28a["currentInstance.ts"]
  1dba970c_2182_6fa4_46b1_6faf85d0d083 --> 08d717e5_b9dd_701c_e7a2_51d83681d28a
  907f4994_ea28_43b1_7976_0db9f0e97637["component"]
  1dba970c_2182_6fa4_46b1_6faf85d0d083 --> 907f4994_ea28_43b1_7976_0db9f0e97637
  style 1dba970c_2182_6fa4_46b1_6faf85d0d083 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 CompilerSFC domain, ScriptAnalyzer 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: CompilerSFC, subdomain: ScriptAnalyzer, directory: src/v3).

Analyze Your Own Codebase

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

Try Supermodel Free