Skip to content

Commit

Permalink
fix: allow events to be specified as symbols in waitForEvent (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
lithdew authored May 24, 2023
1 parent bf9aa2a commit 863a33b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ lib
es
yarn-error.log
.idea
.direnv
.envrc
14 changes: 7 additions & 7 deletions src/waitForEvent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {execute} from './execute';
import { execute } from './execute';

export type EventTargetLike<T> =
| EventTargetLike.HasEventTargetAddRemove<T>
Expand Down Expand Up @@ -28,7 +28,7 @@ export type EventTargetLike<T> =
export function waitForEvent<T>(
signal: AbortSignal,
target: EventTargetLike<T>,
eventName: string,
eventName: string | symbol,
options?: EventTargetLike.EventListenerOptions,
): Promise<T> {
return execute<T>(signal, resolve => {
Expand Down Expand Up @@ -87,23 +87,23 @@ export namespace EventTargetLike {
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/847731ba1d7fa6db6b911c0e43aa0afe596e7723/types/jquery/misc.d.ts#L6395
export interface JQueryStyleEventEmitter<TContext, T> {
on: (
eventName: string,
eventName: string | symbol,
handler: (this: TContext, t: T, ...args: any[]) => any,
) => void;
off: (
eventName: string,
eventName: string | symbol,
handler: (this: TContext, t: T, ...args: any[]) => any,
) => void;
}

export interface HasEventTargetAddRemove<E> {
addEventListener(
type: string,
type: string | symbol,
listener: ((evt: E) => void) | null,
options?: boolean | AddEventListenerOptions,
): void;
removeEventListener(
type: string,
type: string | symbol,
listener: ((evt: E) => void) | null,
options?: EventListenerOptions | boolean,
): void;
Expand All @@ -123,7 +123,7 @@ export namespace EventTargetLike {

function listen<T>(
target: EventTargetLike<T>,
eventName: string,
eventName: string | symbol,
handler: (...args: any[]) => void,
options?: EventTargetLike.EventListenerOptions,
) {
Expand Down

0 comments on commit 863a33b

Please sign in to comment.