Skip to content

Commit

Permalink
mpvue 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hucq committed Feb 13, 2019
1 parent f21ee4d commit c1feaab
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 36 deletions.
49 changes: 17 additions & 32 deletions packages/mpvue-template-compiler/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -5895,9 +5895,9 @@ var attrs$3 = {
} else if (key === 'v-show') {
attrs['hidden'] = "{{!(" + val + ")}}";
} else if (/^v\-on\:/i.test(key)) {
attrs = this$1.event(key, val, attrs, tag);
attrs = this$1.event(key, val, attrs, tag, log);
} else if (/^v\-bind\:/i.test(key)) {
attrs = this$1.bind(key, val, attrs, tag, attrsMap['wx:key']);
attrs = this$1.bind(key, val, attrs, tag, attrsMap['a:key']);
} else if (/^v\-model/.test(key)) {
attrs = this$1.model(key, val, attrs, tag, log);
} else if (directiveMap$3[key]) {
Expand Down Expand Up @@ -5941,7 +5941,7 @@ var attrs$3 = {
return ast
},

event: function event (key, val, attrs, tag) {
event: function event (key, val, attrs, tag, log) {
// 小程序能力所致,bind 和 catch 事件同时绑定时候,只会触发 bind ,catch 不会被触发。
// .stop 的使用会阻止冒泡,但是同时绑定了一个非冒泡事件,会导致该元素上的 catchEventName 失效!
// .prevent 可以直接干掉,因为小程序里没有什么默认事件,比如submit并不会跳转页面
Expand All @@ -5968,7 +5968,7 @@ var attrs$3 = {
var eventType = 'on';
var isStop = eventNameMap.includes('stop');
if (eventNameMap.includes('capture')) {
eventType = isStop ? 'capture-catch:' : 'capture-bind:';
log('支付宝小程序不支持事件捕获');
} else if (isStop) {
eventType = 'catch';
}
Expand All @@ -5983,28 +5983,12 @@ var attrs$3 = {
var name = key.replace(/^v\-bind\:/i, '');

if (isIf && name === 'key') {
attrs['wx:key'] = val;
attrs['a:key'] = val;
}

node.tag = 'template';
node.attrsMap.name = slotId;
delete node.attrsMap.slot;
// 缓存,会集中生成一个 slots 文件
slots[slotId] = { node: convertAst$1(node, options, util), name: slotName, slotId: slotId };
wxmlAst.slots[slotName] = slotId;
});
// 清理当前组件下的节点信息,因为 slot 都被转移了
children.length = 0;
wxmlAst.children.length = 0;
}

wxmlAst.attrsMap = attrs$1.format(wxmlAst.attrsMap);
wxmlAst = tag$1(wxmlAst, options);
wxmlAst = convertFor$1(wxmlAst, options);
wxmlAst = attrs$1.convertAttr(wxmlAst, log);
if (children && !isSlot) {
wxmlAst.children = children.map(function (k) { return convertAst$1(k, options, util); });
}
if (tag === 'template') {
return attrs
}

if (name === 'href') {
attrs['url'] = "{{" + val + "}}";
Expand Down Expand Up @@ -6046,18 +6030,17 @@ var attrs$3 = {
attrs['value'] = "{{" + val + "}}";
if (key === 'v-model.lazy') {
if (isFormInput) {
attrs['bindblur'] = 'handleProxy';
attrs['onBlur'] = 'handleProxy';
} else {
attrs['bindchange'] = 'handleProxy';
attrs['onChange'] = 'handleProxy';
}
} else {
if (isFormInput) {
attrs['bindinput'] = 'handleProxy';
attrs['onInput'] = 'handleProxy';
} else {
attrs['bindchange'] = 'handleProxy';
attrs['onChange'] = 'handleProxy';
}
}

return attrs
}
};
Expand Down Expand Up @@ -6146,9 +6129,11 @@ var convertFor$3 = function (ast) {
attrsMap[astMap$3['alias']] = alias;
}

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

return ast
};

function mpmlAst$3 (compiled, options, log) {
if ( options === void 0 ) options = {};
Expand Down
2 changes: 0 additions & 2 deletions packages/mpvue-template-compiler/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "mpvue-template-compiler",
"version": "2.0.0",
"version": "1.0.20",
"description": "mpvue template compiler for Vue",
"main": "index.js",
"repository": {
Expand All @@ -26,4 +25,3 @@
"de-indent": "^1.0.2"
}
}

3 changes: 1 addition & 2 deletions packages/mpvue/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4185,7 +4185,7 @@ Object.defineProperty(Vue$3.prototype, '$ssrContext', {
});

Vue$3.version = '2.4.1';
Vue$3.mpvueVersion = '1.0.20';
Vue$3.mpvueVersion = '2.0.0';

/* globals renderer */

Expand Down Expand Up @@ -5471,7 +5471,6 @@ function diffData (vm, data) {
Object.keys(vmData).forEach(function (vmDataItemKey) {
if (vmData[vmDataItemKey] instanceof Object) {
// 引用类型
if (vmDataItemKey === '__keyPath') { return }
minifyDeepData(rootKey, vmDataItemKey, vmData[vmDataItemKey], data, vm._mpValueSet, vm);
} else if (vmData[vmDataItemKey] !== undefined) {
// _data上的值属性只有要更新的时候才赋值
Expand Down

0 comments on commit c1feaab

Please sign in to comment.