Skip to content

Conversation

@jonahsnider
Copy link

@jonahsnider jonahsnider commented Mar 15, 2021

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

In fact, implementing this revealed 2 non-compliant ShardingManager#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 the dependencies field of package.json.

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

@DevYukine
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants