I am looking to develop a customizable macro item that can be edited by the user.
Each macro item will have a defined type and event value.
There are three types of items: pressKey, releaseKey, and delayInMs.
For pressKeyEvent and releaseKeyEvent, I want users to only be able to select a key object as the event value.
For delayEvent, users should only be able to select an integer as the event value.
Currently, this is what I have:
export enum MacroEventEnum {
pressKey,
releaseKey,
delayInMs
}
export class MacroItem {
// Represents the type of the macro event
public macroEvent: MacroEventEnum;
// Represents the value associated with the macro event
public macroEventValue: any;
constructor(macroEvent: MacroEventEnum, macroEventValue: any) {
this.macroEvent = macroEvent;
this.macroEventValue = macroEventValue;
}
}
The issue arises when the user changes the macroEvent type to pressKey but can still input a time as the macroEvent value.
What kind of design pattern would be most suitable in this scenario considering that the user can frequently change the macroEvent?
Thank you for your insights :)