Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions examples/demo/src/services/TooltipHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class TooltipHelper {
private static _instance: TooltipHelper;
private tooltips: Record<string, TooltipData> = {};
private initialized = false;
private initialization?: Promise<void>;

static getInstance(): TooltipHelper {
if (!TooltipHelper._instance) {
Expand All @@ -24,20 +25,25 @@ class TooltipHelper {
return TooltipHelper._instance;
}

async init(): Promise<void> {
init(): Promise<void> {
if (this.initialized) {
return;
return Promise.resolve();
}
try {
const response = await fetch(TOOLTIP_URL);
if (response.ok) {
const json = await response.json();
this.tooltips = json as Record<string, TooltipData>;
}
} catch {
// Tooltips are non-critical; silently ignore failures
if (!this.initialization) {
this.initialization = (async () => {
try {
const response = await fetch(TOOLTIP_URL);
if (!response.ok) return;
this.tooltips = (await response.json()) as Record<string, TooltipData>;
this.initialized = true;
} catch {
// Tooltips are non-critical; silently ignore failures and allow a retry.
}
})().finally(() => {
this.initialization = undefined;
});
}
this.initialized = true;
return this.initialization;
}

getTooltip(key: string): TooltipData | undefined {
Expand Down
Loading