Skip to content

Commit

Permalink
refactor(ChannelSelectMenu): better handling of channel_types state
Browse files Browse the repository at this point in the history
  • Loading branch information
didinele committed Nov 1, 2022
1 parent 92ec4ad commit 62f5240
Showing 1 changed file with 3 additions and 4 deletions.
Expand Up @@ -29,23 +29,22 @@ export class ChannelSelectMenuBuilder extends BaseSelectMenuBuilder<APIChannelSe
* ```
*/
public constructor(data?: Partial<APIChannelSelectComponent>) {
const { channel_types = [], ...initData } = data ?? {};
super({ ...initData, type: ComponentType.ChannelSelect, channel_types });
super({ ...data, type: ComponentType.ChannelSelect });
}

public addChannelTypes(...types: RestOrArray<ChannelType>) {
// eslint-disable-next-line no-param-reassign
types = normalizeArray(types);

this.data.channel_types?.push(...channelTypesValidator.parse(types));
(this.data.channel_types ??= []).push(...channelTypesValidator.parse(types));
return this;
}

public setChannelTypes(...types: RestOrArray<ChannelType>) {
// eslint-disable-next-line no-param-reassign
types = normalizeArray(types);

this.data.channel_types?.splice(0, this.data.channel_types.length, ...channelTypesValidator.parse(types));
(this.data.channel_types ??= []).splice(0, this.data.channel_types.length, ...channelTypesValidator.parse(types));
return this;
}

Expand Down

0 comments on commit 62f5240

Please sign in to comment.