refactor: applyDirectives -> withDirectives

This commit is contained in:
Evan You
2019-10-18 16:35:01 -04:00
parent cba34453db
commit e98a85f3cb
20 changed files with 63 additions and 64 deletions

View File

@@ -8,7 +8,7 @@ import {
inject,
resolveComponent,
resolveDirective,
applyDirectives,
withDirectives,
Plugin,
ref,
getCurrentInstance
@@ -128,7 +128,7 @@ describe('api: createApp', () => {
return () => {
// resolve in render
const BarBaz = resolveDirective('bar-baz')!
return applyDirectives(h('div'), [[FooBar], [BarBaz]])
return withDirectives(h('div'), [[FooBar], [BarBaz]])
}
}
}

View File

@@ -1,6 +1,6 @@
import {
h,
applyDirectives,
withDirectives,
ref,
render,
nodeOps,
@@ -107,7 +107,7 @@ describe('directives', () => {
},
render() {
_prevVnode = _vnode
_vnode = applyDirectives(h('div', count.value), [
_vnode = withDirectives(h('div', count.value), [
[
{
beforeMount,
@@ -174,7 +174,7 @@ describe('directives', () => {
},
render() {
_prevVnode = _vnode
_vnode = applyDirectives(h('div', count.value), [
_vnode = withDirectives(h('div', count.value), [
[
fn,
// value

View File

@@ -11,8 +11,8 @@ return applyDirectives(h(comp), [
])
*/
import { VNode, cloneVNode } from './vnode'
import { extend, isArray, isFunction, EMPTY_OBJ, makeMap } from '@vue/shared'
import { VNode } from './vnode'
import { isArray, isFunction, EMPTY_OBJ, makeMap } from '@vue/shared'
import { warn } from './warning'
import { ComponentInternalInstance } from './component'
import { currentRenderingInstance } from './componentRenderUtils'
@@ -120,11 +120,10 @@ export type DirectiveArguments = Array<
| [Directive, any, string, DirectiveModifiers]
>
export function applyDirectives(vnode: VNode, directives: DirectiveArguments) {
export function withDirectives(vnode: VNode, directives: DirectiveArguments) {
const instance = currentRenderingInstance
if (instance !== null) {
vnode = cloneVNode(vnode)
vnode.props = vnode.props != null ? extend({}, vnode.props) : {}
vnode.props = vnode.props || {}
for (let i = 0; i < directives.length; i++) {
const [dir, value, arg, modifiers] = directives[i]
applyDirective(vnode.props, instance, dir, value, arg, modifiers)

View File

@@ -38,7 +38,7 @@ export {
// Internal, for compiler generated code
// should sync with '@vue/compiler-core/src/runtimeConstants.ts'
export { applyDirectives } from './directives'
export { withDirectives } from './directives'
export {
resolveComponent,
resolveDirective,