import { AppKernel } from "@scripts/app/AppKernel"; type StoreTarget = Record; type StoreMethod = (...args: unknown[]) => unknown; /** * 调用所有 Store 上存在的同名方法。 * 默认清空 Store 状态;可传入方法名及其参数执行其他批量操作。 */ export async function emitEvents(eventName = "clear", ...args: unknown[]): Promise { const tasks: Promise[] = []; 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") }