cache autocomplete elements

This commit is contained in:
LenAnderson
2024-04-25 18:02:06 -04:00
parent 12a2f54095
commit e531da615e

View File

@ -35,21 +35,12 @@ export class SlashCommand {
/**@type {SlashCommandNamedArgument[]}*/ namedArgumentList = [];
/**@type {SlashCommandArgument[]}*/ unnamedArgumentList = [];
get helpStringFormatted() {
let aliases = '';
if (this.aliases?.length > 0) {
aliases = ' (alias: ';
aliases += this.aliases
.map(it=>`<span class="monospace">/${it}</span>`)
.join(', ')
;
aliases += ')';
}
return `<span class="monospace">/${this.name}</span> ${this.helpString}${aliases}`;
}
/**@type {Object.<string, HTMLElement>}*/ helpCache = {};
/**@type {Object.<string, DocumentFragment>}*/ helpDetailsCache = {};
renderHelpItem(key = null) {
key = key ?? this.name;
if (!this.helpCache[key]) {
const typeIcon = '/';
const li = document.createElement('li'); {
li.classList.add('item');
@ -189,12 +180,15 @@ export class SlashCommand {
}
}
}
return li;
this.helpCache[key] = li;
}
return this.helpCache[key];
}
renderHelpDetails(key = null) {
const frag = document.createDocumentFragment();
key = key ?? this.name;
if (!this.helpDetailsCache[key]) {
const frag = document.createDocumentFragment();
const cmd = this;
const namedArguments = cmd.namedArgumentList ?? [];
const unnamedArguments = cmd.unnamedArgumentList ?? [];
@ -358,6 +352,8 @@ export class SlashCommand {
frag.append(aliases);
}
}
return frag;
this.helpDetailsCache[key] = frag;
}
return this.helpDetailsCache[key].cloneNode(true);
}
}