提交 8cb77614 编写于 作者: L liuxiaohang

fix(mp-toutiao): 修复 字节小程序$emit不触发 fixed #2774

上级 d5466f64
......@@ -192,7 +192,7 @@ function queue (hooks, data) {
}
if (res === false) {
return {
then () {}
then () { }
}
}
}
......@@ -272,16 +272,20 @@ const promiseInterceptor = {
if (!isPromise(res)) {
return res
}
return res.then(res => {
return res[1]
}).catch(res => {
return res[0]
return new Promise((resolve, reject) => {
res.then(res => {
if (res[0]) {
reject(res[0]);
} else {
resolve(res[1]);
}
});
})
}
};
const SYNC_API_RE =
/^\$|Window$|WindowStyle$|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/;
/^\$|Window$|WindowStyle$|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64|getLocale|setLocale/;
const CONTEXT_API_RE = /^create|Manager$/;
......@@ -1088,8 +1092,10 @@ function initTriggerEvent (mpInstance) {
}
function initHook (name, options, isComponent) {
{
// fix by Lxh 字节自定义组件Component构造器文档上写有created,但是实测只触发了lifetimes上的created
isComponent && (options = options.lifetimes)
isComponent && (options = options.lifetimes);
}
const oldHook = options[name];
if (!oldHook) {
options[name] = function () {
......
......@@ -24,7 +24,11 @@ function initTriggerEvent (mpInstance) {
}
}
function initHook (name, options) {
function initHook (name, options, isComponent) {
if (__PLATFORM__ === 'mp-toutiao') {
// fix by Lxh 字节自定义组件Component构造器文档上写有created,但是实测只触发了lifetimes上的created
isComponent && (options = options.lifetimes)
}
const oldHook = options[name]
if (!oldHook) {
options[name] = function () {
......@@ -46,7 +50,7 @@ if (!MPPage.__$wrappered) {
Page.after = MPPage.after
Component = function (options = {}) {
initHook('created', options)
initHook('created', options, true)
return MPComponent(options)
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册