Skip to content

Commit 60ef8c1

Browse files
authored
Merge pull request #1362 from sexdevil/fix/1305
Fix/1305
2 parents ca37c62 + 7ed7518 commit 60ef8c1

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/core/observer/index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,14 @@ export function defineReactive (
185185
childOb = !shallow && observe(newVal, undefined, key)
186186
dep.notify()
187187

188-
const ob = obj.__ob__
189-
if (!ob.__keyPath) {
190-
def(ob, '__keyPath', {}, false)
188+
if (!obj.__keyPath) {
189+
def(obj, '__keyPath', {}, false)
190+
}
191+
obj.__keyPath[key] = true
192+
if (newVal instanceof Object && !(newVal instanceof Array)) {
193+
// 标记是否是通过this.Obj = {} 赋值印发的改动,解决少更新问题#1305
194+
def(newVal, '__newReference', true, false)
191195
}
192-
ob.__keyPath[key] = true
193196
}
194197
})
195198
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function minifyDeepData (rootKey, originKey, vmData, data, _mpValueSet, vm) {
4949
} else {
5050
// Object
5151
let __keyPathOnThis = {} // 存储这层对象的keyPath
52-
if (vmData.__keyPath) {
52+
if (vmData.__keyPath && !vmData.__newReference) {
5353
// 有更新列表 ,按照更新列表更新
5454
__keyPathOnThis = vmData.__keyPath
5555
Object.keys(vmData).forEach((_key) => {
@@ -77,6 +77,8 @@ function minifyDeepData (rootKey, originKey, vmData, data, _mpValueSet, vm) {
7777
// 没有更新列表
7878
compareAndSetDeepData(rootKey + '.' + originKey, vmData, vm, data)
7979
}
80+
// 标记是否是通过this.Obj = {} 赋值印发的改动,解决少更新问题#1305
81+
vmData.__newReference = false
8082
}
8183
} catch (e) {
8284
console.log(e, rootKey, originKey, vmData, data)
@@ -108,7 +110,7 @@ export function diffData (vm, data) {
108110
// console.log(rootKey)
109111

110112
// 值类型变量不考虑优化,还是直接更新
111-
const __keyPathOnThis = getDeepData(['__ob__', '__keyPath'], vmData) || getDeepData(['__ob__', '__keyPath'], vm) || {}
113+
const __keyPathOnThis = vmData.__keyPath || vm.__keyPath || {}
112114
delete vm.__keyPath
113115
delete vmData.__keyPath
114116
delete vmProps.__keyPath

0 commit comments

Comments
 (0)