diff --git a/packages/runtime-core/src/apiLifecycle.ts b/packages/runtime-core/src/apiLifecycle.ts index 9efc4fa..017a7a4 100644 --- a/packages/runtime-core/src/apiLifecycle.ts +++ b/packages/runtime-core/src/apiLifecycle.ts @@ -1,10 +1,50 @@ import { DebuggerEvent } from '@vue/reactivity' +import { + ComponentInternalInstance, + currentInstance, + isInSSRComponentSetup, + LifecycleHooks +} from './component' import { ComponentPublicInstance } from './componentPublicInstance' +export function injectHook( + type: LifecycleHooks, + hook: Function & { __weh?: Function }, + target: ComponentInternalInstance | null = currentInstance, + prepend: boolean = false +): Function | undefined { + // TODO + return +} + +export const createHook = any>( + lifecycle: LifecycleHooks +) => (hook: T, target: ComponentInternalInstance | null = currentInstance) => + !isInSSRComponentSetup && injectHook(lifecycle, hook, target) + +export const onBeforeMount = createHook(LifecycleHooks.BEFORE_MOUNT) +export const onMounted = createHook(LifecycleHooks.MOUNTED) +export const onBeforeUpdate = createHook(LifecycleHooks.BEFORE_UPDATE) +export const onUpdated = createHook(LifecycleHooks.UPDATED) +export const onUnMount = createHook(LifecycleHooks.UNMOUNTED) + export type DebuggerHook = (e: DebuggerEvent) => void +export const onRenderTriggered = createHook( + LifecycleHooks.RENDER_TRIGGERED +) +export const onRenderTracked = createHook( + LifecycleHooks.RENDER_TRACKED +) export type ErrorCapturedHook = ( err: unknown, instance: ComponentPublicInstance | null, info: string ) => boolean | void + +export const onErrorCaptured = ( + hook: ErrorCapturedHook, + target: ComponentInternalInstance | null = currentInstance +) => { + injectHook(LifecycleHooks.ERROR_CAPTURED, hook, target) +} diff --git a/packages/runtime-core/src/component.ts b/packages/runtime-core/src/component.ts index ba43888..8214f98 100644 --- a/packages/runtime-core/src/component.ts +++ b/packages/runtime-core/src/component.ts @@ -375,6 +375,8 @@ export function validateComponentName(name: string, config: AppConfig) { } } +export let isInSSRComponentSetup = false + type CompileFunction = ( template: string | object, options?: CompilerOptions