use nextTick with context in batcher

This commit is contained in:
Evan You 2014-08-09 18:57:46 -04:00
parent fd14d5edc7
commit 043eb6e14c
2 changed files with 6 additions and 4 deletions

View File

@ -30,10 +30,7 @@ p.push = function (job) {
this.has[job.id] = job
if (!this.waiting) {
this.waiting = true
var self = this
_.nextTick(function () {
self.flush()
})
_.nextTick(this.flush, this)
}
} else if (job.override) {
var oldJob = this.has[job.id]

View File

@ -109,11 +109,16 @@ describe('Watcher', function () {
it('non-existent path, $add later', function (done) {
var watcher = new Watcher(vm, 'd.e', spy)
var watcher2 = new Watcher(vm, 'b.e', spy)
expect(watcher.value).toBeUndefined()
expect(watcher2.value).toBeUndefined()
vm.$scope.$add('d', { e: 123 })
vm.b.$add('e', 234)
nextTick(function () {
expect(watcher.value).toBe(123)
expect(watcher2.value).toBe(234)
expect(spy).toHaveBeenCalledWith(123, undefined)
expect(spy).toHaveBeenCalledWith(234, undefined)
done()
})
})