Browse Source

fix dependency collection for multi-nested arrays (fix #3883)

dev
Evan You 8 years ago
parent
commit
86f0d114ec
  1. 19
      src/core/observer/index.js

19
src/core/observer/index.js

@ -155,10 +155,7 @@ export function defineReactive (
childOb.dep.depend() childOb.dep.depend()
} }
if (Array.isArray(value)) { if (Array.isArray(value)) {
for (let e, i = 0, l = value.length; i < l; i++) { dependArray(value)
e = value[i]
e && e.__ob__ && e.__ob__.dep.depend()
}
} }
} }
return value return value
@ -234,3 +231,17 @@ export function del (obj: Object, key: string) {
} }
ob.dep.notify() 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)
}
}
}

Loading…
Cancel
Save