提交 6924630d 编写于 作者: fxy060608's avatar fxy060608

feat(mp): add createSubpackageApp

上级 4510acbc
......@@ -639,74 +639,6 @@ if (!MPPage.__$wrappered) {
};
}
class EventChannel {
constructor (id, events) {
this.id = id;
this.listener = {};
this.emitCache = {};
if (events) {
Object.keys(events).forEach(name => {
this.on(name, events[name]);
});
}
}
emit (eventName, ...args) {
const fns = this.listener[eventName];
if (!fns) {
return (this.emitCache[eventName] || (this.emitCache[eventName] = [])).push(args)
}
fns.forEach(opt => {
opt.fn.apply(opt.fn, args);
});
this.listener[eventName] = fns.filter(opt => opt.type !== 'once');
}
on (eventName, fn) {
this._addListener(eventName, 'on', fn);
this._clearCache(eventName);
}
once (eventName, fn) {
this._addListener(eventName, 'once', fn);
this._clearCache(eventName);
}
off (eventName, fn) {
const fns = this.listener[eventName];
if (!fns) {
return
}
if (fn) {
for (let i = 0; i < fns.length;) {
if (fns[i].fn === fn) {
fns.splice(i, 1);
i--;
}
i++;
}
} else {
delete this.listener[eventName];
}
}
_clearCache (eventName) {
const cacheArgs = this.emitCache[eventName];
if (cacheArgs) {
for (; cacheArgs.length > 0;) {
this.emit.apply(this, [eventName].concat(cacheArgs.shift()));
}
}
}
_addListener (eventName, type, fn) {
(this.listener[eventName] || (this.listener[eventName] = [])).push({
fn,
type
});
}
}
const PAGE_EVENT_HOOKS = [
'onPullDownRefresh',
'onReachBottom',
......@@ -1245,19 +1177,118 @@ function handleEvent (event) {
}
}
class EventChannel {
constructor (id, events) {
this.id = id;
this.listener = {};
this.emitCache = {};
if (events) {
Object.keys(events).forEach(name => {
this.on(name, events[name]);
});
}
}
emit (eventName, ...args) {
const fns = this.listener[eventName];
if (!fns) {
return (this.emitCache[eventName] || (this.emitCache[eventName] = [])).push(args)
}
fns.forEach(opt => {
opt.fn.apply(opt.fn, args);
});
this.listener[eventName] = fns.filter(opt => opt.type !== 'once');
}
on (eventName, fn) {
this._addListener(eventName, 'on', fn);
this._clearCache(eventName);
}
once (eventName, fn) {
this._addListener(eventName, 'once', fn);
this._clearCache(eventName);
}
off (eventName, fn) {
const fns = this.listener[eventName];
if (!fns) {
return
}
if (fn) {
for (let i = 0; i < fns.length;) {
if (fns[i].fn === fn) {
fns.splice(i, 1);
i--;
}
i++;
}
} else {
delete this.listener[eventName];
}
}
_clearCache (eventName) {
const cacheArgs = this.emitCache[eventName];
if (cacheArgs) {
for (; cacheArgs.length > 0;) {
this.emit.apply(this, [eventName].concat(cacheArgs.shift()));
}
}
}
_addListener (eventName, type, fn) {
(this.listener[eventName] || (this.listener[eventName] = [])).push({
fn,
type
});
}
}
const eventChannels = {};
const eventChannelStack = [];
function getEventChannel (id) {
if (id) {
const eventChannel = eventChannels[id];
delete eventChannels[id];
return eventChannel
}
return eventChannelStack.shift()
}
const hooks = [
'onShow',
'onHide',
'onError',
'onPageNotFound',
'onThemeChange',
'onPageNotFound',
'onThemeChange',
'onUnhandledRejection'
];
function initEventChannel () {
Vue.prototype.getOpenerEventChannel = function () {
if (!this.__eventChannel__) {
this.__eventChannel__ = new EventChannel();
}
return this.__eventChannel__
};
const callHook = Vue.prototype.__call_hook;
Vue.prototype.__call_hook = function (hook, args) {
if (hook === 'onLoad' && args && args.__id__) {
this.__eventChannel__ = getEventChannel(args.__id__);
delete args.__id__;
}
return callHook.call(this, hook, args)
};
}
function parseBaseApp (vm, {
mocks,
initRefs
}) {
initEventChannel();
if (vm.$options.store) {
Vue.prototype.$store = vm.$options.store;
}
......@@ -1426,34 +1457,7 @@ function parseApp$1 (vm) {
return appOptions
}
const eventChannels = {};
const eventChannelStack = [];
function getEventChannel (id) {
if (id) {
const eventChannel = eventChannels[id];
delete eventChannels[id];
return eventChannel
}
return eventChannelStack.shift()
}
function createApp (vm) {
Vue.prototype.getOpenerEventChannel = function () {
if (!this.__eventChannel__) {
this.__eventChannel__ = new EventChannel();
}
return this.__eventChannel__
};
const callHook = Vue.prototype.__call_hook;
Vue.prototype.__call_hook = function (hook, args) {
if (hook === 'onLoad' && args && args.__id__) {
this.__eventChannel__ = getEventChannel(args.__id__);
delete args.__id__;
}
return callHook.call(this, hook, args)
};
App(parseApp$1(vm));
return vm
}
......@@ -1675,6 +1679,27 @@ function createComponent (vueOptions) {
}
}
function createSubpackageApp (vm) {
const appOptions = parseApp$1(vm);
const app = getApp({
allowDefault: true
});
const globalData = app.globalData;
if (globalData) {
Object.keys(appOptions.globalData).forEach(name => {
if (!hasOwn(globalData, name)) {
globalData[name] = appOptions.globalData[name];
}
});
}
Object.keys(appOptions).forEach(name => {
if (!hasOwn(app, name)) {
app[name] = appOptions[name];
}
});
return vm
}
todos.forEach(todoApi => {
protocols[todoApi] = false;
});
......@@ -1744,8 +1769,9 @@ if (typeof Proxy !== 'undefined' && "app-plus" !== 'app-plus') {
wx.createApp = createApp;
wx.createPage = createPage;
wx.createComponent = createComponent;
wx.createSubpackageApp = createSubpackageApp;
var uni$1 = uni;
export default uni$1;
export { createApp, createComponent, createPage };
export { createApp, createComponent, createPage, createSubpackageApp };
import { v4 } from 'uuid';
import Vue from 'vue';
const _toString = Object.prototype.toString;
......@@ -513,18 +512,18 @@ function removeStorageSync (key) {
})
}
const UUID_KEY = '__DC_UUID';
let uuid;
const UUID_KEY = '__DC_STAT_UUID';
let deviceId;
function addUuid (result) {
uuid = uuid || getStorageSync(UUID_KEY);
if (!uuid) {
uuid = v4();
deviceId = deviceId || getStorageSync(UUID_KEY);
if (!deviceId) {
deviceId = Date.now() + '' + Math.floor(Math.random() * 1e7);
my.setStorage({
key: UUID_KEY,
data: uuid
data: deviceId
});
}
result.uuid = uuid;
result.deviceId = deviceId;
}
function addSafeAreaInsets (result) {
......@@ -1905,15 +1904,33 @@ const hooks = [
'onShow',
'onHide',
'onError',
'onPageNotFound',
'onThemeChange',
'onPageNotFound',
'onThemeChange',
'onUnhandledRejection'
];
function initEventChannel$1 () {
Vue.prototype.getOpenerEventChannel = function () {
if (!this.__eventChannel__) {
this.__eventChannel__ = new EventChannel();
}
return this.__eventChannel__
};
const callHook = Vue.prototype.__call_hook;
Vue.prototype.__call_hook = function (hook, args) {
if (hook === 'onLoad' && args && args.__id__) {
this.__eventChannel__ = getEventChannel(args.__id__);
delete args.__id__;
}
return callHook.call(this, hook, args)
};
}
function parseBaseApp (vm, {
mocks,
initRefs
}) {
initEventChannel$1();
if (vm.$options.store) {
Vue.prototype.$store = vm.$options.store;
}
......@@ -2317,20 +2334,6 @@ function parseApp (vm) {
}
function createApp (vm) {
Vue.prototype.getOpenerEventChannel = function () {
if (!this.__eventChannel__) {
this.__eventChannel__ = new EventChannel();
}
return this.__eventChannel__
};
const callHook = Vue.prototype.__call_hook;
Vue.prototype.__call_hook = function (hook, args) {
if (hook === 'onLoad' && args && args.__id__) {
this.__eventChannel__ = getEventChannel(args.__id__);
delete args.__id__;
}
return callHook.call(this, hook, args)
};
App(parseApp(vm));
return vm
}
......@@ -2589,6 +2592,27 @@ function createComponent (vueOptions) {
}
}
function createSubpackageApp (vm) {
const appOptions = parseApp(vm);
const app = getApp({
allowDefault: true
});
const globalData = app.globalData;
if (globalData) {
Object.keys(appOptions.globalData).forEach(name => {
if (!hasOwn(globalData, name)) {
globalData[name] = appOptions.globalData[name];
}
});
}
Object.keys(appOptions).forEach(name => {
if (!hasOwn(app, name)) {
app[name] = appOptions[name];
}
});
return vm
}
todos.forEach(todoApi => {
protocols[todoApi] = false;
});
......@@ -2668,8 +2692,9 @@ if (typeof Proxy !== 'undefined' && "mp-alipay" !== 'app-plus') {
my.createApp = createApp;
my.createPage = createPage;
my.createComponent = createComponent;
my.createSubpackageApp = createSubpackageApp;
var uni$1 = uni;
export default uni$1;
export { createApp, createComponent, createPage };
export { createApp, createComponent, createPage, createSubpackageApp };
import { v4 } from 'uuid';
import Vue from 'vue';
const _toString = Object.prototype.toString;
......@@ -528,18 +527,18 @@ var previewImage = {
}
};
const UUID_KEY = '__DC_UUID';
let uuid;
const UUID_KEY = '__DC_STAT_UUID';
let deviceId;
function addUuid (result) {
uuid = uuid || swan.getStorageSync(UUID_KEY);
if (!uuid) {
uuid = v4();
deviceId = deviceId || swan.getStorageSync(UUID_KEY);
if (!deviceId) {
deviceId = Date.now() + '' + Math.floor(Math.random() * 1e7);
swan.setStorage({
key: UUID_KEY,
data: uuid
data: deviceId
});
}
result.uuid = uuid;
result.deviceId = deviceId;
}
function addSafeAreaInsets (result) {
......@@ -1594,15 +1593,33 @@ const hooks = [
'onShow',
'onHide',
'onError',
'onPageNotFound',
'onThemeChange',
'onPageNotFound',
'onThemeChange',
'onUnhandledRejection'
];
function initEventChannel$1 () {
Vue.prototype.getOpenerEventChannel = function () {
if (!this.__eventChannel__) {
this.__eventChannel__ = new EventChannel();
}
return this.__eventChannel__
};
const callHook = Vue.prototype.__call_hook;
Vue.prototype.__call_hook = function (hook, args) {
if (hook === 'onLoad' && args && args.__id__) {
this.__eventChannel__ = getEventChannel(args.__id__);
delete args.__id__;
}
return callHook.call(this, hook, args)
};
}
function parseBaseApp (vm, {
mocks,
initRefs
}) {
initEventChannel$1();
if (vm.$options.store) {
Vue.prototype.$store = vm.$options.store;
}
......@@ -1770,20 +1787,6 @@ function parseApp (vm) {
}
function createApp (vm) {
Vue.prototype.getOpenerEventChannel = function () {
if (!this.__eventChannel__) {
this.__eventChannel__ = new EventChannel();
}
return this.__eventChannel__
};
const callHook = Vue.prototype.__call_hook;
Vue.prototype.__call_hook = function (hook, args) {
if (hook === 'onLoad' && args && args.__id__) {
this.__eventChannel__ = getEventChannel(args.__id__);
delete args.__id__;
}
return callHook.call(this, hook, args)
};
App(parseApp(vm));
return vm
}
......@@ -1934,16 +1937,17 @@ function parseComponent (vueOptions) {
// 关于百度小程序生命周期的说明(组件作为页面时):
// lifetimes:attached --> methods:onShow --> methods:onLoad --> methods:onReady
// 这里在强制将onShow挪到onLoad之后触发,另外一处修改在page-parser.js
let oldAttached = componentOptions.lifetimes.attached;
const oldAttached = componentOptions.lifetimes.attached;
// 百度小程序基础库 3.260 以上支持页面 onInit 生命周期,提前创建 vm 实例
componentOptions.lifetimes.onInit = function onInit (query) {
oldAttached.call(this);
oldAttached = noop;
this.pageinstance.$vm = this.$vm;
this.$vm.__call_hook('onInit', query);
};
componentOptions.lifetimes.attached = function attached () {
oldAttached.call(this);
if (!this.$vm) {
oldAttached.call(this);
}
if (isPage.call(this)) { // 百度 onLoad 在 attached 之前触发(基础库小于 3.70)
// 百度 当组件作为页面时 pageinstancce 不是原来组件的 instance
this.pageinstance.$vm = this.$vm;
......@@ -2074,6 +2078,27 @@ function createComponent (vueOptions) {
}
}
function createSubpackageApp (vm) {
const appOptions = parseApp(vm);
const app = getApp({
allowDefault: true
});
const globalData = app.globalData;
if (globalData) {
Object.keys(appOptions.globalData).forEach(name => {
if (!hasOwn(globalData, name)) {
globalData[name] = appOptions.globalData[name];
}
});
}
Object.keys(appOptions).forEach(name => {
if (!hasOwn(app, name)) {
app[name] = appOptions[name];
}
});
return vm
}
todos.forEach(todoApi => {
protocols[todoApi] = false;
});
......@@ -2153,8 +2178,9 @@ if (typeof Proxy !== 'undefined' && "mp-baidu" !== 'app-plus') {
swan.createApp = createApp;
swan.createPage = createPage;
swan.createComponent = createComponent;
swan.createSubpackageApp = createSubpackageApp;
var uni$1 = uni;
export default uni$1;
export { createApp, createComponent, createPage };
export { createApp, createComponent, createPage, createSubpackageApp };
import { v4 } from 'uuid';
import Vue from 'vue';
const _toString = Object.prototype.toString;
......@@ -528,18 +527,18 @@ var previewImage = {
}
};
const UUID_KEY = '__DC_UUID';
let uuid;
const UUID_KEY = '__DC_STAT_UUID';
let deviceId;
function addUuid (result) {
uuid = uuid || ks.getStorageSync(UUID_KEY);
if (!uuid) {
uuid = v4();
deviceId = deviceId || ks.getStorageSync(UUID_KEY);
if (!deviceId) {
deviceId = Date.now() + '' + Math.floor(Math.random() * 1e7);
ks.setStorage({
key: UUID_KEY,
data: uuid
data: deviceId
});
}
result.uuid = uuid;
result.deviceId = deviceId;
}
function addSafeAreaInsets (result) {
......@@ -1346,15 +1345,33 @@ const hooks = [
'onShow',
'onHide',
'onError',
'onPageNotFound',
'onThemeChange',
'onPageNotFound',
'onThemeChange',
'onUnhandledRejection'
];
function initEventChannel$1 () {
Vue.prototype.getOpenerEventChannel = function () {
if (!this.__eventChannel__) {
this.__eventChannel__ = new EventChannel();
}
return this.__eventChannel__
};
const callHook = Vue.prototype.__call_hook;
Vue.prototype.__call_hook = function (hook, args) {
if (hook === 'onLoad' && args && args.__id__) {
this.__eventChannel__ = getEventChannel(args.__id__);
delete args.__id__;
}
return callHook.call(this, hook, args)
};
}
function parseBaseApp (vm, {
mocks,
initRefs
}) {
initEventChannel$1();
if (vm.$options.store) {
Vue.prototype.$store = vm.$options.store;
}
......@@ -1516,20 +1533,6 @@ function parseApp$1 (vm) {
}
function createApp (vm) {
Vue.prototype.getOpenerEventChannel = function () {
if (!this.__eventChannel__) {
this.__eventChannel__ = new EventChannel();
}
return this.__eventChannel__
};
const callHook = Vue.prototype.__call_hook;
Vue.prototype.__call_hook = function (hook, args) {
if (hook === 'onLoad' && args && args.__id__) {
this.__eventChannel__ = getEventChannel(args.__id__);
delete args.__id__;
}
return callHook.call(this, hook, args)
};
App(parseApp$1(vm));
return vm
}
......@@ -1733,6 +1736,27 @@ function createComponent (vueOptions) {
}
}
function createSubpackageApp (vm) {
const appOptions = parseApp$1(vm);
const app = getApp({
allowDefault: true
});
const globalData = app.globalData;
if (globalData) {
Object.keys(appOptions.globalData).forEach(name => {
if (!hasOwn(globalData, name)) {
globalData[name] = appOptions.globalData[name];
}
});
}
Object.keys(appOptions).forEach(name => {
if (!hasOwn(app, name)) {
app[name] = appOptions[name];
}
});
return vm
}
todos.forEach(todoApi => {
protocols[todoApi] = false;
});
......@@ -1812,8 +1836,9 @@ if (typeof Proxy !== 'undefined' && "mp-kuaishou" !== 'app-plus') {
ks.createApp = createApp;
ks.createPage = createPage;
ks.createComponent = createComponent;
ks.createSubpackageApp = createSubpackageApp;
var uni$1 = uni;
export default uni$1;
export { createApp, createComponent, createPage };
export { createApp, createComponent, createPage, createSubpackageApp };
import { v4 } from 'uuid';
import Vue from 'vue';
const _toString = Object.prototype.toString;
......@@ -528,18 +527,18 @@ var previewImage = {
}
};
const UUID_KEY = '__DC_UUID';
let uuid;
const UUID_KEY = '__DC_STAT_UUID';
let deviceId;
function addUuid (result) {
uuid = uuid || wx.getStorageSync(UUID_KEY);
if (!uuid) {
uuid = v4();
deviceId = deviceId || wx.getStorageSync(UUID_KEY);
if (!deviceId) {
deviceId = Date.now() + '' + Math.floor(Math.random() * 1e7);
wx.setStorage({
key: UUID_KEY,
data: uuid
data: deviceId
});
}
result.uuid = uuid;
result.deviceId = deviceId;
}
function addSafeAreaInsets (result) {
......@@ -1507,15 +1506,33 @@ const hooks = [
'onShow',
'onHide',
'onError',
'onPageNotFound',
'onThemeChange',
'onPageNotFound',
'onThemeChange',
'onUnhandledRejection'
];
function initEventChannel$1 () {
Vue.prototype.getOpenerEventChannel = function () {
if (!this.__eventChannel__) {
this.__eventChannel__ = new EventChannel();
}
return this.__eventChannel__
};
const callHook = Vue.prototype.__call_hook;
Vue.prototype.__call_hook = function (hook, args) {
if (hook === 'onLoad' && args && args.__id__) {
this.__eventChannel__ = getEventChannel(args.__id__);
delete args.__id__;
}
return callHook.call(this, hook, args)
};
}
function parseBaseApp (vm, {
mocks,
initRefs
}) {
initEventChannel$1();
if (vm.$options.store) {
Vue.prototype.$store = vm.$options.store;
}
......@@ -1682,20 +1699,6 @@ function parseApp$1 (vm) {
}
function createApp (vm) {
Vue.prototype.getOpenerEventChannel = function () {
if (!this.__eventChannel__) {
this.__eventChannel__ = new EventChannel();
}
return this.__eventChannel__
};
const callHook = Vue.prototype.__call_hook;
Vue.prototype.__call_hook = function (hook, args) {
if (hook === 'onLoad' && args && args.__id__) {
this.__eventChannel__ = getEventChannel(args.__id__);
delete args.__id__;
}
return callHook.call(this, hook, args)
};
App(parseApp$1(vm));
return vm
}
......@@ -1906,6 +1909,27 @@ function createComponent (vueOptions) {
}
}
function createSubpackageApp (vm) {
const appOptions = parseApp$1(vm);
const app = getApp({
allowDefault: true
});
const globalData = app.globalData;
if (globalData) {
Object.keys(appOptions.globalData).forEach(name => {
if (!hasOwn(globalData, name)) {
globalData[name] = appOptions.globalData[name];
}
});
}
Object.keys(appOptions).forEach(name => {
if (!hasOwn(app, name)) {
app[name] = appOptions[name];
}
});
return vm
}
todos.forEach(todoApi => {
protocols[todoApi] = false;
});
......@@ -1985,8 +2009,9 @@ if (typeof Proxy !== 'undefined' && "mp-qq" !== 'app-plus') {
wx.createApp = createApp;
wx.createPage = createPage;
wx.createComponent = createComponent;
wx.createSubpackageApp = createSubpackageApp;
var uni$1 = uni;
export default uni$1;
export { createApp, createComponent, createPage };
export { createApp, createComponent, createPage, createSubpackageApp };
import { v4 } from 'uuid';
import Vue from 'vue';
const _toString = Object.prototype.toString;
......@@ -528,18 +527,18 @@ var previewImage = {
}
};
const UUID_KEY = '__DC_UUID';
let uuid;
const UUID_KEY = '__DC_STAT_UUID';
let deviceId;
function addUuid (result) {
uuid = uuid || tt.getStorageSync(UUID_KEY);
if (!uuid) {
uuid = v4();
deviceId = deviceId || tt.getStorageSync(UUID_KEY);
if (!deviceId) {
deviceId = Date.now() + '' + Math.floor(Math.random() * 1e7);
tt.setStorage({
key: UUID_KEY,
data: uuid
data: deviceId
});
}
result.uuid = uuid;
result.deviceId = deviceId;
}
function addSafeAreaInsets (result) {
......@@ -1599,15 +1598,33 @@ const hooks = [
'onShow',
'onHide',
'onError',
'onPageNotFound',
'onThemeChange',
'onPageNotFound',
'onThemeChange',
'onUnhandledRejection'
];
function initEventChannel$1 () {
Vue.prototype.getOpenerEventChannel = function () {
if (!this.__eventChannel__) {
this.__eventChannel__ = new EventChannel();
}
return this.__eventChannel__
};
const callHook = Vue.prototype.__call_hook;
Vue.prototype.__call_hook = function (hook, args) {
if (hook === 'onLoad' && args && args.__id__) {
this.__eventChannel__ = getEventChannel(args.__id__);
delete args.__id__;
}
return callHook.call(this, hook, args)
};
}
function parseBaseApp (vm, {
mocks,
initRefs
}) {
initEventChannel$1();
if (vm.$options.store) {
Vue.prototype.$store = vm.$options.store;
}
......@@ -1849,20 +1866,6 @@ function parseApp (vm) {
}
function createApp (vm) {
Vue.prototype.getOpenerEventChannel = function () {
if (!this.__eventChannel__) {
this.__eventChannel__ = new EventChannel();
}
return this.__eventChannel__
};
const callHook = Vue.prototype.__call_hook;
Vue.prototype.__call_hook = function (hook, args) {
if (hook === 'onLoad' && args && args.__id__) {
this.__eventChannel__ = getEventChannel(args.__id__);
delete args.__id__;
}
return callHook.call(this, hook, args)
};
App(parseApp(vm));
return vm
}
......@@ -2114,6 +2117,27 @@ function createComponent (vueOptions) {
}
}
function createSubpackageApp (vm) {
const appOptions = parseApp(vm);
const app = getApp({
allowDefault: true
});
const globalData = app.globalData;
if (globalData) {
Object.keys(appOptions.globalData).forEach(name => {
if (!hasOwn(globalData, name)) {
globalData[name] = appOptions.globalData[name];
}
});
}
Object.keys(appOptions).forEach(name => {
if (!hasOwn(app, name)) {
app[name] = appOptions[name];
}
});
return vm
}
todos.forEach(todoApi => {
protocols[todoApi] = false;
});
......@@ -2193,8 +2217,9 @@ if (typeof Proxy !== 'undefined' && "mp-toutiao" !== 'app-plus') {
tt.createApp = createApp;
tt.createPage = createPage;
tt.createComponent = createComponent;
tt.createSubpackageApp = createSubpackageApp;
var uni$1 = uni;
export default uni$1;
export { createApp, createComponent, createPage };
export { createApp, createComponent, createPage, createSubpackageApp };
import { v4 } from 'uuid';
import Vue from 'vue';
const _toString = Object.prototype.toString;
......@@ -423,18 +422,18 @@ var previewImage = {
}
};
const UUID_KEY = '__DC_UUID';
let uuid;
const UUID_KEY = '__DC_STAT_UUID';
let deviceId;
function addUuid (result) {
uuid = uuid || wx.getStorageSync(UUID_KEY);
if (!uuid) {
uuid = v4();
deviceId = deviceId || wx.getStorageSync(UUID_KEY);
if (!deviceId) {
deviceId = Date.now() + '' + Math.floor(Math.random() * 1e7);
wx.setStorage({
key: UUID_KEY,
data: uuid
data: deviceId
});
}
result.uuid = uuid;
result.deviceId = deviceId;
}
function addSafeAreaInsets (result) {
......@@ -1247,19 +1246,50 @@ function handleEvent (event) {
}
}
const eventChannels = {};
const eventChannelStack = [];
function getEventChannel (id) {
if (id) {
const eventChannel = eventChannels[id];
delete eventChannels[id];
return eventChannel
}
return eventChannelStack.shift()
}
const hooks = [
'onShow',
'onHide',
'onError',
'onPageNotFound',
'onThemeChange',
'onPageNotFound',
'onThemeChange',
'onUnhandledRejection'
];
function initEventChannel () {
Vue.prototype.getOpenerEventChannel = function () {
// 微信小程序使用自身getOpenerEventChannel
{
return this.$scope.getOpenerEventChannel()
}
};
const callHook = Vue.prototype.__call_hook;
Vue.prototype.__call_hook = function (hook, args) {
if (hook === 'onLoad' && args && args.__id__) {
this.__eventChannel__ = getEventChannel(args.__id__);
delete args.__id__;
}
return callHook.call(this, hook, args)
};
}
function parseBaseApp (vm, {
mocks,
initRefs
}) {
initEventChannel();
if (vm.$options.store) {
Vue.prototype.$store = vm.$options.store;
}
......@@ -1428,34 +1458,7 @@ function parseApp (vm) {
})
}
const eventChannels = {};
const eventChannelStack = [];
function getEventChannel (id) {
if (id) {
const eventChannel = eventChannels[id];
delete eventChannels[id];
return eventChannel
}
return eventChannelStack.shift()
}
function createApp (vm) {
Vue.prototype.getOpenerEventChannel = function () {
// 微信小程序使用自身getOpenerEventChannel
{
return this.$scope.getOpenerEventChannel()
}
};
const callHook = Vue.prototype.__call_hook;
Vue.prototype.__call_hook = function (hook, args) {
if (hook === 'onLoad' && args && args.__id__) {
this.__eventChannel__ = getEventChannel(args.__id__);
delete args.__id__;
}
return callHook.call(this, hook, args)
};
App(parseApp(vm));
return vm
}
......@@ -1658,6 +1661,27 @@ function createComponent (vueOptions) {
}
}
function createSubpackageApp (vm) {
const appOptions = parseApp(vm);
const app = getApp({
allowDefault: true
});
const globalData = app.globalData;
if (globalData) {
Object.keys(appOptions.globalData).forEach(name => {
if (!hasOwn(globalData, name)) {
globalData[name] = appOptions.globalData[name];
}
});
}
Object.keys(appOptions).forEach(name => {
if (!hasOwn(app, name)) {
app[name] = appOptions[name];
}
});
return vm
}
todos.forEach(todoApi => {
protocols[todoApi] = false;
});
......@@ -1737,8 +1761,9 @@ if (typeof Proxy !== 'undefined' && "mp-weixin" !== 'app-plus') {
wx.createApp = createApp;
wx.createPage = createPage;
wx.createComponent = createComponent;
wx.createSubpackageApp = createSubpackageApp;
var uni$1 = uni;
export default uni$1;
export { createApp, createComponent, createPage };
export { createApp, createComponent, createPage, createSubpackageApp };
......@@ -1320,15 +1320,33 @@ const hooks = [
'onShow',
'onHide',
'onError',
'onPageNotFound',
'onThemeChange',
'onPageNotFound',
'onThemeChange',
'onUnhandledRejection'
];
function initEventChannel$1 () {
Vue.prototype.getOpenerEventChannel = function () {
if (!this.__eventChannel__) {
this.__eventChannel__ = new EventChannel();
}
return this.__eventChannel__
};
const callHook = Vue.prototype.__call_hook;
Vue.prototype.__call_hook = function (hook, args) {
if (hook === 'onLoad' && args && args.__id__) {
this.__eventChannel__ = getEventChannel(args.__id__);
delete args.__id__;
}
return callHook.call(this, hook, args)
};
}
function parseBaseApp (vm, {
mocks,
initRefs
}) {
initEventChannel$1();
if (vm.$options.store) {
Vue.prototype.$store = vm.$options.store;
}
......@@ -1558,20 +1576,6 @@ function parseApp (vm) {
}
function createApp (vm) {
Vue.prototype.getOpenerEventChannel = function () {
if (!this.__eventChannel__) {
this.__eventChannel__ = new EventChannel();
}
return this.__eventChannel__
};
const callHook = Vue.prototype.__call_hook;
Vue.prototype.__call_hook = function (hook, args) {
if (hook === 'onLoad' && args && args.__id__) {
this.__eventChannel__ = getEventChannel(args.__id__);
delete args.__id__;
}
return callHook.call(this, hook, args)
};
App(parseApp(vm));
return vm
}
......@@ -1823,6 +1827,27 @@ function createComponent (vueOptions) {
}
}
function createSubpackageApp (vm) {
const appOptions = parseApp(vm);
const app = getApp({
allowDefault: true
});
const globalData = app.globalData;
if (globalData) {
Object.keys(appOptions.globalData).forEach(name => {
if (!hasOwn(globalData, name)) {
globalData[name] = appOptions.globalData[name];
}
});
}
Object.keys(appOptions).forEach(name => {
if (!hasOwn(app, name)) {
app[name] = appOptions[name];
}
});
return vm
}
todos.forEach(todoApi => {
protocols[todoApi] = false;
});
......@@ -1902,8 +1927,9 @@ if (typeof Proxy !== 'undefined' && "quickapp-webview" !== 'app-plus') {
qa.createApp = createApp;
qa.createPage = createPage;
qa.createComponent = createComponent;
qa.createSubpackageApp = createSubpackageApp;
var uni$1 = uni;
export default uni$1;
export { createApp, createComponent, createPage };
export { createApp, createComponent, createPage, createSubpackageApp };
......@@ -36,7 +36,11 @@ function getProvides () {
}
if (process.env.UNI_USING_COMPONENTS) {
provides.createApp = [uniPath, 'createApp']
if (process.env.UNI_SUBPACKGE) {
provides.createApp = [uniPath, 'createSubpackageApp']
} else {
provides.createApp = [uniPath, 'createApp']
}
provides.createPage = [uniPath, 'createPage']
provides.createComponent = [uniPath, 'createComponent']
}
......
......@@ -26,7 +26,8 @@ import {
import createApp from './wrapper/create-app'
import createPage from './wrapper/create-page'
import createComponent from './wrapper/create-component'
import createComponent from './wrapper/create-component'
import createSubpackageApp from './wrapper/create-subpackage-app'
todos.forEach(todoApi => {
protocols[todoApi] = false
......@@ -114,11 +115,13 @@ if (__PLATFORM__ === 'app-plus') {
__GLOBAL__.createApp = createApp
__GLOBAL__.createPage = createPage
__GLOBAL__.createComponent = createComponent
__GLOBAL__.createSubpackageApp = createSubpackageApp
export {
createApp,
createPage,
createComponent
createComponent,
createSubpackageApp
}
export default uni
import Vue from 'vue'
import 'uni-platform/runtime/index'
import EventChannel from 'uni-helpers/EventChannel'
import parseApp from 'uni-platform/runtime/wrapper/app-parser'
import {
getEventChannel
} from 'uni-helpers/navigate-to'
export default function createApp (vm) {
Vue.prototype.getOpenerEventChannel = function () {
// 微信小程序使用自身getOpenerEventChannel
if (__PLATFORM__ === 'mp-weixin') {
return this.$scope.getOpenerEventChannel()
}
if (!this.__eventChannel__) {
this.__eventChannel__ = new EventChannel()
}
return this.__eventChannel__
}
const callHook = Vue.prototype.__call_hook
Vue.prototype.__call_hook = function (hook, args) {
if (hook === 'onLoad' && args && args.__id__) {
this.__eventChannel__ = getEventChannel(args.__id__)
delete args.__id__
}
return callHook.call(this, hook, args)
}
App(parseApp(vm))
return vm
}
}
import 'uni-platform/runtime/index'
import {
hasOwn
} from 'uni-shared'
import parseApp from 'uni-platform/runtime/wrapper/app-parser'
export default function createSubpackageApp (vm) {
const appOptions = parseApp(vm)
const app = getApp({
allowDefault: true
})
const globalData = app.globalData
if (globalData) {
Object.keys(appOptions.globalData).forEach(name => {
if (!hasOwn(globalData, name)) {
globalData[name] = appOptions.globalData[name]
}
})
}
Object.keys(appOptions).forEach(name => {
if (!hasOwn(app, name)) {
app[name] = appOptions[name]
}
})
return vm
}
......@@ -5,19 +5,47 @@ import {
initMocks
} from 'uni-wrapper/util'
import EventChannel from 'uni-helpers/EventChannel'
import {
getEventChannel
} from 'uni-helpers/navigate-to'
const hooks = [
'onShow',
'onHide',
'onError',
'onPageNotFound',
'onThemeChange',
'onPageNotFound',
'onThemeChange',
'onUnhandledRejection'
]
function initEventChannel () {
Vue.prototype.getOpenerEventChannel = function () {
// 微信小程序使用自身getOpenerEventChannel
if (__PLATFORM__ === 'mp-weixin') {
return this.$scope.getOpenerEventChannel()
}
if (!this.__eventChannel__) {
this.__eventChannel__ = new EventChannel()
}
return this.__eventChannel__
}
const callHook = Vue.prototype.__call_hook
Vue.prototype.__call_hook = function (hook, args) {
if (hook === 'onLoad' && args && args.__id__) {
this.__eventChannel__ = getEventChannel(args.__id__)
delete args.__id__
}
return callHook.call(this, hook, args)
}
}
export default function parseBaseApp (vm, {
mocks,
initRefs
}) {
initEventChannel()
if (vm.$options.store) {
Vue.prototype.$store = vm.$options.store
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册