Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 = <T extends Function = () => 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<DebuggerHook>( | ||
LifecycleHooks.RENDER_TRIGGERED | ||
) | ||
export const onRenderTracked = createHook<DebuggerHook>( | ||
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters