Skip to content

Commit

Permalink
fire watcher on object when properties are added/deleted in non-deep …
Browse files Browse the repository at this point in the history
…mode (close vuejs#2036)
  • Loading branch information
yyx990803 committed Dec 17, 2015
1 parent aec06da commit e1d6b3e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,11 @@ Watcher.prototype.run = function () {
var value = this.get()
if (
value !== this.value ||
// Deep watchers and Array watchers should fire even
// Deep watchers and watchers on Object/Arrays should fire even
// when the value is the same, because the value may
// have mutated; but only do so if this is a
// non-shallow update (caused by a vm digest).
((isArray(value) || this.deep) && !this.shallow)
((isObject(value) || this.deep) && !this.shallow)
) {
// set new value
var oldValue = this.value
Expand Down
14 changes: 14 additions & 0 deletions test/unit/specs/watcher_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,20 @@ describe('Watcher', function () {
})
})

it('fire change for prop addition/deletion in non-deep mode', function (done) {
new Watcher(vm, 'b', spy)
Vue.set(vm.b, 'e', 123)
nextTick(function () {
expect(spy).toHaveBeenCalledWith(vm.b, vm.b)
expect(spy.calls.count()).toBe(1)
Vue.delete(vm.b, 'e')
nextTick(function () {
expect(spy.calls.count()).toBe(2)
done()
})
})
})

it('watch function', function (done) {
var watcher = new Watcher(vm, function () {
return this.a + this.b.d
Expand Down

0 comments on commit e1d6b3e

Please sign in to comment.