fix: phase 9+10 refactoring

This commit is contained in:
2026-02-16 07:04:15 +01:00
parent e7c395e1bd
commit 4051fa9333
8 changed files with 295 additions and 128 deletions

View File

@@ -0,0 +1,27 @@
type ElectronOn = ((channel: string, callback: (...args: unknown[]) => void) => (() => void) | void) | undefined;
interface SubscribeTagEventsOptions {
includeUpdated?: boolean;
}
const BASE_TAG_EVENTS = ['tag:created', 'tag:deleted', 'tag:renamed', 'tags:merged'] as const;
export function subscribeToTagEvents(
on: ElectronOn,
callback: () => void,
options: SubscribeTagEventsOptions = {}
): () => void {
if (!on) {
return () => {};
}
const channels = options.includeUpdated
? [...BASE_TAG_EVENTS, 'tag:updated']
: BASE_TAG_EVENTS;
const unsubscribers = channels.map((channel) => on(channel, callback) || (() => {}));
return () => {
unsubscribers.forEach((unsubscribe) => unsubscribe());
};
}