feat(runtime-dom): v-model directive runtime

This commit is contained in:
Evan You
2019-10-11 17:55:20 -04:00
parent a371b2ec0e
commit a42ad6cc9d
5 changed files with 262 additions and 47 deletions

View File

@@ -12,7 +12,7 @@ return applyDirectives(h(comp), [
*/
import { VNode, cloneVNode } from './vnode'
import { extend, isArray, isFunction } from '@vue/shared'
import { extend, isArray, isFunction, EMPTY_OBJ } from '@vue/shared'
import { warn } from './warning'
import { ComponentInternalInstance } from './component'
import { currentRenderingInstance } from './componentRenderUtils'
@@ -21,26 +21,26 @@ import { ComponentPublicInstance } from './componentProxy'
export interface DirectiveBinding {
instance: ComponentPublicInstance | null
value?: any
oldValue?: any
value: any
oldValue: any
arg?: string
modifiers?: DirectiveModifiers
modifiers: DirectiveModifiers
}
export type DirectiveHook = (
el: any,
export type DirectiveHook<T = any> = (
el: T,
binding: DirectiveBinding,
vnode: VNode,
vnode: VNode<any, T>,
prevVNode: VNode | null
) => void
export interface Directive {
beforeMount?: DirectiveHook
mounted?: DirectiveHook
beforeUpdate?: DirectiveHook
updated?: DirectiveHook
beforeUnmount?: DirectiveHook
unmounted?: DirectiveHook
export interface Directive<T = any> {
beforeMount?: DirectiveHook<T>
mounted?: DirectiveHook<T>
beforeUpdate?: DirectiveHook<T>
updated?: DirectiveHook<T>
beforeUnmount?: DirectiveHook<T>
unmounted?: DirectiveHook<T>
}
type DirectiveModifiers = Record<string, boolean>
@@ -53,7 +53,7 @@ function applyDirective(
directive: Directive,
value?: any,
arg?: string,
modifiers?: DirectiveModifiers
modifiers: DirectiveModifiers = EMPTY_OBJ
) {
let valueCacheForDir = valueCache.get(directive)!
if (!valueCacheForDir) {