Skip to content

Commit

Permalink
fix(core, cef): registerEvent with empty string, off bus, cef instances
Browse files Browse the repository at this point in the history
  • Loading branch information
dockfries committed Oct 24, 2024
1 parent 49fc8ed commit f8faed7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/cef/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export class Cef {
return Cef.instances.get(pid + "_" + browserId);
}
static getInstances() {
return Cef.instances.values();
return [...Cef.instances.values()];
}
}

Expand Down
10 changes: 8 additions & 2 deletions packages/core/src/controllers/bus/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ export function defineEvent<T extends object>(options: Options<T>) {
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;
Expand All @@ -111,6 +113,10 @@ export function defineEvent<T extends object>(options: Options<T>) {
}
}

if (currentMiddlewares.length === 0) {
eventBus.delete(name);
}

return currentMiddlewares.length;
};

Expand All @@ -120,7 +126,7 @@ export function defineEvent<T extends object>(options: Options<T>) {
const h = [pusher, trigger] as const;

if (isNative) {
identifier && samp.registerEvent(name, identifier);
typeof identifier !== "undefined" && samp.registerEvent(name, identifier);
samp.on(name, trigger);
}

Expand Down

0 comments on commit f8faed7

Please sign in to comment.