Skip to content

Commit c4ec2fe

Browse files
authored
Merge branch 'master' into feature/ttalipay
2 parents 7e8ea3f + e43361a commit c4ec2fe

File tree

5 files changed

+59
-28
lines changed

5 files changed

+59
-28
lines changed

packages/mpvue-template-compiler/build.js

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2894,8 +2894,6 @@ function observe (value, asRootData, key) {
28942894
!value._isVue
28952895
) {
28962896
ob = new Observer(value, key);
2897-
ob.__keyPath = ob.__keyPath ? ob.__keyPath : {};
2898-
ob.__keyPath[key] = true;
28992897
}
29002898
if (asRootData && ob) {
29012899
ob.vmCount++;
@@ -2959,8 +2957,15 @@ function defineReactive$$1 (
29592957
}
29602958
childOb = !shallow && observe(newVal, undefined, key);
29612959
dep.notify();
2962-
obj.__keyPath = obj.__keyPath ? obj.__keyPath : {};
2960+
2961+
if (!obj.__keyPath) {
2962+
def(obj, '__keyPath', {}, false);
2963+
}
29632964
obj.__keyPath[key] = true;
2965+
if (newVal instanceof Object && !(newVal instanceof Array)) {
2966+
// 标记是否是通过this.Obj = {} 赋值印发的改动,解决少更新问题#1305
2967+
def(newVal, '__newReference', true, false);
2968+
}
29642969
}
29652970
});
29662971
}
@@ -2995,7 +3000,7 @@ function set (target, key, val) {
29953000
defineReactive$$1(ob.value, key, val);
29963001
// Vue.set 添加对象属性,渲染时候把 val 传给小程序渲染
29973002
if (!target.__keyPath) {
2998-
target.__keyPath = {};
3003+
def(target, '__keyPath', {}, false);
29993004
}
30003005
target.__keyPath[key] = true;
30013006
ob.dep.notify();
@@ -5981,9 +5986,25 @@ var attrs$3 = {
59815986
attrs['wx:key'] = val;
59825987
}
59835988

5984-
if (tag === 'template') {
5985-
return attrs
5986-
}
5989+
node.tag = 'template';
5990+
node.attrsMap.name = slotId;
5991+
delete node.attrsMap.slot;
5992+
// 缓存,会集中生成一个 slots 文件
5993+
slots[slotId] = { node: convertAst$1(node, options, util), name: slotName, slotId: slotId };
5994+
wxmlAst.slots[slotName] = slotId;
5995+
});
5996+
// 清理当前组件下的节点信息,因为 slot 都被转移了
5997+
children.length = 0;
5998+
wxmlAst.children.length = 0;
5999+
}
6000+
6001+
wxmlAst.attrsMap = attrs$1.format(wxmlAst.attrsMap);
6002+
wxmlAst = tag$1(wxmlAst, options);
6003+
wxmlAst = convertFor$1(wxmlAst, options);
6004+
wxmlAst = attrs$1.convertAttr(wxmlAst, log);
6005+
if (children && !isSlot) {
6006+
wxmlAst.children = children.map(function (k) { return convertAst$1(k, options, util); });
6007+
}
59876008

59886009
if (name === 'href') {
59896010
attrs['url'] = "{{" + val + "}}";
@@ -6125,11 +6146,9 @@ var convertFor$3 = function (ast) {
61256146
attrsMap[astMap$3['alias']] = alias;
61266147
}
61276148

6128-
delete attrsMap['v-for'];
6129-
}
6130-
6131-
return ast
6132-
};
6149+
// 引用子模版
6150+
var importCode = Object.keys(deps).map(function (k) { return components[k] ? ("<import src=\"" + (components[k].src) + "\" />") : ''; }).join('');
6151+
code = importCode + "<template name=\"" + (options.name) + "\">" + code + "</template>";
61336152

