Skip to content

Commit 11c77ea

Browse files
authored
Merge pull request #1360 from Meituan-Dianping/fix/render
增量更新diff算法bugfix
2 parents 5d49fb9 + 4d3001c commit 11c77ea

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

src/core/observer/index.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,6 @@ export function observe (value: any, asRootData: ?boolean, key: any): Observer |
121121
!value._isVue
122122
) {
123123
ob = new Observer(value, key)
124-
ob.__keyPath = ob.__keyPath ? ob.__keyPath : {}
125-
ob.__keyPath[key] = true
126124
}
127125
if (asRootData && ob) {
128126
ob.vmCount++
@@ -186,8 +184,12 @@ export function defineReactive (
186184
}
187185
childOb = !shallow && observe(newVal, undefined, key)
188186
dep.notify()
189-
obj.__keyPath = obj.__keyPath ? obj.__keyPath : {}
190-
obj.__keyPath[key] = true
187+
188+
const ob = obj.__ob__
189+
if (!ob.__keyPath) {
190+
def(ob, '__keyPath', {}, false)
191+
}
192+
ob.__keyPath[key] = true
191193
}
192194
})
193195
}
@@ -222,7 +224,7 @@ export function set (target: Array<any> | Object, key: any, val: any): any {
222224
defineReactive(ob.value, key, val)
223225
// Vue.set 添加对象属性,渲染时候把 val 传给小程序渲染
224226
if (!target.__keyPath) {
225-
target.__keyPath = {}
227+
def(target, '__keyPath', {}, false)
226228
}
227229
target.__keyPath[key] = true
228230
ob.dep.notify()
@@ -253,7 +255,7 @@ export function del (target: Array<any> | Object, key: any) {
253255
return
254256
}
255257
if (!target.__keyPath) {
256-
target.__keyPath = {}
258+
def(target, '__keyPath', {}, false)
257259
}
258260
// Vue.del 删除对象属性,渲染时候把这个属性设置为 undefined
259261
target.__keyPath[key] = 'del'

src/platforms/mp/runtime/diff-data.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export function diffData (vm, data) {
108108
// console.log(rootKey)
109109

110110
// 值类型变量不考虑优化,还是直接更新
111-
const __keyPathOnThis = vmData.__keyPath || vm.__keyPath || {}
111+
const __keyPathOnThis = getDeepData(['__ob__', '__keyPath'], vmData) || getDeepData(['__ob__', '__keyPath'], vm) || {}
112112
delete vm.__keyPath
113113
delete vmData.__keyPath
114114
delete vmProps.__keyPath
@@ -117,7 +117,6 @@ export function diffData (vm, data) {
117117
Object.keys(vmData).forEach((vmDataItemKey) => {
118118
if (vmData[vmDataItemKey] instanceof Object) {
119119
// 引用类型
120-
if (vmDataItemKey === '__keyPath') { return }
121120
minifyDeepData(rootKey, vmDataItemKey, vmData[vmDataItemKey], data, vm._mpValueSet, vm)
122121
} else if (vmData[vmDataItemKey] !== undefined) {
123122
// _data上的值属性只有要更新的时候才赋值
@@ -130,7 +129,6 @@ export function diffData (vm, data) {
130129
Object.keys(vmProps).forEach((vmPropsItemKey) => {
131130
if (vmProps[vmPropsItemKey] instanceof Object) {
132131
// 引用类型
133-
if (vmPropsItemKey === '__keyPath') { return }
134132
minifyDeepData(rootKey, vmPropsItemKey, vmProps[vmPropsItemKey], data, vm._mpValueSet, vm)
135133
} else if (vmProps[vmPropsItemKey] !== undefined) {
136134
data[rootKey + '.' + vmPropsItemKey] = vmProps[vmPropsItemKey]

src/platforms/mp/runtime/events.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,14 @@ function getWebEventByMP (e) {
8181
return event
8282
}
8383

84+
85+
const KEY_SEP = '_'
8486
export function handleProxyWithVue (e) {
8587
const rootVueVM = this.$root
8688
const { type, target = {}, currentTarget } = e
8789
const { dataset = {} } = currentTarget || target
8890
const { comkey = '', eventid } = dataset
89-
const vm = getVM(rootVueVM, comkey.split(','))
91+
const vm = getVM(rootVueVM, comkey.split(KEY_SEP))
9092

9193
if (!vm) {
9294
return

0 commit comments

Comments
 (0)