(
eventSuffix: TEvent,
payload: TEventMap[TEvent],
)
| 191 | } |
| 192 | } |
| 193 | emit<TEvent extends keyof TEventMap & string>( |
| 194 | eventSuffix: TEvent, |
| 195 | payload: TEventMap[TEvent], |
| 196 | ) { |
| 197 | if (!this.#enabled) { |
| 198 | this.debugLog( |
| 199 | 'Event bus client is disabled, not emitting event', |
| 200 | eventSuffix, |
| 201 | payload, |
| 202 | ) |
| 203 | return |
| 204 | } |
| 205 | if (this.#internalEventTarget) { |
| 206 | this.debugLog( |
| 207 | 'Emitting event to internal event target', |
| 208 | eventSuffix, |
| 209 | payload, |
| 210 | ) |
| 211 | this.#internalEventTarget.dispatchEvent( |
| 212 | new CustomEvent(`${this.#pluginId}:${eventSuffix}`, { |
| 213 | detail: this.createEventPayload(eventSuffix, payload), |
| 214 | }), |
| 215 | ) |
| 216 | } |
| 217 | |
| 218 | if (this.#failedToConnect) { |
| 219 | this.debugLog('Previously failed to connect, not emitting to bus') |
| 220 | return |
| 221 | } |
| 222 | // wait to connect to the bus |
| 223 | if (!this.#connected) { |
| 224 | this.debugLog('Bus not available, will be pushed as soon as connected') |
| 225 | this.#queuedEvents.push(this.createEventPayload(eventSuffix, payload)) |
| 226 | // start connection to event bus |
| 227 | if (typeof CustomEvent !== 'undefined' && !this.#connecting) { |
| 228 | this.#connectFunction() |
| 229 | this.startConnectLoop() |
| 230 | } |
| 231 | return |
| 232 | } |
| 233 | // emit right now |
| 234 | return this.emitEventToBus(this.createEventPayload(eventSuffix, payload)) |
| 235 | } |
| 236 | |
| 237 | on<TEvent extends keyof TEventMap & string>( |
| 238 | eventSuffix: TEvent, |
no test coverage detected