Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/use-event-listener/use-event-listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ interface EventListenerOptions {
type EventLike<T extends Callback = Callback> =
| { Connect(callback: T): ConnectionLike }
| { connect(callback: T): ConnectionLike }
| { subscribe(callback: T): ConnectionLike };
| { subscribe(callback: T): ConnectionLike }
| ((callback: T) => ConnectionLike);

type ConnectionLike = { Disconnect(): void } | { disconnect(): void } | (() => void);

Expand All @@ -32,6 +33,8 @@ const connect = (event: EventLike, callback: Callback): ConnectionLike => {
}
});
return connection;
} else if (typeIs(event, "function")) {
return event(callback);
} else if ("Connect" in event) {
return event.Connect(callback);
} else if ("connect" in event) {
Expand Down