Skip to content

Commit d164cf5

Browse files
committed
directive: always call update + ensure modifiers
1 parent 2c4fe07 commit d164cf5

File tree

8 files changed

+17
-38
lines changed

8 files changed

+17
-38
lines changed

src/core/vdom/modules/directives.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export default {
1717
}
1818
}
1919

20+
const emptyModifiers = Object.create(null)
21+
2022
function applyDirectives (
2123
oldVnode: VNodeWithData,
2224
vnode: VNodeWithData,
@@ -31,12 +33,11 @@ function applyDirectives (
3133
const def = resolveAsset(vnode.context.$options, 'directives', dir.name, true)
3234
const fn = def && def[hook]
3335
if (fn) {
34-
// only call update if value has changed
3536
if (isUpdate && oldDirs) {
36-
const oldValue = dir.oldValue = oldDirs[i].value
37-
if (oldValue === dir.value) {
38-
continue
39-
}
37+
dir.oldValue = oldDirs[i].value
38+
}
39+
if (!dir.modifiers) {
40+
dir.modifiers = emptyModifiers
4041
}
4142
fn(vnode.elm, dir, vnode, oldVnode)
4243
}

test/unit/features/options/directives.spec.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ describe('Options directives', () => {
3535
expect(el).toBe(vm.$el)
3636
expect(oldVnode).toBe(vm._vnode)
3737
expect(oldVnode).not.toBe(vnode)
38-
expect(binding.value).toBe('bar')
39-
expect(binding.oldValue).toBe('foo')
4038
expect(binding.expression).toBe('a')
39+
if (binding.value !== binding.oldValue) {
40+
expect(binding.value).toBe('bar')
41+
expect(binding.oldValue).toBe('foo')
42+
}
4143
},
4244
componentUpdated (el, binding, vnode) {
4345
componentUpdatedSpy()

test/unit/modules/vdom/modules/attrs.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { patch } from 'web/runtime/patch'
22
import VNode from 'core/vdom/vnode'
33
import { xlinkNS } from 'web/util/index'
44

5-
describe('attrs module', () => {
5+
describe('vdom attrs module', () => {
66
it('should create an element with staticAttrs', () => {
77
const vnode = new VNode('p', { staticAttrs: { id: 1, class: 'class1' }})
88
const elm = patch(null, vnode)

test/unit/modules/vdom/modules/class.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { patch } from 'web/runtime/patch'
22
import VNode from 'core/vdom/vnode'
33

4-
describe('class module', () => {
4+
describe('vdom class module', () => {
55
it('shuold create an element with staticClass', () => {
66
const vnode = new VNode('p', { staticClass: 'class1' })
77
const elm = patch(null, vnode)

test/unit/modules/vdom/modules/directive.spec.js

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import Vue from 'vue'
22
import { patch } from 'web/runtime/patch'
33
import VNode from 'core/vdom/vnode'
44

5-
describe('directive module', () => {
6-
it('should work directive', () => {
5+
describe('vdom directive module', () => {
6+
it('should work', () => {
77
const directive1 = {
88
bind: jasmine.createSpy('bind'),
99
update: jasmine.createSpy('update'),
@@ -35,28 +35,4 @@ describe('directive module', () => {
3535
patch(vnode2, vnode3)
3636
expect(directive1.unbind).toHaveBeenCalled()
3737
})
38-
39-
it('should not update when same binding value', () => {
40-
const directive1 = {
41-
update: jasmine.createSpy('update')
42-
}
43-
const vm = new Vue({ directives: { directive1 }})
44-
const vnode1 = new VNode('div', {}, [
45-
new VNode('p', {
46-
directives: [{
47-
name: 'directive1', value: 'hello', arg: 'arg1', modifiers: { modifire1: true }
48-
}]
49-
}, undefined, 'hello world', undefined, undefined, vm)
50-
])
51-
const vnode2 = new VNode('div', {}, [
52-
new VNode('p', {
53-
directives: [{
54-
name: 'directive1', value: 'hello', arg: 'arg1', modifiers: { modifire1: true }
55-
}]
56-
}, undefined, 'hello world', undefined, undefined, vm)
57-
])
58-
patch(null, vnode1)
59-
patch(vnode1, vnode2)
60-
expect(directive1.update).not.toHaveBeenCalled()
61-
})
6238
})

test/unit/modules/vdom/modules/events.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { patch } from 'web/runtime/patch'
22
import VNode from 'core/vdom/vnode'
33

4-
describe('events module', () => {
4+
describe('vdom events module', () => {
55
it('should attach event handler to element', () => {
66
const click = jasmine.createSpy()
77
const vnode = new VNode('a', { on: { click }})

test/unit/modules/vdom/modules/props.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { patch } from 'web/runtime/patch'
22
import VNode from 'core/vdom/vnode'
33

4-
describe('props module', () => {
4+
describe('vdom props module', () => {
55
it('should create an element with props', () => {
66
const vnode = new VNode('a', { props: { src: 'http://localhost/' }})
77
const elm = patch(null, vnode)

test/unit/modules/vdom/modules/style.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { patch } from 'web/runtime/patch'
22
import VNode from 'core/vdom/vnode'
33

4-
describe('style module', () => {
4+
describe('vdom style module', () => {
55
it('should create an element with style', () => {
66
const vnode = new VNode('p', { style: { fontSize: '12px' }})
77
const elm = patch(null, vnode)

0 commit comments

Comments
 (0)