Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(event-emitter)!: add typed EventEmitter, remove legacy events
- Loading branch information
Showing
9 changed files
with
76 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright (c) | ||
* Weyoss <weyoss@protonmail.com> | ||
* https://github.com/weyoss | ||
* | ||
* This source code is licensed under the MIT license found in the LICENSE file | ||
* in the root directory of this source tree. | ||
*/ | ||
|
||
import { EventEmitter as Base } from 'events'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export type TEventEmitterEvent = Record<string | symbol, (...args: any) => any>; // type-coverage:ignore-line | ||
|
||
export declare interface EventEmitter<Events extends TEventEmitterEvent> | ||
extends Base { | ||
on<E extends keyof Events>(event: E, listener: Events[E]): this; | ||
once<E extends keyof Events>(event: E, listener: Events[E]): this; | ||
emit<E extends keyof Events>( | ||
event: E, | ||
...args: Parameters<Events[E]> | ||
): boolean; | ||
removeAllListeners<E extends keyof Events>(event?: E): this; | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging | ||
export class EventEmitter< | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
Events extends TEventEmitterEvent, | ||
> extends Base {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright (c) | ||
* Weyoss <weyoss@protonmail.com> | ||
* https://github.com/weyoss | ||
* | ||
* This source code is licensed under the MIT license found in the LICENSE file | ||
* in the root directory of this source tree. | ||
*/ | ||
|
||
export type TEvent = { | ||
error: (err: Error) => void; | ||
next: () => void; | ||
up: () => void; | ||
down: () => void; | ||
goingUp: () => void; | ||
goingDown: () => void; | ||
tick: () => void; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* Copyright (c) | ||
* Weyoss <weyoss@protonmail.com> | ||
* https://github.com/weyoss | ||
* | ||
* This source code is licensed under the MIT license found in the LICENSE file | ||
* in the root directory of this source tree. | ||
*/ | ||
|
||
export * from './event'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ | |
export * from './common'; | ||
export * from './redis'; | ||
export * from './logger'; | ||
export * from './event'; |