diff --git a/packages/cef/src/main.ts b/packages/cef/src/main.ts index e3e3e2c..552a9fd 100644 --- a/packages/cef/src/main.ts +++ b/packages/cef/src/main.ts @@ -215,7 +215,7 @@ export class Cef { return Cef.instances.get(pid + "_" + browserId); } static getInstances() { - return Cef.instances.values(); + return [...Cef.instances.values()]; } } diff --git a/packages/core/src/controllers/bus/index.ts b/packages/core/src/controllers/bus/index.ts index 0944d8a..e0ad16a 100644 --- a/packages/core/src/controllers/bus/index.ts +++ b/packages/core/src/controllers/bus/index.ts @@ -99,7 +99,9 @@ export function defineEvent(options: Options) { const pushedPos = length - 1; const off = () => { - const currentMiddlewares = eventBus.get(name) || []; + const currentMiddlewares = eventBus.get(name); + if (!currentMiddlewares) return; + const currentMaxPos = currentMiddlewares.length - 1; const endIdx = currentMaxPos < pushedPos ? currentMaxPos : pushedPos; @@ -111,6 +113,10 @@ export function defineEvent(options: Options) { } } + if (currentMiddlewares.length === 0) { + eventBus.delete(name); + } + return currentMiddlewares.length; }; @@ -120,7 +126,7 @@ export function defineEvent(options: Options) { const h = [pusher, trigger] as const; if (isNative) { - identifier && samp.registerEvent(name, identifier); + typeof identifier !== "undefined" && samp.registerEvent(name, identifier); samp.on(name, trigger); }