Skip to content

Commit ee5f458

Browse files
committed
a more proper fix for #1683
1 parent 7df204e commit ee5f458

File tree

4 files changed

+14
-18
lines changed

4 files changed

+14
-18
lines changed

src/directives/internal/prop.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ module.exports = {
3131
filters: prop.filters,
3232
// important: props need to be observed on the
3333
// v-for scope if present
34-
scope: this._scope,
35-
// only fire callback when reference has changed
36-
refOnly: true
34+
scope: this._scope
3735
}
3836
)
3937

@@ -52,7 +50,10 @@ module.exports = {
5250
function (val) {
5351
parentWatcher.set(val)
5452
}, {
55-
refOnly: true
53+
// ensure sync upward before parent sync down.
54+
// this is necessary in cases e.g. the child
55+
// mutates a prop array, then replaces it. (#1683)
56+
sync: true
5657
}
5758
)
5859
})

src/observer/index.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,13 @@ function defineReactive (obj, key, val) {
179179
get: function metaGetter () {
180180
if (Dep.target) {
181181
dep.depend()
182-
if (!Dep.refOnly) {
183-
if (childOb) {
184-
childOb.dep.depend()
185-
}
186-
if (_.isArray(val)) {
187-
for (var e, i = 0, l = val.length; i < l; i++) {
188-
e = val[i]
189-
e && e.__ob__ && e.__ob__.dep.depend()
190-
}
182+
if (childOb) {
183+
childOb.dep.depend()
184+
}
185+
if (_.isArray(val)) {
186+
for (var e, i = 0, l = val.length; i < l; i++) {
187+
e = val[i]
188+
e && e.__ob__ && e.__ob__.dep.depend()
191189
}
192190
}
193191
}

src/watcher.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ var uid = 0
2020
* - {Boolean} user
2121
* - {Boolean} sync
2222
* - {Boolean} lazy
23-
* - {Boolean} refOnly
2423
* - {Function} [preProcess]
2524
* - {Function} [postProcess]
2625
* @constructor
@@ -180,7 +179,6 @@ Watcher.prototype.set = function (value) {
180179

181180
Watcher.prototype.beforeGet = function () {
182181
Dep.target = this
183-
Dep.refOnly = !!this.refOnly
184182
this.newDeps = Object.create(null)
185183
}
186184

@@ -190,7 +188,6 @@ Watcher.prototype.beforeGet = function () {
190188

191189
Watcher.prototype.afterGet = function () {
192190
Dep.target = null
193-
Dep.refOnly = false
194191
var ids = Object.keys(this.deps)
195192
var i = ids.length
196193
while (i--) {

test/unit/specs/directives/internal/prop_spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ if (_.inBrowser) {
552552
})
553553

554554
// #1683
555-
it('should only trigger sync on reference change', function (done) {
555+
it('should properly sync back up when mutating then replace', function (done) {
556556
var vm = new Vue({
557557
el: el,
558558
data: {
@@ -566,7 +566,7 @@ if (_.inBrowser) {
566566
}
567567
})
568568
var child = vm.$children[0]
569-
child.items.push(3) // this should not trigger parent to sync it down
569+
child.items.push(3)
570570
var newArray = child.items = [4]
571571
_.nextTick(function () {
572572
expect(child.items).toBe(newArray)

0 commit comments

Comments
 (0)