Skip to content

Commit

Permalink
memoized suggester getItems() calls
Browse files Browse the repository at this point in the history
  • Loading branch information
valentine195 committed Jul 9, 2021
1 parent 85772ba commit 4b20912
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/utils/suggester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ abstract class SuggestionModal<T> extends FuzzySuggestModal<T> {
export class FileSuggestionModal extends SuggestionModal<TFile> {
file: TFile;
text: TextComponent;
files = this.app.vault.getMarkdownFiles();
constructor(app: App, input: TextComponent) {
super(app, input.inputEl);
this.text = input;
Expand Down Expand Up @@ -308,19 +309,21 @@ export class FileSuggestionModal extends SuggestionModal<TFile> {
});
}
getItems() {
return this.app.vault.getMarkdownFiles();
return this.files;
}
}

export class SRDMonsterSuggestionModal extends SuggestionModal<
Creature | SRDMonster
> {
creature: Creature | SRDMonster;
creatures: (Creature | SRDMonster)[];
constructor(public plugin: InitiativeTracker, inputEl: HTMLInputElement) {
super(plugin.app, inputEl);
this.creatures = [...this.plugin.players, ...this.plugin.bestiary];
}
getItems() {
return [...this.plugin.players, ...this.plugin.bestiary];
return this.creatures;
}
getItemText(item: Creature | SRDMonster) {
return item.name;
Expand Down Expand Up @@ -454,16 +457,18 @@ abstract class ElementSuggestionModal<T> extends FuzzySuggestModal<T> {

export class HomebrewMonsterSuggestionModal extends ElementSuggestionModal<HomebrewCreature> {
creature: HomebrewCreature;
homebrew: HomebrewCreature[];
constructor(
public plugin: InitiativeTracker,
inputEl: HTMLInputElement,
el: HTMLDivElement
) {
super(plugin.app, inputEl, el);
this.homebrew = [...this.plugin.data.homebrew];
this.onInputChanged();
}
getItems() {
return [...this.plugin.data.homebrew];
return this.homebrew;
}
getItemText(item: HomebrewCreature) {
return item.name;
Expand Down

0 comments on commit 4b20912

Please sign in to comment.