summaryrefslogtreecommitdiff
path: root/packages/frontend/src/events.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/frontend/src/events.ts')
-rw-r--r--packages/frontend/src/events.ts19
1 files changed, 17 insertions, 2 deletions
diff --git a/packages/frontend/src/events.ts b/packages/frontend/src/events.ts
index dfd3d4120c..26b1881d15 100644
--- a/packages/frontend/src/events.ts
+++ b/packages/frontend/src/events.ts
@@ -5,9 +5,24 @@
import { EventEmitter } from 'eventemitter3';
import * as Misskey from 'misskey-js';
+import { onBeforeUnmount } from 'vue';
-export const globalEvents = new EventEmitter<{
+type Events = {
themeChanging: () => void;
themeChanged: () => void;
clientNotification: (notification: Misskey.entities.Notification) => void;
-}>();
+ notePosted: (note: Misskey.entities.Note) => void;
+ noteDeleted: (noteId: Misskey.entities.Note['id']) => void;
+};
+
+export const globalEvents = new EventEmitter<Events>();
+
+export function useGlobalEvent<T extends keyof Events>(
+ event: T,
+ callback: Events[T],
+): void {
+ globalEvents.on(event, callback);
+ onBeforeUnmount(() => {
+ globalEvents.off(event, callback);
+ });
+}