mirror of
https://github.com/immich-app/immich.git
synced 2026-03-01 18:19:10 +03:00
feat: add onMany to BaseEventManager (#25492)
Use a map of events instead of array of tuples for better ergonomics.
This commit is contained in:
@@ -30,6 +30,17 @@ export class BaseEventManager<Events extends EventMap> {
|
||||
};
|
||||
}
|
||||
|
||||
onMany(subscriptions: { [T in keyof Events]?: EventCallback<Events, T> }) {
|
||||
const cleanups = Object.entries(subscriptions).map(([event, callback]) =>
|
||||
this.on(event as keyof Events, callback as EventCallback<Events, keyof Events>),
|
||||
);
|
||||
return () => {
|
||||
for (const cleanup of cleanups) {
|
||||
cleanup();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
emit<T extends keyof Events>(event: T, ...params: Events[T]) {
|
||||
const listeners = this.getListeners(event);
|
||||
for (const listener of listeners) {
|
||||
|
||||
Reference in New Issue
Block a user