Skip to content

Commit

Permalink
Add full fallback settings when setting() is not defined (context)
Browse files Browse the repository at this point in the history
techniq committed Feb 12, 2024
1 parent 7190af0 commit 68f886e
Showing 2 changed files with 15 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/fifty-seals-hang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte-ux": patch
---

Do not require `settings()` to be defined
16 changes: 10 additions & 6 deletions packages/svelte-ux/src/lib/components/settings.ts
Original file line number Diff line number Diff line change
@@ -118,15 +118,19 @@ export function settings(settings: SettingsInput): Settings {
});
}

const FALLBACK_CONTEXT: Settings = {
currentTheme: createThemeStore({ light: ['light'], dark: ['dark'] }),
componentSettingsCache: {},
...createLocaleStores({}),
};

export function getSettings(): Settings {
// in a try/catch to be able to test wo svelte components
// in a try/catch to be able to test w/o svelte components

try {
return getContext<Settings>(settingsKey) ?? {};
return getContext<Settings>(settingsKey) ?? FALLBACK_CONTEXT;
} catch (error) {
return {
currentTheme: createThemeStore({ light: ['light'], dark: ['dark'] }),
componentSettingsCache: {},
};
return FALLBACK_CONTEXT;
}
}

0 comments on commit 68f886e

Please sign in to comment.