fix: 解决首页需要登录才能看到元素
This commit is contained in:
@@ -117,10 +117,7 @@ class EventBus {
|
||||
// 如果 allowAsyncHandlerRun 为 true,在每个监听器执行后调用 defaultAsyncHandler
|
||||
// 如果 allowAsyncHandlerRun 为 false,不调用 defaultAsyncHandler
|
||||
// 注意:如果 allowAsyncHandlerRun 为 false,defaultAsyncHandler 不会被调用,也不会等待其 resolve
|
||||
// 定义一个设置每个监听器执行后,是否都要调用 defaultAsyncHandler
|
||||
// 如果 callDefaultAsyncHandlerAfterEachListener 为 true,每个监听器执行后都调用 defaultAsyncHandler
|
||||
// 如果 callDefaultAsyncHandlerAfterEachListener 为 false,只在所有监听器执行完毕后调用 defaultAsyncHandler
|
||||
async emit(eventName, data, defaultAsyncHandler, { allowContinuePropagation = true, stopOnError = false, allowAsyncHandlerRun = true, callDefaultAsyncHandlerAfterEachListener = false } = {}) {
|
||||
async emit(eventName, data, defaultAsyncHandler, { allowContinuePropagation = true, stopOnError = false, allowAsyncHandlerRun = true } = {}) {
|
||||
// 先创建事件对象,方便传入 defaultAsyncHandler
|
||||
const event = this.createEvent(eventName, data)
|
||||
|
||||
@@ -149,23 +146,14 @@ class EventBus {
|
||||
)
|
||||
|
||||
// 调用 defaultAsyncHandler(仅当允许)
|
||||
await callDefaultAsyncHandler(event, null, domResult ?? true)
|
||||
await callDefaultAsyncHandler(event, null, domResult)
|
||||
|
||||
// 如果不允许继续传播,则直接返回(根据 defaultPrevented 判断结果)
|
||||
if (!allowContinuePropagation) {
|
||||
return !event.defaultPrevented
|
||||
}
|
||||
// 否则继续走普通 EventBus 处理(fallthrough)
|
||||
} else if (this.platform === 'h5') {
|
||||
// 调用 defaultAsyncHandler(仅当允许)
|
||||
await callDefaultAsyncHandler(event, null, true)
|
||||
|
||||
// 如果不允许继续传播,则直接返回(根据 defaultPrevented 判断结果)
|
||||
if (!allowContinuePropagation) {
|
||||
return !event.defaultPrevented
|
||||
}
|
||||
// 否则继续走普通 EventBus 处理(fallthrough)
|
||||
}
|
||||
}
|
||||
|
||||
// 普通 EventBus 触发
|
||||
const handlers = this.events.get(eventName)
|
||||
@@ -202,17 +190,10 @@ class EventBus {
|
||||
}
|
||||
|
||||
// 在每个监听器执行后,如果允许并且提供了 defaultAsyncHandler,就调用并等待它
|
||||
if (callDefaultAsyncHandlerAfterEachListener && allowAsyncHandlerRun) {
|
||||
await callDefaultAsyncHandler(event, handler, awaitedResult)
|
||||
}
|
||||
console.log('==> callDefaultAsyncHandler', {event, handler, awaitedResult})
|
||||
await callDefaultAsyncHandler(event, handler, awaitedResult)
|
||||
} catch (error) {
|
||||
console.error(`EventBus ${eventName} error:`, error)
|
||||
|
||||
// 发现错误,默认调用 defaultAsyncHandler(仅当允许)
|
||||
if (allowAsyncHandlerRun && callDefaultAsyncHandlerAfterEachListener) {
|
||||
await callDefaultAsyncHandler(event, handler, true)
|
||||
}
|
||||
|
||||
// 如果全局或该 handler 指定遇错停止传播,则停止
|
||||
if (stopOnError || handler.options?.stopOnError) {
|
||||
break
|
||||
@@ -226,11 +207,6 @@ class EventBus {
|
||||
}
|
||||
}
|
||||
|
||||
// 如果 callDefaultAsyncHandlerAfterEachListener 为 false,只在所有监听器执行完毕后调用 defaultAsyncHandler
|
||||
if (!callDefaultAsyncHandlerAfterEachListener && allowAsyncHandlerRun) {
|
||||
await callDefaultAsyncHandler(event, null, true)
|
||||
}
|
||||
|
||||
return !event.defaultPrevented
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user