I am trying to create something like this as below
export function f1(param1: string, param2: string) {
console.log('Hello', param1, param2);
}
export function f2(param3: string) {
console.log('world', param3);
}
interface Metadata {
functionName: string;
functionParams: any;
}
const testMap: Map<string, Metadata> = new Map<string, Metadata>([
['action1', {functionName: 'f1', functionParams: {param1: 'any', param2:'any1'}}],
['action2', {functionName: 'f2', functionParams: {param3: 'any2'}}]
])
So basically I want to call f1 or f2 function after reading it through a testMap. The idea is to store all action and their mappings against a function and execute actions in one go instead of creating multiple if and else statements.
Can somebody help I can achieve this ?
['action1', {functionName: f1, functionParams: ['any','any1']}]?