61346153
function mpmlAst$3 (compiled, options, log) {
61356154
if ( options === void 0 ) options = {};

packages/mpvue-template-compiler/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "mpvue-template-compiler",
33
"version": "2.0.0",
4+
"version": "1.0.20",
45
"description": "mpvue template compiler for Vue",
56
"main": "index.js",
67
"repository": {

packages/mpvue/index.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -861,8 +861,6 @@ function observe (value, asRootData, key) {
861861
!value._isVue
862862
) {
863863
ob = new Observer(value, key);
864-
ob.__keyPath = ob.__keyPath ? ob.__keyPath : {};
865-
ob.__keyPath[key] = true;
866864
}
867865
if (asRootData && ob) {
868866
ob.vmCount++;
@@ -926,8 +924,15 @@ function defineReactive$$1 (
926924
}
927925
childOb = !shallow && observe(newVal, undefined, key);
928926
dep.notify();
929-
obj.__keyPath = obj.__keyPath ? obj.__keyPath : {};
927+
928+
if (!obj.__keyPath) {
929+
def(obj, '__keyPath', {}, false);
930+
}
930931
obj.__keyPath[key] = true;
932+
if (newVal instanceof Object && !(newVal instanceof Array)) {
933+
// 标记是否是通过this.Obj = {} 赋值印发的改动,解决少更新问题#1305
934+
def(newVal, '__newReference', true, false);
935+
}
931936
}
932937
});
933938
}
@@ -962,7 +967,7 @@ function set (target, key, val) {
962967
defineReactive$$1(ob.value, key, val);
963968
// Vue.set 添加对象属性,渲染时候把 val 传给小程序渲染
964969
if (!target.__keyPath) {
965-
target.__keyPath = {};
970+
def(target, '__keyPath', {}, false);
966971
}
967972
target.__keyPath[key] = true;
968973
ob.dep.notify();
@@ -993,7 +998,7 @@ function del (target, key) {
993998
return
994999
}
9951000
if (!target.__keyPath) {
996-
target.__keyPath = {};
1001+
def(target, '__keyPath', {}, false);
9971002
}
9981003
// Vue.del 删除对象属性,渲染时候把这个属性设置为 undefined
9991004
target.__keyPath[key] = 'del';
@@ -4180,7 +4185,7 @@ Object.defineProperty(Vue$3.prototype, '$ssrContext', {
41804185
});
41814186

41824187
Vue$3.version = '2.4.1';
4183-
Vue$3.mpvueVersion = '1.1.1';
4188+
Vue$3.mpvueVersion = '1.0.20';
41844189

41854190
/* globals renderer */
41864191

@@ -5396,7 +5401,7 @@ function minifyDeepData (rootKey, originKey, vmData, data, _mpValueSet, vm) {
53965401
} else {
53975402
// Object
53985403
var _keyPathOnThis = {}; // 存储这层对象的keyPath
5399-
if (vmData.__keyPath) {
5404+
if (vmData.__keyPath && !vmData.__newReference) {
54005405
// 有更新列表 ,按照更新列表更新
54015406
_keyPathOnThis = vmData.__keyPath;
54025407
Object.keys(vmData).forEach(function (_key) {
@@ -5424,6 +5429,8 @@ function minifyDeepData (rootKey, originKey, vmData, data, _mpValueSet, vm) {
54245429
// 没有更新列表
54255430
compareAndSetDeepData(rootKey + '.' + originKey, vmData, vm, data);
54265431
}
5432+
// 标记是否是通过this.Obj = {} 赋值印发的改动,解决少更新问题#1305
5433+
vmData.__newReference = false;
54275434
}
54285435
} catch (e) {
54295436
console.log(e, rootKey, originKey, vmData, data);
@@ -5477,7 +5484,6 @@ function diffData (vm, data) {
54775484
Object.keys(vmProps).forEach(function (vmPropsItemKey) {
54785485
if (vmProps[vmPropsItemKey] instanceof Object) {
54795486
// 引用类型
5480-
if (vmPropsItemKey === '__keyPath') { return }
54815487
minifyDeepData(rootKey, vmPropsItemKey, vmProps[vmPropsItemKey], data, vm._mpValueSet, vm);
54825488
} else if (vmProps[vmPropsItemKey] !== undefined) {
54835489
data[rootKey + '.' + vmPropsItemKey] = vmProps[vmPropsItemKey];

src/core/observer/index.js

Lines changed: 10 additions & 5 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,15 @@ export function defineReactive (
186184
}
187185
childOb = !shallow && observe(newVal, undefined, key)
188186
dep.notify()
189-
obj.__keyPath = obj.__keyPath ? obj.__keyPath : {}
187+
188+
if (!obj.__keyPath) {
189+
def(obj, '__keyPath', {}, false)
190+
}
190191
obj.__keyPath[key] = true
192+
if (newVal instanceof Object && !(newVal instanceof Array)) {
193+
// 标记是否是通过this.Obj = {} 赋值印发的改动,解决少更新问题#1305
194+
def(newVal, '__newReference', true, false)
195+
}
191196
}
192197
})
193198
}
@@ -222,7 +227,7 @@ export function set (target: Array<any> | Object, key: any, val: any): any {
222227
defineReactive(ob.value, key, val)
223228
// Vue.set 添加对象属性,渲染时候把 val 传给小程序渲染
224229
if (!target.__keyPath) {
225-
target.__keyPath = {}
230+
def(target, '__keyPath', {}, false)
226231
}
227232
target.__keyPath[key] = true
228233
ob.dep.notify()
@@ -253,7 +258,7 @@ export function del (target: Array<any> | Object, key: any) {
253258
return
254259
}
255260
if (!target.__keyPath) {
256-
target.__keyPath = {}
261+
def(target, '__keyPath', {}, false)
257262
}
258263
// Vue.del 删除对象属性,渲染时候把这个属性设置为 undefined
259264
target.__keyPath[key] = 'del'

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

Lines changed: 3 additions & 3 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)
@@ -117,7 +119,6 @@ export function diffData (vm, data) {
117119
Object.keys(vmData).forEach((vmDataItemKey) => {
118120
if (vmData[vmDataItemKey] instanceof Object) {
119121
// 引用类型
120-
if (vmDataItemKey === '__keyPath') { return }
121122
minifyDeepData(rootKey, vmDataItemKey, vmData[vmDataItemKey], data, vm._mpValueSet, vm)
122123
} else if (vmData[vmDataItemKey] !== undefined) {
123124
// _data上的值属性只有要更新的时候才赋值
@@ -130,7 +131,6 @@ export function diffData (vm, data) {
130131
Object.keys(vmProps).forEach((vmPropsItemKey) => {
131132
if (vmProps[vmPropsItemKey] instanceof Object) {
132133
// 引用类型
133-
if (vmPropsItemKey === '__keyPath') { return }
134134
minifyDeepData(rootKey, vmPropsItemKey, vmProps[vmPropsItemKey], data, vm._mpValueSet, vm)
135135
} else if (vmProps[vmPropsItemKey] !== undefined) {
136136
data[rootKey + '.' + vmPropsItemKey] = vmProps[vmPropsItemKey]

0 commit comments

Comments
 (0)