Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

types(runtime-core): support type with directive value #1007

Merged
merged 1 commit into from
Jun 11, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions packages/runtime-core/src/directives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ import { currentRenderingInstance } from './componentRenderUtils'
import { callWithAsyncErrorHandling, ErrorCodes } from './errorHandling'
import { ComponentPublicInstance } from './componentProxy'

export interface DirectiveBinding {
export interface DirectiveBinding<V = any> {
instance: ComponentPublicInstance | null
value: any
oldValue: any
value: V
oldValue: V | null
arg?: string
modifiers: DirectiveModifiers
dir: ObjectDirective
dir: ObjectDirective<any, V>
}

export type DirectiveHook<T = any, Prev = VNode<any, T> | null> = (
export type DirectiveHook<T = any, Prev = VNode<any, T> | null, V = any> = (
el: T,
binding: DirectiveBinding,
binding: DirectiveBinding<V>,
vnode: VNode<any, T>,
prevVNode: Prev
) => void
Expand All @@ -40,19 +40,21 @@ export type SSRDirectiveHook = (
vnode: VNode
) => Data | undefined

export interface ObjectDirective<T = any> {
beforeMount?: DirectiveHook<T, null>
mounted?: DirectiveHook<T, null>
beforeUpdate?: DirectiveHook<T, VNode<any, T>>
updated?: DirectiveHook<T, VNode<any, T>>
beforeUnmount?: DirectiveHook<T, null>
unmounted?: DirectiveHook<T, null>
export interface ObjectDirective<T = any, V = any> {
beforeMount?: DirectiveHook<T, null, V>
mounted?: DirectiveHook<T, null, V>
beforeUpdate?: DirectiveHook<T, VNode<any, T>, V>
updated?: DirectiveHook<T, VNode<any, T>, V>
beforeUnmount?: DirectiveHook<T, null, V>
unmounted?: DirectiveHook<T, null, V>
getSSRProps?: SSRDirectiveHook
}

export type FunctionDirective<T = any> = DirectiveHook<T>
export type FunctionDirective<T = any, V = any> = DirectiveHook<T, any, V>

export type Directive<T = any> = ObjectDirective<T> | FunctionDirective<T>
export type Directive<T = any, V = any> =
| ObjectDirective<T, V>
| FunctionDirective<T, V>

export type DirectiveModifiers = Record<string, boolean>

Expand Down