Skip to content

armgit / papra

Public Imported from GitHub
0

The minimalistic document archiving platform.

refactor(client): allow async callbacks in hook system (#1189)

Corentin Thomasset9d1c64272d22
diff --git a/apps/papra-client/src/modules/shared/hooks/hooks.ts b/apps/papra-client/src/modules/shared/hooks/hooks.ts
index 9e119927..210d3574 100644
--- a/apps/papra-client/src/modules/shared/hooks/hooks.ts
+++ b/apps/papra-client/src/modules/shared/hooks/hooks.ts
@@ -1,10 +1,11 @@
export { createHook, createWaitForHook };
function createHook<T = any>() {
- let callbacks: ((args: T) => void)[] = [];
+ let callbacks: ((args: T) => void | Promise<void>)[] = [];
return {
on: (callback: (args: T) => void | Promise<void>) => callbacks.push(callback),
+ // oxlint-disable-next-line typescript/await-thenable
trigger: (args: T) => Promise.all(callbacks.map((callback) => callback(args))),
removeHandler: (callback: (args: T) => void) => {
callbacks = callbacks.filter((cb) => cb !== callback);