mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-09 15:39:24 +08:00
chore: api update
This commit is contained in:
parent
caedd9720e
commit
84d8ccf83b
@ -63,10 +63,21 @@ export class EventBus {
|
||||
return this.on(eventName, listener, { ...options, once: true });
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an event listener or all listeners for eventName
|
||||
*/
|
||||
off(eventName: string | string[], listener?: EventListener): void {
|
||||
if (Array.isArray(eventName)) {
|
||||
eventName.forEach((name) => this.singleOff(name, listener));
|
||||
} else {
|
||||
this.singleOff(eventName, listener);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an event listener or all listeners for an event
|
||||
*/
|
||||
off(eventName: string, listener?: EventListener): void {
|
||||
private singleOff(eventName: string, listener?: EventListener): void {
|
||||
// Check if this is a wildcard pattern
|
||||
const isWildcard = eventName.includes('*');
|
||||
const listenersMap = isWildcard ? this.patternListeners : this.listeners;
|
||||
@ -152,7 +163,7 @@ export class EventBus {
|
||||
listenersMap.get(eventName).push(registeredListener);
|
||||
|
||||
// Return unsubscribe function
|
||||
return () => this.off(eventName, listener);
|
||||
return () => this.singleOff(eventName, listener);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -211,7 +222,7 @@ export class EventBus {
|
||||
const result = listener(ctx);
|
||||
|
||||
// Handle async listeners
|
||||
if (result instanceof Promise) {
|
||||
if (result instanceof Promise && options.blocking) {
|
||||
await result;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user