mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-12-26 18:09:40 +08:00
map lookup
This commit is contained in:
parent
dc494b8f8f
commit
0aaa7db094
1 changed files with 10 additions and 9 deletions
|
|
@ -367,11 +367,6 @@ export const commands: CommandsSubgroup = {
|
|||
],
|
||||
};
|
||||
|
||||
function findCommandById(key: string): Command | undefined {
|
||||
const id = "change" + key.charAt(0).toUpperCase() + key.slice(1);
|
||||
return commands.list.find((it) => it.id === id);
|
||||
}
|
||||
|
||||
const lists = {
|
||||
themes: ThemesCommands[0]?.subgroup,
|
||||
loadChallenge: LoadChallengeCommands[0]?.subgroup,
|
||||
|
|
@ -381,8 +376,14 @@ const lists = {
|
|||
resultSaving: ResultSavingCommands[0]?.subgroup,
|
||||
};
|
||||
|
||||
const subGroupByConfigKey = Object.fromEntries(
|
||||
commands.list
|
||||
.filter((it) => it.id.startsWith("change"))
|
||||
.map((it) => [it.id.slice("change".length).toLowerCase(), it.subgroup]),
|
||||
);
|
||||
|
||||
export function doesListExist(listName: string): boolean {
|
||||
if (findCommandById(listName)) {
|
||||
if (subGroupByConfigKey[listName] !== undefined) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -394,9 +395,9 @@ export async function getList(
|
|||
): Promise<CommandsSubgroup> {
|
||||
await Promise.allSettled([challengesPromise]);
|
||||
|
||||
const commandList = findCommandById(listName);
|
||||
if (commandList !== undefined && commandList.subgroup !== undefined) {
|
||||
return commandList.subgroup;
|
||||
const subGroup = subGroupByConfigKey[listName];
|
||||
if (subGroup !== undefined) {
|
||||
return subGroup;
|
||||
}
|
||||
|
||||
const list = lists[listName as ListsObjectKeys];
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue