DirectiveBinding,
nextTick
} from '@vue/runtime-test'
+import { currentInstance, ComponentInternalInstance } from '../src/component'
describe('directives', () => {
it('should work', async () => {
function assertBindings(binding: DirectiveBinding) {
expect(binding.value).toBe(count.value)
expect(binding.arg).toBe('foo')
+ expect(binding.instance).toBe(_instance && _instance.proxy)
expect(binding.modifiers && binding.modifiers.ok).toBe(true)
}
unmounted
}
+ let _instance: ComponentInternalInstance | null = null
let _vnode: VNode | null = null
let _prevVnode: VNode | null = null
const Comp = {
+ setup() {
+ _instance = currentInstance
+ },
render() {
_prevVnode = _vnode
_vnode = withDirectives(h('div', count.value), [
function assertBindings(binding: DirectiveBinding) {
expect(binding.value).toBe(count.value)
expect(binding.arg).toBe('foo')
+ expect(binding.instance).toBe(_instance && _instance.proxy)
expect(binding.modifiers && binding.modifiers.ok).toBe(true)
}
expect(prevVNode).toBe(_prevVnode)
}) as DirectiveHook)
+ let _instance: ComponentInternalInstance | null = null
let _vnode: VNode | null = null
let _prevVnode: VNode | null = null
const Comp = {
+ setup() {
+ _instance = currentInstance
+ },
render() {
_prevVnode = _vnode
_vnode = withDirectives(h('div', count.value), [
function assertBindings(binding: DirectiveBinding) {
expect(binding.value).toBe(count.value)
expect(binding.arg).toBe('foo')
+ expect(binding.instance).toBe(_instance && _instance.proxy)
expect(binding.modifiers && binding.modifiers.ok).toBe(true)
}
unmounted
}
+ let _instance: ComponentInternalInstance | null = null
let _vnode: VNode | null = null
let _prevVnode: VNode | null = null
}
const Comp = {
+ setup() {
+ _instance = currentInstance
+ },
render() {
return withDirectives(h(Child, { count: count.value }), [
[
import { isFunction, EMPTY_OBJ, makeMap, EMPTY_ARR } from '@vue/shared'
import { warn } from './warning'
import { ComponentInternalInstance } from './component'
+import { currentRenderingInstance } from './componentRenderUtils'
import { callWithAsyncErrorHandling, ErrorCodes } from './errorHandling'
+import { ComponentPublicInstance } from './componentProxy'
export interface DirectiveBinding {
+ instance: ComponentPublicInstance | null
value: any
oldValue: any
arg?: string
vnode: T,
directives: DirectiveArguments
): T {
+ const internalInstance = currentRenderingInstance
+ if (internalInstance === null) {
+ __DEV__ && warn(`withDirectives can only be used inside render functions.`)
+ return vnode
+ }
+ const instance = internalInstance.proxy
const props = vnode.props || (vnode.props = {})
- const bindings: DirectiveBinding[] =
- vnode.dirs || (vnode.dirs = new Array(directives.length))
+ const bindings = vnode.dirs || (vnode.dirs = new Array(directives.length))
const injected: Record<string, true> = {}
for (let i = 0; i < directives.length; i++) {
let [dir, value, arg, modifiers = EMPTY_OBJ] = directives[i]
}
bindings[i] = {
dir,
+ instance,
value,
oldValue: void 0,
arg,