⛹️♂️ Makes feature flag store only run once
This commit is contained in:
@@ -1,17 +1,20 @@
|
|||||||
import { api } from '$lib/api';
|
import { api } from '$lib/api';
|
||||||
import { notifications } from '$lib/components/toasts/notifications';
|
import { notifications } from '$lib/components/toasts/notifications';
|
||||||
import { onMount } from 'svelte';
|
import { writable, type Writable } from 'svelte/store';
|
||||||
import { writable } from 'svelte/store';
|
|
||||||
|
let featureFlagsStore: Writable<Record<string, boolean>>;
|
||||||
|
|
||||||
export function useFeatureFlags() {
|
export function useFeatureFlags() {
|
||||||
const featureFlags = writable<Record<string, boolean>>({});
|
if (!featureFlagsStore) {
|
||||||
onMount(async () => {
|
featureFlagsStore = writable<Record<string, boolean>>({});
|
||||||
const result = await api.get<Record<string, boolean>>('/api/features');
|
|
||||||
if (result.isOk()) featureFlags.set(result.inner);
|
api.get<Record<string, boolean>>('/api/features').then((result) => {
|
||||||
|
if (result.isOk()) featureFlagsStore.set(result.inner);
|
||||||
else {
|
else {
|
||||||
notifications.error('Feature flag could not fetched', 2500);
|
notifications.error('Feature flag could not be fetched', 2500);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
return featureFlags;
|
|
||||||
|
return featureFlagsStore;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user