提交 07d03bfc 编写于 作者: fxy060608's avatar fxy060608

build uni-app-plus

上级 c6528f2e
...@@ -21,7 +21,7 @@ function hasOwn (obj, key) { ...@@ -21,7 +21,7 @@ function hasOwn (obj, key) {
function noop () {} function noop () {}
const SYNC_API_RE = /hideKeyboard|upx2px|canIUse|^create|Sync$|Manager$/; const SYNC_API_RE = /requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$/;
const CONTEXT_API_RE = /^create|Manager$/; const CONTEXT_API_RE = /^create|Manager$/;
...@@ -228,35 +228,6 @@ TODOS.forEach(function (name) { ...@@ -228,35 +228,6 @@ TODOS.forEach(function (name) {
todoApis[name] = createTodoApi(name); todoApis[name] = createTodoApi(name);
}); });
var providers = {};
function getProvider ({
service,
success,
fail,
complete
}) {
let res = false;
if (providers[service]) {
res = {
errMsg: 'getProvider:ok',
service,
provider: providers[service]
};
isFn(success) && success(res);
} else {
res = {
errMsg: 'getProvider:fail:服务[' + service + ']不存在'
};
isFn(fail) && fail(res);
}
isFn(complete) && complete(res);
}
var extraApi = /*#__PURE__*/Object.freeze({
getProvider: getProvider
});
function requireNativePlugin (pluginName) { function requireNativePlugin (pluginName) {
/* eslint-disable no-undef */ /* eslint-disable no-undef */
return __requireNativePlugin__(pluginName) return __requireNativePlugin__(pluginName)
...@@ -289,13 +260,13 @@ function initHooks (mpOptions, hooks, delay = false) { ...@@ -289,13 +260,13 @@ function initHooks (mpOptions, hooks, delay = false) {
}); });
} }
function getData (vueOptions) { function getData (vueOptions, context) {
let data = vueOptions.data || {}; let data = vueOptions.data || {};
const methods = vueOptions.methods || {}; const methods = vueOptions.methods || {};
if (typeof data === 'function') { if (typeof data === 'function') {
try { try {
data = data(); data = data.call(context); // 支持 Vue.prototype 上挂的数据
} catch (e) { } catch (e) {
if (process.env.VUE_APP_DEBUG) { if (process.env.VUE_APP_DEBUG) {
console.warn('根据 Vue 的 data 函数初始化小程序 data 失败,请尽量确保 data 函数中不访问 vm 对象,否则可能影响首次数据渲染速度。', data); console.warn('根据 Vue 的 data 函数初始化小程序 data 失败,请尽量确保 data 函数中不访问 vm 对象,否则可能影响首次数据渲染速度。', data);
...@@ -561,7 +532,7 @@ const hooks$1 = [ ...@@ -561,7 +532,7 @@ const hooks$1 = [
function createPage (vueOptions) { function createPage (vueOptions) {
vueOptions = vueOptions.default || vueOptions; vueOptions = vueOptions.default || vueOptions;
const pageOptions = { const pageOptions = {
data: getData(vueOptions), data: getData(vueOptions, Vue.prototype),
onLoad (args) { onLoad (args) {
this.$vm = new Vue(Object.assign(vueOptions, { this.$vm = new Vue(Object.assign(vueOptions, {
...@@ -570,7 +541,7 @@ function createPage (vueOptions) { ...@@ -570,7 +541,7 @@ function createPage (vueOptions) {
})); }));
this.$vm.__call_hook('created'); this.$vm.__call_hook('created');
this.$vm.__call_hook('onLoad', args); // 开发者一般可能会在 onLoad 时赋值,所以提前到 mount 之前 this.$vm.__call_hook('onLoad', args); // 开发者可能会在 onLoad 时赋值,提前到 mount 之前
this.$vm.$mount(); this.$vm.$mount();
}, },
onReady () { onReady () {
...@@ -615,6 +586,9 @@ function initVueComponent (mpInstace, VueComponent, extraOptions = {}) { ...@@ -615,6 +586,9 @@ function initVueComponent (mpInstace, VueComponent, extraOptions = {}) {
}); });
mpInstace.$vm.$scopedSlots = mpInstace.$vm.$slots = $slots; mpInstace.$vm.$scopedSlots = mpInstace.$vm.$slots = $slots;
} }
// 性能优先,mount 提前到 attached 中,保证组件首次渲染数据被合并
// 导致与标准 Vue 的差异,data 和 computed 中不能使用$parent,provide等组件属性
mpInstace.$vm.$mount();
} }
function createComponent (vueOptions) { function createComponent (vueOptions) {
...@@ -629,7 +603,7 @@ function createComponent (vueOptions) { ...@@ -629,7 +603,7 @@ function createComponent (vueOptions) {
multipleSlots: true, multipleSlots: true,
addGlobalClass: true addGlobalClass: true
}, },
data: getData(vueOptions), data: getData(vueOptions, Vue.prototype),
properties, properties,
lifetimes: { lifetimes: {
attached () { attached () {
...@@ -639,9 +613,9 @@ function createComponent (vueOptions) { ...@@ -639,9 +613,9 @@ function createComponent (vueOptions) {
initVueComponent(this, VueComponent); // 目前发现部分情况小程序 attached 不触发 initVueComponent(this, VueComponent); // 目前发现部分情况小程序 attached 不触发
triggerLink(this); // 处理 parent,children triggerLink(this); // 处理 parent,children
// 初始化渲染数据(需要等 parent,inject 都初始化完成,否则可以放到 attached 里边初始化渲染) // 补充生命周期
this.$vm.__call_hook('created'); this.$vm.__call_hook('created');
this.$vm.$mount(); this.$vm.__call_hook('beforeMount');
this.$vm._isMounted = true; this.$vm._isMounted = true;
this.$vm.__call_hook('mounted'); this.$vm.__call_hook('mounted');
this.$vm.__call_hook('onReady'); this.$vm.__call_hook('onReady');
...@@ -681,12 +655,6 @@ if (typeof Proxy !== 'undefined') { ...@@ -681,12 +655,6 @@ if (typeof Proxy !== 'undefined') {
if (api[name]) { if (api[name]) {
return promisify(name, api[name]) return promisify(name, api[name])
} }
if (extraApi[name]) {
return promisify(name, extraApi[name])
}
if (todoApis[name]) {
return promisify(name, todoApis[name])
}
if (!hasOwn(wx, name) && !hasOwn(protocols, name)) { if (!hasOwn(wx, name) && !hasOwn(protocols, name)) {
return return
} }
...@@ -696,14 +664,6 @@ if (typeof Proxy !== 'undefined') { ...@@ -696,14 +664,6 @@ if (typeof Proxy !== 'undefined') {
} else { } else {
uni.upx2px = upx2px; uni.upx2px = upx2px;
Object.keys(todoApis).forEach(name => {
uni[name] = promisify(name, todoApis[name]);
});
Object.keys(extraApi).forEach(name => {
uni[name] = promisify(name, todoApis[name]);
});
Object.keys(api).forEach(name => { Object.keys(api).forEach(name => {
uni[name] = promisify(name, api[name]); uni[name] = promisify(name, api[name]);
}); });
......
{ {
"name": "@dcloudio/uni-app-plus", "name": "@dcloudio/uni-app-plus",
"version": "0.0.202", "version": "0.0.204",
"description": "uni-app app-plus", "description": "uni-app app-plus",
"main": "dist/index.js", "main": "dist/index.js",
"scripts": { "scripts": {
......
...@@ -21,7 +21,7 @@ function hasOwn (obj, key) { ...@@ -21,7 +21,7 @@ function hasOwn (obj, key) {
function noop () {} function noop () {}
const SYNC_API_RE = /hideKeyboard|upx2px|canIUse|^create|Sync$|Manager$/; const SYNC_API_RE = /requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$/;
const CONTEXT_API_RE = /^create|Manager$/; const CONTEXT_API_RE = /^create|Manager$/;
...@@ -291,13 +291,13 @@ function initHooks (mpOptions, hooks, delay = false) { ...@@ -291,13 +291,13 @@ function initHooks (mpOptions, hooks, delay = false) {
}); });
} }
function getData (vueOptions) { function getData (vueOptions, context) {
let data = vueOptions.data || {}; let data = vueOptions.data || {};
const methods = vueOptions.methods || {}; const methods = vueOptions.methods || {};
if (typeof data === 'function') { if (typeof data === 'function') {
try { try {
data = data(); data = data.call(context); // 支持 Vue.prototype 上挂的数据
} catch (e) { } catch (e) {
if (process.env.VUE_APP_DEBUG) { if (process.env.VUE_APP_DEBUG) {
console.warn('根据 Vue 的 data 函数初始化小程序 data 失败,请尽量确保 data 函数中不访问 vm 对象,否则可能影响首次数据渲染速度。', data); console.warn('根据 Vue 的 data 函数初始化小程序 data 失败,请尽量确保 data 函数中不访问 vm 对象,否则可能影响首次数据渲染速度。', data);
...@@ -563,7 +563,7 @@ const hooks$1 = [ ...@@ -563,7 +563,7 @@ const hooks$1 = [
function createPage (vueOptions) { function createPage (vueOptions) {
vueOptions = vueOptions.default || vueOptions; vueOptions = vueOptions.default || vueOptions;
const pageOptions = { const pageOptions = {
data: getData(vueOptions), data: getData(vueOptions, Vue.prototype),
onLoad (args) { onLoad (args) {
this.$vm = new Vue(Object.assign(vueOptions, { this.$vm = new Vue(Object.assign(vueOptions, {
...@@ -572,7 +572,7 @@ function createPage (vueOptions) { ...@@ -572,7 +572,7 @@ function createPage (vueOptions) {
})); }));
this.$vm.__call_hook('created'); this.$vm.__call_hook('created');
this.$vm.__call_hook('onLoad', args); // 开发者一般可能会在 onLoad 时赋值,所以提前到 mount 之前 this.$vm.__call_hook('onLoad', args); // 开发者可能会在 onLoad 时赋值,提前到 mount 之前
this.$vm.$mount(); this.$vm.$mount();
}, },
onReady () { onReady () {
...@@ -634,7 +634,7 @@ function createComponent (vueOptions) { ...@@ -634,7 +634,7 @@ function createComponent (vueOptions) {
multipleSlots: true, multipleSlots: true,
addGlobalClass: true addGlobalClass: true
}, },
data: getData(vueOptions), data: getData(vueOptions, Vue.prototype),
properties, properties,
lifetimes: { lifetimes: {
attached () { attached () {
...@@ -686,9 +686,11 @@ if (typeof Proxy !== 'undefined') { ...@@ -686,9 +686,11 @@ if (typeof Proxy !== 'undefined') {
if (api[name]) { if (api[name]) {
return promisify(name, api[name]) return promisify(name, api[name])
} }
{
if (extraApi[name]) { if (extraApi[name]) {
return promisify(name, extraApi[name]) return promisify(name, extraApi[name])
} }
}
if (todoApis[name]) { if (todoApis[name]) {
return promisify(name, todoApis[name]) return promisify(name, todoApis[name])
} }
...@@ -705,9 +707,11 @@ if (typeof Proxy !== 'undefined') { ...@@ -705,9 +707,11 @@ if (typeof Proxy !== 'undefined') {
uni[name] = promisify(name, todoApis[name]); uni[name] = promisify(name, todoApis[name]);
}); });
{
Object.keys(extraApi).forEach(name => { Object.keys(extraApi).forEach(name => {
uni[name] = promisify(name, todoApis[name]); uni[name] = promisify(name, todoApis[name]);
}); });
}
Object.keys(api).forEach(name => { Object.keys(api).forEach(name => {
uni[name] = promisify(name, api[name]); uni[name] = promisify(name, api[name]);
......
{ {
"name": "@dcloudio/uni-mp-weixin", "name": "@dcloudio/uni-mp-weixin",
"version": "0.0.913", "version": "0.0.914",
"description": "uni-app mp-weixin", "description": "uni-app mp-weixin",
"main": "dist/index.js", "main": "dist/index.js",
"scripts": { "scripts": {
......
...@@ -2,7 +2,7 @@ import { ...@@ -2,7 +2,7 @@ import {
isFn isFn
} from 'uni-shared' } from 'uni-shared'
const SYNC_API_RE = /hideKeyboard|upx2px|canIUse|^create|Sync$|Manager$/ const SYNC_API_RE = /requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$/
const CONTEXT_API_RE = /^create|Manager$/ const CONTEXT_API_RE = /^create|Manager$/
......
...@@ -31,12 +31,14 @@ if (typeof Proxy !== 'undefined') { ...@@ -31,12 +31,14 @@ if (typeof Proxy !== 'undefined') {
if (api[name]) { if (api[name]) {
return promisify(name, api[name]) return promisify(name, api[name])
} }
if (__PLATFORM__ !== 'app-plus') {
if (extraApi[name]) { if (extraApi[name]) {
return promisify(name, extraApi[name]) return promisify(name, extraApi[name])
} }
if (todoApi[name]) { if (todoApi[name]) {
return promisify(name, todoApi[name]) return promisify(name, todoApi[name])
} }
}
if (!hasOwn(__GLOBAL__, name) && !hasOwn(protocols, name)) { if (!hasOwn(__GLOBAL__, name) && !hasOwn(protocols, name)) {
return return
} }
...@@ -46,13 +48,14 @@ if (typeof Proxy !== 'undefined') { ...@@ -46,13 +48,14 @@ if (typeof Proxy !== 'undefined') {
} else { } else {
uni.upx2px = upx2px uni.upx2px = upx2px
if (__PLATFORM__ !== 'app-plus') {
Object.keys(todoApi).forEach(name => { Object.keys(todoApi).forEach(name => {
uni[name] = promisify(name, todoApi[name]) uni[name] = promisify(name, todoApi[name])
}) })
Object.keys(extraApi).forEach(name => { Object.keys(extraApi).forEach(name => {
uni[name] = promisify(name, todoApi[name]) uni[name] = promisify(name, todoApi[name])
}) })
}
Object.keys(api).forEach(name => { Object.keys(api).forEach(name => {
uni[name] = promisify(name, api[name]) uni[name] = promisify(name, api[name])
......
...@@ -50,7 +50,7 @@ export function createComponent (vueOptions) { ...@@ -50,7 +50,7 @@ export function createComponent (vueOptions) {
multipleSlots: true, multipleSlots: true,
addGlobalClass: true addGlobalClass: true
}, },
data: getData(vueOptions), data: getData(vueOptions, Vue.prototype),
properties, properties,
lifetimes: { lifetimes: {
attached () { attached () {
......
...@@ -30,7 +30,7 @@ const hooks = [ ...@@ -30,7 +30,7 @@ const hooks = [
export function createPage (vueOptions) { export function createPage (vueOptions) {
vueOptions = vueOptions.default || vueOptions vueOptions = vueOptions.default || vueOptions
const pageOptions = { const pageOptions = {
data: getData(vueOptions), data: getData(vueOptions, Vue.prototype),
onLoad (args) { onLoad (args) {
if (__PLATFORM__ === 'mp-baidu') { if (__PLATFORM__ === 'mp-baidu') {
this.$baiduComponentInstances = Object.create(null) this.$baiduComponentInstances = Object.create(null)
...@@ -42,7 +42,7 @@ export function createPage (vueOptions) { ...@@ -42,7 +42,7 @@ export function createPage (vueOptions) {
})) }))
this.$vm.__call_hook('created') this.$vm.__call_hook('created')
this.$vm.__call_hook('onLoad', args) // 开发者一般可能会在 onLoad 时赋值,所以提前到 mount 之前 this.$vm.__call_hook('onLoad', args) // 开发者可能会在 onLoad 时赋值,提前到 mount 之前
this.$vm.$mount() this.$vm.$mount()
}, },
onReady () { onReady () {
......
...@@ -28,13 +28,13 @@ export function initHooks (mpOptions, hooks, delay = false) { ...@@ -28,13 +28,13 @@ export function initHooks (mpOptions, hooks, delay = false) {
}) })
} }
export function getData (vueOptions) { export function getData (vueOptions, context) {
let data = vueOptions.data || {} let data = vueOptions.data || {}
const methods = vueOptions.methods || {} const methods = vueOptions.methods || {}
if (typeof data === 'function') { if (typeof data === 'function') {
try { try {
data = data() data = data.call(context) // 支持 Vue.prototype 上挂的数据
} catch (e) { } catch (e) {
if (process.env.VUE_APP_DEBUG) { if (process.env.VUE_APP_DEBUG) {
console.warn('根据 Vue 的 data 函数初始化小程序 data 失败,请尽量确保 data 函数中不访问 vm 对象,否则可能影响首次数据渲染速度。', data) console.warn('根据 Vue 的 data 函数初始化小程序 data 失败,请尽量确保 data 函数中不访问 vm 对象,否则可能影响首次数据渲染速度。', data)
......
export default function requireNativePlugin (pluginName) {
/* eslint-disable no-undef */
return __requireNativePlugin__(pluginName)
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册