Skip to content
This repository has been archived by the owner on Oct 25, 2022. It is now read-only.

Commit

Permalink
feat(core): Track provisioned option IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
oliversalzburg committed Sep 25, 2022
1 parent dbf8fae commit 6ebc01a
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/userscript/source/ui/SettingsSectionUi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export abstract class SettingsSectionUi<TState> {
abstract setState(state: TState): void;
abstract refreshUi(): void;

private static _provisionedOptionElements = new Map<string, JQuery<HTMLElement>>();

/**
* Expands the options list if true, and collapses it if false.
* Changes the value of _itemsExpanded even if _mainChild is not defined.
Expand Down Expand Up @@ -346,6 +348,11 @@ export abstract class SettingsSectionUi<TState> {
onUnCheck?: () => void;
} = {}
): JQuery<HTMLElement> {
if (SettingsSectionUi._provisionedOptionElements.has(name)) {
throw new Error(
`Duplicate option ID requested! The option ID '${name}' has already been assigned to a previously provisoned element.`
);
}
const element = $("<li/>");
const elementLabel = `${upgradeIndicator ? `⮤ ` : ""}${i18nName}`;

Expand Down Expand Up @@ -387,6 +394,8 @@ export abstract class SettingsSectionUi<TState> {

element.append(input, label);

SettingsSectionUi._provisionedOptionElements.set(name, element);

return element;
}

Expand Down

0 comments on commit 6ebc01a

Please sign in to comment.