Skip to content

Commit

Permalink
Merge pull request #277 from Meituan-Dianping/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
anchengjian authored Apr 13, 2018
2 parents 3f39878 + e179a6d commit 94c119a
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 22 deletions.
8 changes: 4 additions & 4 deletions packages/mpvue-template-compiler/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -1676,7 +1676,6 @@ function handleError (err, vm, info) {
}

/* */
/* globals MutationObserver */

// can we use __proto__?
var hasProto = '__proto__' in {};
Expand Down Expand Up @@ -4352,15 +4351,15 @@ function transformDynamicClass (staticClass, clsBinding) {
var result = babel.transform(("!" + clsBinding), { plugins: [transformObjectToTernaryOperator] });
// 先实现功能,再优化代码
// https://github.com/babel/babel/issues/7138
var cls = prettier.format(result.code, { semi: false, singleQuote: true }).slice(1).slice(0, -1).replace(/\n|\r/g, "");
var cls = prettier.format(result.code, { semi: false, singleQuote: true }).slice(1).slice(0, -1).replace(/\n|\r/g, '');
return (staticClass + " {{" + cls + "}}")
}

function transformDynamicStyle (staticStyle, styleBinding) {
if ( staticStyle === void 0 ) staticStyle = '';

var result = babel.transform(("!" + styleBinding), { plugins: [transformObjectToString] });
var cls = prettier.format(result.code, { semi: false, singleQuote: true }).slice(1).slice(0, -1).replace(/\n|\r/g, "");
var cls = prettier.format(result.code, { semi: false, singleQuote: true }).slice(1).slice(0, -1).replace(/\n|\r/g, '');
return (staticStyle + " {{" + cls + "}}")
}

Expand Down Expand Up @@ -4863,7 +4862,8 @@ function compileToWxml (compiled, options) {
slot.code = generate$2(slot.node, options);
});

return { code: code, compiled: compiled, slots: slots }
// TODO: 后期优化掉这种暴力全部 import,虽然对性能没啥大影响
return { code: code, compiled: compiled, slots: slots, importCode: importCode }
}

