Skip to content

Commit ca37c62

Browse files
committed
npm publish 1.0.19 by tag @Alpha
1 parent 11c77ea commit ca37c62

File tree

4 files changed

+65
-48
lines changed

4 files changed

+65
-48
lines changed

packages/mpvue-template-compiler/build.js

Lines changed: 18 additions & 17 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++;
@@ -2920,8 +2918,6 @@ function defineReactive$$1 (
29202918
return
29212919
}
29222920

2923-
// TODO: 先试验标记一下 keyPath
2924-
29252921
// cater for pre-defined getter/setters
29262922
var getter = property && property.get;
29272923
var setter = property && property.set;
@@ -2961,8 +2957,12 @@ function defineReactive$$1 (
29612957
}
29622958
childOb = !shallow && observe(newVal, undefined, key);
29632959
dep.notify();
2964-
obj.__keyPath = obj.__keyPath ? obj.__keyPath : {};
2965-
obj.__keyPath[key] = true;
2960+
2961+
var ob = obj.__ob__;
2962+
if (!ob.__keyPath) {
2963+
def(ob, '__keyPath', {}, false);
2964+
}
2965+
ob.__keyPath[key] = true;
29662966
}
29672967
});
29682968
}
@@ -2995,8 +2995,10 @@ function set (target, key, val) {
29952995
return val
29962996
}
29972997
defineReactive$$1(ob.value, key, val);
2998-
// Vue.set 添加对象属性,渲染时候把val传给小程序渲染
2999-
target.__keyPath = target.__keyPath ? target.__keyPath : {};
2998+
// Vue.set 添加对象属性,渲染时候把 val 传给小程序渲染
2999+
if (!target.__keyPath) {
3000+
def(target, '__keyPath', {}, false);
3001+
}
30003002
target.__keyPath[key] = true;
30013003
ob.dep.notify();
30023004
return val
@@ -4615,7 +4617,7 @@ var component = {
46154617
var mpcomid = ast.mpcomid;
46164618
var slots = ast.slots;
46174619
if (slotName) {
4618-
attrsMap['data'] = "{{...$root[$k], $root}}";
4620+
attrsMap['data'] = "{{...$root[$p], ...$root[$k], $root}}";
46194621
// bindedName is available when rendering slot in v-for
46204622
var bindedName = attrsMap['v-bind:name'];
46214623
if(bindedName) {
@@ -5290,7 +5292,7 @@ function getSlotsName$1 (obj) {
52905292
.join(',')
52915293
}
52925294

5293-
function tmplateSlotsObj$1(obj) {
5295+
function tmplateSlotsObj$1 (obj) {
52945296
if (!obj) {
52955297
return []
52965298
}
@@ -5313,13 +5315,13 @@ var component$1 = {
53135315
var mpcomid = ast.mpcomid;
53145316
var slots = ast.slots;
53155317
if (slotName) {
5316-
attrsMap['data'] = "{{{...$root[$k], $root}}}";
5318+
attrsMap['data'] = '{{{...$root[$k], $root}}}';
53175319
// bindedName is available when rendering slot in v-for
53185320
var bindedName = attrsMap['v-bind:name'];
5319-
if(bindedName) {
5320-
attrsMap['is'] = "{{$for[" + bindedName + "]}}";
5321+
if (bindedName) {
5322+
attrsMap['is'] = '{{$for[' + bindedName + ']}}';
53215323
} else {
5322-
attrsMap['is'] = "{{" + slotName + "}}";
5324+
attrsMap['is'] = '{{' + slotName + '}}';
53235325
}
53245326
} else {
53255327
var slotsName = getSlotsName$1(slots);
@@ -5537,7 +5539,7 @@ var tag$1 = function (ast, options) {
55375539
};
55385540

55395541
var astMap$1 = {
5540-
// 'if': 's-if',
5542+
'if': 's-if',
55415543
'v-for': 's-for',
55425544
'alias': 's-for-item',
55435545
'iterator1': 's-for-index',
@@ -5644,6 +5646,7 @@ function convertAst$1 (node, options, util) {
56445646
children.length = 0;
56455647
wxmlAst.children.length = 0;
56465648
}
5649+
56475650
wxmlAst.attrsMap = attrs$1.format(wxmlAst.attrsMap);
56485651
wxmlAst = tag$1(wxmlAst, options);
56495652
wxmlAst = convertFor$1(wxmlAst, options);
@@ -5758,8 +5761,6 @@ function compileToWxml$2 (compiled, options) {
57585761
var slots = ref.slots; if ( slots === void 0 ) slots = {};
57595762
var code = generate$3(wxast, options);
57605763

5761-
console.log(code);
5762-
57635764
// 引用子模版
57645765
var importCode = Object.keys(deps).map(function (k) { return components[k] ? ("<import src=\"" + (components[k].src) + "\" />") : ''; }).join('');
57655766
code = importCode + "<template name=\"" + (options.name) + "\">" + code + "</template>";

packages/mpvue-template-compiler/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mpvue-template-compiler",
3-
"version": "1.0.13",
3+
"version": "1.0.19",
44
"description": "mpvue template compiler for Vue",
55
"main": "index.js",
66
"repository": {

packages/mpvue/index.js

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ try {
77
global.Page = global.Page || Page;
88
global.Component = global.Component || Component;
99
global.getApp = global.getApp || getApp;
10+
11+
if (typeof wx !== 'undefined') {
12+
global.mpvue = wx;
13+
global.mpvuePlatform = 'wx';
14+
} else if (typeof swan !== 'undefined') {
15+
global.mpvue = swan;
16+
global.mpvuePlatform = 'swan';
17+
}
1018
} catch (e) {}
1119

1220
(function (global, factory) {
@@ -847,8 +855,6 @@ function observe (value, asRootData, key) {
847855
!value._isVue
848856
) {
849857
ob = new Observer(value, key);
850-
ob.__keyPath = ob.__keyPath ? ob.__keyPath : {};
851-
ob.__keyPath[key] = true;
852858
}
853859
if (asRootData && ob) {
854860
ob.vmCount++;
@@ -873,8 +879,6 @@ function defineReactive$$1 (
873879
return
874880
}
875881

876-
// TODO: 先试验标记一下 keyPath
877-
878882
// cater for pre-defined getter/setters
879883
var getter = property && property.get;
880884
var setter = property && property.set;
@@ -914,8 +918,12 @@ function defineReactive$$1 (
914918
}
915919
childOb = !shallow && observe(newVal, undefined, key);
916920
dep.notify();
917-
obj.__keyPath = obj.__keyPath ? obj.__keyPath : {};
918-
obj.__keyPath[key] = true;
921+
922+
var ob = obj.__ob__;
923+
if (!ob.__keyPath) {
924+
def(ob, '__keyPath', {}, false);
925+
}
926+
ob.__keyPath[key] = true;
919927
}
920928
});
921929
}
@@ -948,8 +956,10 @@ function set (target, key, val) {
948956
return val
949957
}
950958
defineReactive$$1(ob.value, key, val);
951-
// Vue.set 添加对象属性,渲染时候把val传给小程序渲染
952-
target.__keyPath = target.__keyPath ? target.__keyPath : {};
959+
// Vue.set 添加对象属性,渲染时候把 val 传给小程序渲染
960+
if (!target.__keyPath) {
961+
def(target, '__keyPath', {}, false);
962+
}
953963
target.__keyPath[key] = true;
954964
ob.dep.notify();
955965
return val
@@ -978,8 +988,10 @@ function del (target, key) {
978988
if (!ob) {
979989
return
980990
}
981-
target.__keyPath = target.__keyPath ? target.__keyPath : {};
982-
// Vue.del 删除对象属性,渲染时候把这个属性设置为undefined
991+
if (!target.__keyPath) {
992+
def(target, '__keyPath', {}, false);
993+
}
994+
// Vue.del 删除对象属性,渲染时候把这个属性设置为 undefined
983995
target.__keyPath[key] = 'del';
984996
ob.dep.notify();
985997
}
@@ -4961,6 +4973,8 @@ function callHook$1 (vm, hook, params) {
49614973
var handlers = vm.$options[hook];
49624974
if (hook === 'onError' && handlers) {
49634975
handlers = [handlers];
4976+
} else if (hook === 'onPageNotFound' && handlers) {
4977+
handlers = [handlers];
49644978
}
49654979

49664980
var ret;
@@ -5176,6 +5190,10 @@ function initMP (mpType, next) {
51765190

51775191
onError: function onError (err) {
51785192
callHook$1(rootVueVM, 'onError', err);
5193+
},
5194+
5195+
onPageNotFound: function onPageNotFound (err) {
5196+
callHook$1(rootVueVM, 'onPageNotFound', err);
51795197
}
51805198
});
51815199
} else if (mpType === 'component') {
@@ -5343,13 +5361,14 @@ function getDeepData (keyList, viewData) {
53435361
}
53445362
}
53455363
}
5346-
function compareAndSetDeepData (key, newData, vm, data) {
5364+
5365+
function compareAndSetDeepData (key, newData, vm, data, forceUpdate) {
53475366
// 比较引用类型数据
53485367
try {
53495368
var keyList = key.split('.');
5350-
//page.__viewData__老版小程序不存在,使用mpvue里绑的data比对
5369+
// page.__viewData__老版小程序不存在,使用mpvue里绑的data比对
53515370
var oldData = getDeepData(keyList, vm.$root.$mp.page.data);
5352-
if (oldData === null || JSON.stringify(oldData) !== JSON.stringify(newData)) {
5371+
if (oldData === null || JSON.stringify(oldData) !== JSON.stringify(newData) || forceUpdate) {
53535372
data[key] = newData;
53545373
}
53555374
} catch (e) {
@@ -5369,7 +5388,7 @@ function minifyDeepData (rootKey, originKey, vmData, data, _mpValueSet, vm) {
53695388
try {
53705389
if (vmData instanceof Array) {
53715390
// 数组
5372-
compareAndSetDeepData(rootKey + '.' + originKey, vmData, vm, data);
5391+
compareAndSetDeepData(rootKey + '.' + originKey, vmData, vm, data, true);
53735392
} else {
53745393
// Object
53755394
var _keyPathOnThis = {}; // 存储这层对象的keyPath
@@ -5431,20 +5450,19 @@ function diffData (vm, data) {
54315450
});
54325451
// console.log(rootKey)
54335452

5434-
// 值类型变量不考虑优化,还是直接更新
5435-
var __keyPathOnThis = vmData.__keyPath || vm.__keyPath || {};
5453+
// 值类型变量不考虑优化,还是直接更新
5454+
var __keyPathOnThis = getDeepData(['__ob__', '__keyPath'], vmData) || getDeepData(['__ob__', '__keyPath'], vm) || {};
54365455
delete vm.__keyPath;
54375456
delete vmData.__keyPath;
54385457
delete vmProps.__keyPath;
54395458
if (vm._mpValueSet === 'done') {
54405459
// 第二次赋值才进行缩减操作
54415460
Object.keys(vmData).forEach(function (vmDataItemKey) {
54425461
if (vmData[vmDataItemKey] instanceof Object) {
5443-
// 引用类型
5444-
if (vmDataItemKey === '__keyPath') { return }
5462+
// 引用类型
54455463
minifyDeepData(rootKey, vmDataItemKey, vmData[vmDataItemKey], data, vm._mpValueSet, vm);
5446-
} else if(vmData[vmDataItemKey] !== undefined){
5447-
// _data上的值属性只有要更新的时候才赋值
5464+
} else if (vmData[vmDataItemKey] !== undefined) {
5465+
// _data上的值属性只有要更新的时候才赋值
54485466
if (__keyPathOnThis[vmDataItemKey] === true) {
54495467
data[rootKey + '.' + vmDataItemKey] = vmData[vmDataItemKey];
54505468
}
@@ -5454,9 +5472,8 @@ function diffData (vm, data) {
54545472
Object.keys(vmProps).forEach(function (vmPropsItemKey) {
54555473
if (vmProps[vmPropsItemKey] instanceof Object) {
54565474
// 引用类型
5457-
if (vmPropsItemKey === '__keyPath') { return }
54585475
minifyDeepData(rootKey, vmPropsItemKey, vmProps[vmPropsItemKey], data, vm._mpValueSet, vm);
5459-
} else if(vmProps[vmPropsItemKey] !== undefined){
5476+
} else if (vmProps[vmPropsItemKey] !== undefined) {
54605477
data[rootKey + '.' + vmPropsItemKey] = vmProps[vmPropsItemKey];
54615478
}
54625479
// _props上的值属性只有要更新的时候才赋值
@@ -5471,14 +5488,14 @@ function diffData (vm, data) {
54715488
Object.keys(vmComputedWatchers).forEach(function (computedItemKey) {
54725489
data[rootKey + '.' + computedItemKey] = vm[computedItemKey];
54735490
});
5474-
// 更新的时候要删除$root.0:{},否则会覆盖原正确数据
5491+
// 更新的时候要删除$root.0:{},否则会覆盖原正确数据
54755492
delete data[rootKey];
54765493
}
54775494
if (vm._mpValueSet === undefined) {
5478-
// 第一次设置数据成功后,标记位置true,再更新到这个节点如果没有keyPath数组认为不需要更新
5495+
// 第一次设置数据成功后,标记位置true,再更新到这个节点如果没有keyPath数组认为不需要更新
54795496
vm._mpValueSet = 'done';
54805497
}
5481-
if (Vue$3.config.devtools) {
5498+
if (Vue$3.config._mpTrace) {
54825499
// console.log('更新VM节点', vm)
54835500
// console.log('实际传到Page.setData数据', data)
54845501
diffLog(data);
@@ -5624,7 +5641,6 @@ function getPage (vm) {
56245641
}
56255642

56265643
// 优化js变量动态变化时候引起全量更新
5627-
56285644
// 优化每次 setData 都传递大量新数据
56295645
function updateDataToMP () {
56305646
var page = getPage(this);
@@ -5633,9 +5649,7 @@ function updateDataToMP () {
56335649
}
56345650

56355651
var data = formatVmData(this);
5636-
56375652
diffData(this, data);
5638-
56395653
throttleSetData(page.setData.bind(page), data);
56405654
}
56415655

@@ -5743,6 +5757,8 @@ function getWebEventByMP (e) {
57435757
return event
57445758
}
57455759

5760+
5761+
var KEY_SEP$1 = '_';
57465762
function handleProxyWithVue (e) {
57475763
var rootVueVM = this.$root;
57485764
var type = e.type;
@@ -5752,7 +5768,7 @@ function handleProxyWithVue (e) {
57525768
var dataset = ref.dataset; if ( dataset === void 0 ) dataset = {};
57535769
var comkey = dataset.comkey; if ( comkey === void 0 ) comkey = '';
57545770
var eventid = dataset.eventid;
5755-
var vm = getVM(rootVueVM, comkey.split(','));
5771+
var vm = getVM(rootVueVM, comkey.split(KEY_SEP$1));
57565772

57575773
if (!vm) {
57585774
return

packages/mpvue/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mpvue",
3-
"version": "1.0.13",
3+
"version": "1.0.19",
44
"description": "Vue Runtime for mini program",
55
"main": "index.js",
66
"repository": {

0 commit comments

Comments
 (0)