Skip to content

Commit

Permalink
fix dependency collection for multi-nested arrays (fix vuejs#3883)
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Oct 11, 2016
1 parent 3446d14 commit 86f0d11
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/core/observer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,7 @@ export function defineReactive (
childOb.dep.depend()
}
if (Array.isArray(value)) {
for (let e, i = 0, l = value.length; i < l; i++) {
e = value[i]
e && e.__ob__ && e.__ob__.dep.depend()
}
dependArray(value)
}
}
return value
Expand Down Expand Up @@ -234,3 +231,17 @@ export function del (obj: Object, key: string) {
}
ob.dep.notify()
}

/**
* Collect dependencies on array elements when the array is touched, since
* we cannot intercept array element access like property getters.
*/
function dependArray (value: Array<any>) {
for (let e, i = 0, l = value.length; i < l; i++) {
e = value[i]
e && e.__ob__ && e.__ob__.dep.depend()
if (Array.isArray(e)) {
dependArray(e)
}
}
}

0 comments on commit 86f0d11

Please sign in to comment.