Skip to content

Commit

Permalink
Use Object.assign instead of Reflect.set
Browse files Browse the repository at this point in the history
  • Loading branch information
JstnMcBrd committed Jun 23, 2024
1 parent f1cb8a6 commit edb60f4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/commands/CommandHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class CommandHandler extends SlashCommandBuilder {
* @param id The new ID to use
*/
public setId(id: Snowflake): this {
Reflect.set(this, 'id', id);
Object.assign(this, { id });
return this;
}

Expand Down
16 changes: 1 addition & 15 deletions src/events/EventHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,13 @@ export class EventHandler<K extends keyof ClientEvents = keyof ClientEvents> {
this.name = name;
}

/**
* Unnecessary because the name is set in the constructor and defines the generic class type.
* Unsafe because the generic type should never change, so the name should never change.
*/
// /**
// * Sets the name of the event this handler is for.
// *
// * @param name The name to use
// */
// public setName (name: K): this {
// Reflect.set(this, 'name', name);
// return this;
// }

/**
* Sets whether this event can only fire once.
*
* @param once Whether this event can only fire once
*/
public setOnce(once: boolean): this {
Reflect.set(this, 'once', once);
Object.assign(this, { once });
return this;
}

Expand Down
8 changes: 4 additions & 4 deletions src/events/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import { ready } from './ready.js';
/** The list of all event handlers. */
const eventHandlers = new Map<string, EventHandler>();

addEventHandler(error as EventHandler);
addEventHandler(interactionCreate as EventHandler);
addEventHandler(messageCreate as EventHandler);
addEventHandler(ready as EventHandler);
addEventHandler(error);
addEventHandler(interactionCreate);
addEventHandler(messageCreate);
addEventHandler(ready);

/**
* Add the given event handler to the list of event handlers.
Expand Down

0 comments on commit edb60f4

Please sign in to comment.