Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

[Feat] Use type-safe EventEmitter interface#402

Open
jonahsnider wants to merge2 commits intoDevYukine:master
base:master
Choose a base branch
Loading
fromdice-discord:feat/typed-event-emitter

Conversation

jonahsnider
Copy link

@jonahsniderjonahsnider commentedMar 15, 2021
edited
Loading

This replaces theSharderEvents enum with an object type that maps event names to listener function signatures. In combination with theTypedEventEmitter interface from@pizzafox/util this means TypeScript users get automatic type-checking of their event listeners, and the library gets safe calls toemit.

In fact, implementing this revealed 2 non-compliantShardingManager#emit usages:

private_shardready(message:NodeMessage){
const{d:{ shardID}}=message.data;
this._debug(`Shard${shardID} became ready`);
this.manager.emit(SharderEvents.SHARD_READY,shardID);
}

private_shardreconnect(message:NodeMessage){
const{d:{ shardID}}=message.data;
this._debug(`Shard${shardID} tries to reconnect`);
this.manager.emit(SharderEvents.SHARD_RECONNECT,shardID);
}

Adding the dependency will slightly increase bundle size, even though it's just used at build-time for TypeScript users.The official recommendation is to list it in thedependencies field ofpackage.json.

In its current state this PR is a breaking change sinceSharderEvents is no longer an enum. This could easily be changed back to anenum and rename the new type to something likeSharderEventListeners.

@DevYukine
Copy link
Owner

This seems interesting, i will have a look on the weekend at it 👍

jonahsnider reacted with heart emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@jonahsnider@DevYukine

[8]ページ先頭

©2009-2025 Movatter.jp