| 123456789101112131415161718192021222324252627 |
- import { AppKernel } from "@scripts/app/AppKernel";
- type StoreTarget = Record<string, unknown>;
- type StoreMethod = (...args: unknown[]) => unknown;
- /**
- * 调用所有 Store 上存在的同名方法。
- * 默认清空 Store 状态;可传入方法名及其参数执行其他批量操作。
- */
- export async function emitEvents(eventName = "clear", ...args: unknown[]): Promise<void> {
- const tasks: Promise<unknown>[] = [];
- for (const target of Object.values(AppKernel.stores)) {
- if (!target || typeof target !== "object") continue;
- const method = (target as unknown as StoreTarget)[eventName];
- if (typeof method !== "function") continue;
- tasks.push(Promise.resolve((method as StoreMethod).apply(target, args)));
- }
- await Promise.all(tasks);
- }
- export async function onUserLogout() {
- return emitEvents("onUserLogout")
- }
|