Kaynağa Gözat

add config.async option

Evan You 11 yıl önce
ebeveyn
işleme
4cd4daf274
3 değiştirilmiş dosya ile 23 ekleme ve 1 silme
  1. 6 0
      src/config.js
  2. 6 1
      src/watcher.js
  3. 11 0
      test/unit/specs/watcher_spec.js

+ 6 - 0
src/config.js

@@ -42,6 +42,12 @@ module.exports = {
 
   interpolate: true,
 
+  /**
+   * Whether to use async rendering.
+   */
+
+  async: true,
+
   /**
    * Internal flag to indicate the delimiters have been
    * changed.

+ 6 - 1
src/watcher.js

@@ -1,4 +1,5 @@
 var _ = require('./util')
+var config = require('./config')
 var Observer = require('./observer')
 var expParser = require('./parse/expression')
 var Batcher = require('./batcher')
@@ -126,7 +127,11 @@ p.afterGet = function () {
  */
 
 p.update = function () {
-  batcher.push(this)
+  if (config.async) {
+    batcher.push(this)
+  } else {
+    this.run()
+  }
 }
 
 /**

+ 11 - 0
test/unit/specs/watcher_spec.js

@@ -348,4 +348,15 @@ describe('Watcher', function () {
     })
   })
 
+  it('synchronous updates', function () {
+    config.async = false
+    var watcher = new Watcher(vm, 'a', spy)
+    vm.a = 2
+    vm.a = 3
+    expect(spy.calls.count()).toBe(2)
+    expect(spy).toHaveBeenCalledWith(2, 1)
+    expect(spy).toHaveBeenCalledWith(3, 2)
+    config.async = true
+  })
+
 })