Bladeren bron

support sync watcher as internal flag

Evan You 10 jaren geleden
bovenliggende
commit
634a0734c4
2 gewijzigde bestanden met toevoegingen van 7 en 1 verwijderingen
  1. 2 1
      build/karma.cover.config.js
  2. 5 0
      src/core/observer/watcher.js

+ 2 - 1
build/karma.cover.config.js

@@ -19,7 +19,8 @@ module.exports = function (config) {
       ignore: [
         'test/',
         'src/compiler/parser/html-parser.js',
-        'src/core/instance/proxy.js'
+        'src/core/instance/proxy.js',
+        'src/sfc/deindent.js'
       ]
     }]]
   }

+ 5 - 0
src/core/observer/watcher.js

@@ -27,6 +27,7 @@ export default class Watcher {
   deep: boolean;
   user: boolean;
   lazy: boolean;
+  sync: boolean;
   dirty: boolean;
   active: boolean;
   deps: Array<Dep>;
@@ -48,6 +49,7 @@ export default class Watcher {
     this.deep = !!options.deep
     this.user = !!options.user
     this.lazy = !!options.lazy
+    this.sync = !!options.sync
     this.expression = expOrFn.toString()
     this.cb = cb
     this.id = ++uid // uid for batching
@@ -167,8 +169,11 @@ export default class Watcher {
    * Will be called when a dependency changes.
    */
   update () {
+    /* istanbul ignore else */
     if (this.lazy) {
       this.dirty = true
+    } else if (this.sync) {
+      this.run()
     } else {
       queueWatcher(this)
     }