Skip to content

Commit 4cd4daf

Browse files
committed
add config.async option
1 parent 0c42a68 commit 4cd4daf

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

src/config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ module.exports = {
4242

4343
interpolate: true,
4444

45+
/**
46+
* Whether to use async rendering.
47+
*/
48+
49+
async: true,
50+
4551
/**
4652
* Internal flag to indicate the delimiters have been
4753
* changed.

src/watcher.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var _ = require('./util')
2+
var config = require('./config')
23
var Observer = require('./observer')
34
var expParser = require('./parse/expression')
45
var Batcher = require('./batcher')
@@ -126,7 +127,11 @@ p.afterGet = function () {
126127
*/
127128

128129
p.update = function () {
129-
batcher.push(this)
130+
if (config.async) {
131+
batcher.push(this)
132+
} else {
133+
this.run()
134+
}
130135
}
131136

132137
/**

test/unit/specs/watcher_spec.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,4 +348,15 @@ describe('Watcher', function () {
348348
})
349349
})
350350

351+
it('synchronous updates', function () {
352+
config.async = false
353+
var watcher = new Watcher(vm, 'a', spy)
354+
vm.a = 2
355+
vm.a = 3
356+
expect(spy.calls.count()).toBe(2)
357+
expect(spy).toHaveBeenCalledWith(2, 1)
358+
expect(spy).toHaveBeenCalledWith(3, 2)
359+
config.async = true
360+
})
361+
351362
})

0 commit comments

Comments
 (0)