Skip to content

Commit

Permalink
fix(client): if no awaited event target, return
Browse files Browse the repository at this point in the history
  • Loading branch information
blakebyrnes committed Dec 8, 2022
1 parent 677ef1b commit 920f843
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions client/lib/AwaitedEventTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,19 @@ export default class AwaitedEventTarget<T> implements IAwaitedEventTarget<T> {
options?,
): Promise<void> {
const { target, jsPath } = await this.getEventTarget();
return (await target).addEventListener(jsPath, eventType as string, listenerFn as any, options);
const awaitedTarget = await target;
if (!awaitedTarget) return;
return awaitedTarget.addEventListener(jsPath, eventType as string, listenerFn as any, options);
}

public async removeEventListener<K extends keyof T>(
eventType: K,
listenerFn: T[K] & Function,
): Promise<void> {
const { target, jsPath } = await this.getEventTarget();
return (await target).removeEventListener(jsPath, eventType as string, listenerFn as any);
const awaitedTarget = await target;
if (!awaitedTarget) return;
return awaitedTarget.removeEventListener(jsPath, eventType as string, listenerFn as any);
}

// aliases
Expand Down

0 comments on commit 920f843

Please sign in to comment.