10000 fix :class binding array syntax cleanup (fix #1458) · Aphasia-GitHub/vue@d7d73db · GitHub
[go: up one dir, main page]

Skip to content

Commit d7d73db

Browse files
committed
fix :class binding array syntax cleanup (fix vuejs#1458)
1 parent 91d6eeb commit d7d73db

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/directives/class.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ module.exports = {
5757
addClass(this.el, value[i])
5858
}
5959
}
60-
this.prevKeys = value
60+
this.prevKeys = value.slice()
6161
},
6262

6363
cleanup: function (value) {
6464
if (this.prevKeys) {
6565
var i = this.prevKeys.length
6666
while (i--) {
6767
var key = this.prevKeys[i]
68-
if (!value || !contains(value, key)) {
68+
if (key && (!value || !contains(value, key))) {
6969
removeClass(this.el, key)
7070
}
7171
}

test/unit/specs/directives/class_spec.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,14 @@ if (_.inBrowser) {
5959
expect(el.className).toBe('a c d')
6060
dir.update()
6161
expect(el.className).toBe('a')
62-
dir.update(['e', ''])
62+
// test mutating array
63+
var arr = ['e', '']
64+
dir.update(arr)
6365
expect(el.className).toBe('a e')
66+
arr.length = 0
67+
arr.push('f')
68+
dir.update(arr)
69+
expect(el.className).toBe('a f')
6470
})
6571

6672
})

0 commit comments

Comments
 (0)
0