Skip to content

Commit 329987c

Browse files
committed
fix :class binding array syntax cleanup (fix #1458)
1 parent d2633e7 commit 329987c

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/directives/internal/class.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ module.exports = {
3636
addClass(this.el, value[i])
3737
}
3838
}
39-
this.prevKeys = value
39+
this.prevKeys = value.slice()
4040
},
4141

4242
cleanup: function (value) {
4343
if (this.prevKeys) {
4444
var i = this.prevKeys.length
4545
while (i--) {
4646
var key = this.prevKeys[i]
47-
if (!value || !contains(value, key)) {
47+
if (key && (!value || !contains(value, key))) {
4848
removeClass(this.el, key)
4949
}
5050
}

test/unit/specs/directives/internal/class_spec.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,14 @@ if (_.inBrowser) {
4747
expect(el.className).toBe('a c d')
4848
dir.update()
4949
expect(el.className).toBe('a')
50-
dir.update(['e', ''])
50+
// test mutating array
51+
var arr = ['e', '']
52+
dir.update(arr)
5153
expect(el.className).toBe('a e')
54+
arr.length = 0
55+
arr.push('f')
56+
dir.update(arr)
57+
expect(el.className).toBe('a f')
5258
})
5359

5460
})

0 commit comments

Comments
 (0)