Evan You 10 лет назад
Родитель
Сommit
794214a3ff

+ 2 - 2
src/directives/prop.js

@@ -25,7 +25,7 @@ module.exports = {
         if (_.assertProp(prop, val)) {
           child[childKey] = val
         }
-      }
+      }, { sync: true }
     )
 
     // set the child initial value.
@@ -47,7 +47,7 @@ module.exports = {
           childKey,
           function (val) {
             parent.$set(parentKey, val)
-          }
+          }, { sync: true }
         )
       })
     }

+ 3 - 1
src/watcher.js

@@ -18,6 +18,7 @@ var uid = 0
  *                 - {Boolean} twoWay
  *                 - {Boolean} deep
  *                 - {Boolean} user
+ *                 - {Boolean} sync
  *                 - {Boolean} lazy
  *                 - {Function} [preProcess]
  * @constructor
@@ -35,6 +36,7 @@ function Watcher (vm, expOrFn, cb, options) {
   this.deep = !!options.deep
   this.user = !!options.user
   this.twoWay = !!options.twoWay
+  this.sync = !!options.sync
   this.lazy = !!options.lazy
   this.dirty = this.lazy
   this.filters = options.filters
@@ -183,7 +185,7 @@ p.afterGet = function () {
 p.update = function (shallow) {
   if (this.lazy) {
     this.dirty = true
-  } else if (!config.async) {
+  } else if (this.sync || !config.async) {
     this.run()
   } else {
     // if queued, only overwrite shallow with non-shallow,

+ 1 - 1
test/unit/specs/directives/prop_spec.js

@@ -29,9 +29,9 @@ if (_.inBrowser) {
       _.nextTick(function () {
         expect(el.innerHTML).toBe('<test>BB</test>')
         vm.$.child.b = 'BBB'
+        expect(vm.b).toBe('BB')
         _.nextTick(function () {
           expect(el.innerHTML).toBe('<test>BBB</test>')
-          expect(vm.b).toBe('BB')
           done()
         })
       })

+ 7 - 11
test/unit/specs/instance/scope_spec.js

@@ -101,7 +101,7 @@ describe('Instance Scope', function () {
       expect(vm.hasOwnProperty('a')).toBe(false)
     })
 
-    it('replace $data and handle props', function (done) {
+    it('replace $data and handle props', function () {
       var el = document.createElement('div')
       var vm = new Vue({
         el: el,
@@ -144,17 +144,13 @@ describe('Instance Scope', function () {
       expect(child.b).toBe(3)
       expect(child.c).toBe(4)
       // assert parent state
-      Vue.nextTick(function () {
-        // one-way
-        expect(vm.a).toBe(1)
-        // one-time
-        expect(vm.b).toBe(2)
-        // two-way
-        expect(vm.c).toBe(4)
-        done()
-      })
+      // one-way
+      expect(vm.a).toBe(1)
+      // one-time
+      expect(vm.b).toBe(2)
+      // two-way
+      expect(vm.c).toBe(4)
     })
-
   })
 
   describe('computed', function () {