/* */
Expand Down
2 changes: 1 addition & 1 deletion packages/mpvue-template-compiler/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mpvue-template-compiler",
"version": "1.0.7",
"version": "1.0.8",
"description": "mpvue template compiler for Vue",
"main": "index.js",
"repository": {
Expand Down
27 changes: 20 additions & 7 deletions packages/mpvue/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,6 @@ function handleError (err, vm, info) {
}

/* */
/* globals MutationObserver */

// can we use __proto__?
var hasProto = '__proto__' in {};
Expand Down Expand Up @@ -4145,7 +4144,7 @@ Object.defineProperty(Vue$3.prototype, '$ssrContext', {
});

Vue$3.version = '2.4.1';
Vue$3.mpvueVersion = '1.0.7';
Vue$3.mpvueVersion = '1.0.8';

/* globals renderer */

Expand Down Expand Up @@ -5342,7 +5341,20 @@ function getHandle (vnode, eventid, eventTypes) {
var children = ref.children; if ( children === void 0 ) children = [];
var componentInstance = ref.componentInstance;
if (componentInstance) {
return res
// 增加 slot 情况的处理
// Object.values 会多增加几行编译后的代码
Object.keys(componentInstance.$slots).forEach(function (slotKey) {
var slot = componentInstance.$slots[slotKey];
var slots = Array.isArray(slot) ? slot : [slot];
slots.forEach(function (node) {
res = res.concat(getHandle(node, eventid, eventTypes));
});
});
} else {
// 避免遍历超出当前组件的 vm
children.forEach(function (node) {
res = res.concat(getHandle(node, eventid, eventTypes));
});
}

var attrs = data.attrs;
Expand All @@ -5359,10 +5371,6 @@ function getHandle (vnode, eventid, eventTypes) {
return res
}

children.forEach(function (node) {
res = res.concat(getHandle(node, eventid, eventTypes));
});

return res
}

Expand Down Expand Up @@ -5416,6 +5424,11 @@ function handleProxyWithVue (e) {
if (handles.length) {
var event = getWebEventByMP(e);
handles.forEach(function (h) { return h(event); });
} else {
var currentPage = vm.$mp.page.route;
console.group(new Date() + ' 事件警告');
console.warn(("Do not have handler in current page: " + currentPage + ". Please make sure that handler has been defined in " + currentPage + ", or " + currentPage + " has been added into app.json"));
console.groupEnd();
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/mpvue/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mpvue",
"version": "1.0.7",
"version": "1.0.8",
"description": "Vue Runtime for mini program",
"main": "index.js",
"repository": {
Expand Down
1 change: 0 additions & 1 deletion src/core/util/env.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* @flow */
/* globals MutationObserver */

import { noop } from 'shared/util'
import { handleError } from './error'
Expand Down
4 changes: 2 additions & 2 deletions src/platforms/mp/compiler/codegen/convert/attrs.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ function transformDynamicClass (staticClass = '', clsBinding) {
const result = babel.transform(`!${clsBinding}`, { plugins: [transformObjectToTernaryOperator] })
// 先实现功能,再优化代码
// https://github.com/babel/babel/issues/7138
const cls = prettier.format(result.code, { semi: false, singleQuote: true }).slice(1).slice(0, -1).replace(/\n|\r/g, "")
const cls = prettier.format(result.code, { semi: false, singleQuote: true }).slice(1).slice(0, -1).replace(/\n|\r/g, '')
return `${staticClass} {{${cls}}}`
}

function transformDynamicStyle (staticStyle = '', styleBinding) {
const result = babel.transform(`!${styleBinding}`, { plugins: [transformObjectToString] })
const cls = prettier.format(result.code, { semi: false, singleQuote: true }).slice(1).slice(0, -1).replace(/\n|\r/g, "")
const cls = prettier.format(result.code, { semi: false, singleQuote: true }).slice(1).slice(0, -1).replace(/\n|\r/g, '')
return `${staticStyle} {{${cls}}}`
}

Expand Down
3 changes: 2 additions & 1 deletion src/platforms/mp/compiler/codegen/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ export function compileToWxml (compiled, options = {}) {
slot.code = generate(slot.node, options)
})

return { code, compiled, slots }
// TODO: 后期优化掉这种暴力全部 import,虽然对性能没啥大影响
return { code, compiled, slots, importCode }
}
24 changes: 19 additions & 5 deletions src/platforms/mp/runtime/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,20 @@ function getHandle (vnode, eventid, eventTypes = []) {

const { data = {}, children = [], componentInstance } = vnode || {}
if (componentInstance) {
return res
// 增加 slot 情况的处理
// Object.values 会多增加几行编译后的代码
Object.keys(componentInstance.$slots).forEach(slotKey => {
const slot = componentInstance.$slots[slotKey]
const slots = Array.isArray(slot) ? slot : [slot]
slots.forEach(node => {
res = res.concat(getHandle(node, eventid, eventTypes))
})
})
} else {
// 避免遍历超出当前组件的 vm
children.forEach(node => {
res = res.concat(getHandle(node, eventid, eventTypes))
})
}

const { attrs, on } = data
Expand All @@ -43,10 +56,6 @@ function getHandle (vnode, eventid, eventTypes = []) {
return res
}

children.forEach(node => {
res = res.concat(getHandle(node, eventid, eventTypes))
})

return res
}

Expand Down Expand Up @@ -90,5 +99,10 @@ export function handleProxyWithVue (e) {
if (handles.length) {
const event = getWebEventByMP(e)
handles.forEach(h => h(event))
} else {
const currentPage = vm.$mp.page.route
console.group(new Date() + ' 事件警告')
console.warn(`Do not have handler in current page: ${currentPage}. Please make sure that handler has been defined in ${currentPage}, or ${currentPage} has been added into app.json`)
console.groupEnd()
}
}

0 comments on commit 94c119a

Please sign in to comment.