Skip to content

Commit

Permalink
prevent loop with event queue
Browse files Browse the repository at this point in the history
  • Loading branch information
SchroterQuentin committed Nov 22, 2023
1 parent da818b0 commit d849f9e
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions src/Bones.UI/core/eventQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ const schema: JSONSchemaType<WindowsMessage> = {
const bufferSize = 100;

export class EventQueue {
private static _instance: EventQueue;

private subscriptionCounter: number;
private messageCounter: number;
private buffer: string[];
Expand Down Expand Up @@ -53,17 +51,10 @@ export class EventQueue {
}

public publish(topic: string, payload: any): void {
_(this.subscribers)
.filter((s) => s.topic === topic || s.topic === "*")
.forEach((s) => {
try {
s.callback(topic, payload);
} catch (error) {
console.error(error);
}
});

if (window.top) {
this.publishInternal(topic, payload);

if (window.top && window.top !== window.self) {
this.messageCounter++;
const id = "remote_" + this.messageCounter;

Expand Down Expand Up @@ -98,6 +89,18 @@ export class EventQueue {
}
}

private publishInternal(topic: string, payload: any) {
_(this.subscribers)
.filter((s) => s.topic === topic || s.topic === "*")
.forEach((s) => {
try {
s.callback(topic, payload);
} catch (error) {
console.error(error);
}
});
}

private onWindowsMessage(event: MessageEvent) {
let data;

Expand All @@ -117,7 +120,7 @@ export class EventQueue {
return;
}

this.publish(data.topic, data.payload);
this.publishInternal(data.topic, data.payload);
}
}

Expand Down

0 comments on commit d849f9e

Please sign in to comment.