8000 fire watcher on object when properties are added/deleted in non-deep … · htylab/vue@e1d6b3e · GitHub
[go: up one dir, main page]

Skip to content

Commit e1d6b3e

Browse files
committed
fire watcher on object when properties are added/deleted in non-deep mode (close vuejs#2036)
1 parent aec06da commit e1d6b3e

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/watcher.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,11 @@ Watcher.prototype.run = function () {
233233
var value = this.get()
234234
if (
235235
value !== this.value ||
236-
// Deep watchers and Array watchers should fire even
236+
// Deep watchers and watchers on Object/Arrays should fire even
237237
// when the value is the same, because the value may
238238
// have mutated; but only do so if this is a
239239
// non-shallow update (caused by a vm digest).
240-
((isArray(value) || this.deep) && !this.shallow)
240+
((isObject(value) || this.deep) && !this.shallow)
241241
) {
242242
// set new value
243243
var oldValue = this.value

test/unit/specs/watcher_spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,20 @@ describe('Watcher', function () {
289289
})
290290
})
291291

292+
it('fire change for prop addition/deletion in non-deep mode', function (done) {
293+
new Watcher(vm, 'b', spy)
294+
Vue.set(vm.b, 'e', 123)
295+
nextTick(function () {
296+
expect(spy).toHaveBeenCalledWith(vm.b, vm.b)
297+
expect(spy.calls.count()).toBe(1)
298+
Vue.delete(vm.b, 'e')
299+
nextTick(function () {
300+
expect(spy.calls.count()).toBe(2)
301+
done()
302+
})
303+
})
304+
})
305+
292306
it('watch function', function (done) {
293307
var watcher = new Watcher(vm, function () {
294308
return this.a + this.b.d

0 commit comments

Comments
 (0)
0