]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
types(runtime-vapor): add modifiers & argument type
author三咲智子 Kevin Deng <sxzz@sxzz.moe>
Thu, 7 Dec 2023 02:46:34 +0000 (10:46 +0800)
committer三咲智子 Kevin Deng <sxzz@sxzz.moe>
Thu, 7 Dec 2023 02:46:34 +0000 (10:46 +0800)
packages/runtime-vapor/src/directives.ts

index 7060a92f4f6584df06753db235cfd45f93f6c568..70833e97320a5705928a55d28aab3c58b623b157 100644 (file)
@@ -1,41 +1,62 @@
 import { isFunction } from '@vue/shared'
 import { currentInstance, type ComponentInternalInstance } from './component'
-import type { DirectiveModifiers } from '@vue/runtime-dom'
 
-export interface DirectiveBinding<V = any> {
+export type DirectiveModifiers<M extends string = string> = Record<M, boolean>
+
+export interface DirectiveBinding<
+  V = any,
+  A = string,
+  M extends string = string,
+> {
   instance: ComponentInternalInstance | null
   value: V
   oldValue: V | null
-  arg?: string
-  modifiers?: DirectiveModifiers
+  arg?: A
+  modifiers?: DirectiveModifiers<M>
   dir: ObjectDirective<any, V>
 }
 
-export type DirectiveHook<T = any | null, V = any> = (
-  node: T,
-  binding: DirectiveBinding<V>,
-) => void
+export type DirectiveHook<
+  T = any | null,
+  V = any,
+  A = string,
+  M extends string = string,
+> = (node: T, binding: DirectiveBinding<V, A, M>) => void
 
 // create node -> `created` -> node operation -> `beforeMount` -> node mounted -> `mounted`
 // effect update -> `beforeUpdate` -> node updated -> `updated`
 // `beforeUnmount`-> node unmount -> `unmounted`
-export interface ObjectDirective<T = any, V = any> {
-  created?: DirectiveHook<T, V>
-  beforeMount?: DirectiveHook<T, V>
-  mounted?: DirectiveHook<T, V>
-  // beforeUpdate?: DirectiveHook<T, V>
-  // updated?: DirectiveHook<T, V>
-  beforeUnmount?: DirectiveHook<T, V>
-  unmounted?: DirectiveHook<T, V>
+export interface ObjectDirective<
+  T = any,
+  V = any,
+  A = string,
+  M extends string = string,
+> {
+  created?: DirectiveHook<T, V, A, M>
+  beforeMount?: DirectiveHook<T, V, A, M>
+  mounted?: DirectiveHook<T, V, A, M>
+  // beforeUpdate?: DirectiveHook<T, V,A,M>
+  // updated?: DirectiveHook<T, V,A,M>
+  beforeUnmount?: DirectiveHook<T, V, A, M>
+  unmounted?: DirectiveHook<T, V, A, M>
   // getSSRProps?: SSRDirectiveHook
   // deep?: boolean
 }
 export type DirectiveHookName = Exclude<keyof ObjectDirective, 'deep'>
 
-export type FunctionDirective<T = any, V = any> = DirectiveHook<T, V>
-export type Directive<T = any, V = any> =
-  | ObjectDirective<T, V>
-  | FunctionDirective<T, V>
+export type FunctionDirective<
+  T = any,
+  V = any,
+  A = string,
+  M extends string = string,
+> = DirectiveHook<T, V, A, M>
+
+export type Directive<
+  T = any,
+  V = any,
+  A = string,
+  M extends string = string,
+> = ObjectDirective<T, V, A, M> | FunctionDirective<T, V, A, M>
 
 export type DirectiveArguments = Array<
   | [Directive | undefined]