Skip to content

Commit 4c0446f

Browse files
authored
chore: fix side-effect issue caused by constructor trying to connect (#177)
1 parent 1b35177 commit 4c0446f

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

packages/event-bus-client/src/plugin.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,6 @@ export class EventClient<
7474
this.#connected = false
7575
this.#connectIntervalId = null
7676
this.#connectEveryMs = 500
77-
78-
if (typeof CustomEvent !== 'undefined') {
79-
this.#connectFunction()
80-
this.startConnectLoop()
81-
}
8277
}
8378

8479
private startConnectLoop() {
@@ -188,11 +183,17 @@ export class EventClient<
188183
// wait to connect to the bus
189184
if (!this.#connected) {
190185
this.debugLog('Bus not available, will be pushed as soon as connected')
191-
return this.#queuedEvents.push({
186+
this.#queuedEvents.push({
192187
type: `${this.#pluginId}:${eventSuffix}`,
193188
payload,
194189
pluginId: this.#pluginId,
195190
})
191+
// start connection to event bus
192+
if (typeof CustomEvent !== 'undefined') {
193+
this.#connectFunction()
194+
this.startConnectLoop()
195+
}
196+
return
196197
}
197198
// emit right now
198199
return this.emitEventToBus({

0 commit comments

Comments
 (0)