mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
fix(nuxt3): add types for runtime hooks (and fix page:finished
) (#455)
Co-authored-by: Pooya Parsa <pyapar@gmail.com>
This commit is contained in:
parent
45f898e108
commit
16b769d6b9
@ -44,7 +44,7 @@ if (process.client) {
|
||||
await nuxt.hooks.callHook('app:created', app)
|
||||
await nuxt.hooks.callHook('app:beforeMount', app)
|
||||
|
||||
nuxt.hooks.hookOnce('page:finished', () => {
|
||||
nuxt.hooks.hookOnce('page:finish', () => {
|
||||
nuxt.isHydrating = false
|
||||
})
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { getCurrentInstance } from 'vue'
|
||||
import type { App } from 'vue'
|
||||
import type { App, VNode } from 'vue'
|
||||
import Hookable from 'hookable'
|
||||
import { defineGetter } from './utils'
|
||||
import { legacyPlugin, LegacyContext } from './legacy'
|
||||
@ -13,13 +13,32 @@ type NuxtMeta = {
|
||||
bodyScripts?: string
|
||||
}
|
||||
|
||||
type HookResult = Promise<void> | void
|
||||
export interface RuntimeNuxtHooks {
|
||||
'app:created': (app: App<Element>) => HookResult
|
||||
'app:beforeMount': (app: App<Element>) => HookResult
|
||||
'app:mounted': (app: App<Element>) => HookResult
|
||||
'app:rendered': () => HookResult
|
||||
'page:start': (Component?: VNode) => HookResult
|
||||
'page:finish': (Component?: VNode) => HookResult
|
||||
}
|
||||
type NuxtAppHookName = keyof RuntimeNuxtHooks
|
||||
|
||||
export interface Nuxt {
|
||||
app: App
|
||||
globalName: string
|
||||
|
||||
hooks: Hookable
|
||||
hook: Hookable['hook']
|
||||
callHook: Hookable['callHook']
|
||||
hooks: {
|
||||
/** Register a function to be run when the named Nuxt hook is called. */
|
||||
hook<Hook extends NuxtAppHookName> (hookName: Hook, callback: RuntimeNuxtHooks[Hook]): HookResult
|
||||
hookOnce<Hook extends NuxtAppHookName> (hookName: Hook, callback: RuntimeNuxtHooks[Hook]): HookResult
|
||||
/** Run all Nuxt hooks that have been registered against the hook name. */
|
||||
callHook<Hook extends NuxtAppHookName> (hookName: Hook, ...args: Parameters<RuntimeNuxtHooks[Hook]>): ReturnType<RuntimeNuxtHooks[Hook]>
|
||||
/** Add all hooks in the object passed in. */
|
||||
addHooks (hooks: Partial<RuntimeNuxtHooks>): void
|
||||
}
|
||||
hook: Nuxt['hooks']['hook']
|
||||
callHook: Nuxt['hooks']['callHook']
|
||||
|
||||
[key: string]: any
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user