Skip to content

Commit

Permalink
make prop watchers sync (fix vuejs#1162)
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Aug 15, 2015
1 parent 1934633 commit 794214a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/directives/prop.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = {
if (_.assertProp(prop, val)) {
child[childKey] = val
}
}
}, { sync: true }
)

// set the child initial value.
Expand All @@ -47,7 +47,7 @@ module.exports = {
childKey,
function (val) {
parent.$set(parentKey, val)
}
}, { sync: true }
)
})
}
Expand Down
4 changes: 3 additions & 1 deletion src/watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var uid = 0
* - {Boolean} twoWay
* - {Boolean} deep
* - {Boolean} user
* - {Boolean} sync
* - {Boolean} lazy
* - {Function} [preProcess]
* @constructor
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion test/unit/specs/directives/prop_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})
Expand Down
18 changes: 7 additions & 11 deletions test/unit/specs/instance/scope_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 () {
Expand Down

0 comments on commit 794214a

Please sign in to comment.