Skip to content

Commit

Permalink
Merge branch 'dev' into alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
zhetengbiji committed Feb 2, 2021
2 parents ad1362c + 2535ce7 commit 6251997
Show file tree
Hide file tree
Showing 14 changed files with 508 additions and 263 deletions.
222 changes: 124 additions & 98 deletions packages/uni-app-plus/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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;
});
Expand Down Expand Up @@ -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 };
60 changes: 43 additions & 17 deletions packages/uni-mp-alipay/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1904,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;
}
Expand Down Expand Up @@ -2316,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
}
Expand Down Expand Up @@ -2588,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;
});
Expand Down Expand Up @@ -2667,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 };
Loading

0 comments on commit 6251997

Please sign in to comment.