atomic-server
atomic-server copied to clipboard
Svelte example is broken - store initialization does not work
this is from the docs:
// App.svelte
<script lang="ts">
import { initStore } from '@tomic/svelte';
import { Store } from '@tomic/lib';
onMount(() => {
// This is where you configure your atomic data store.
const store = new Store();
initStore(store);
});
</script>
// do sveltey things
But it errors, according to @AlexMikhalev
We do something completely different in the atomic-sveltekit-demo
:
import { get } from 'svelte/store';
import { initStore, store as atomicStore } from '@tomic/svelte';
import { Store } from '@tomic/lib';
import { currentSiteConfig } from '$lib/siteConfigs';
const init = () => {
const serverUrl = new URL(currentSiteConfig.siteResource);
serverUrl.pathname = '/';
const atomicStore = new Store({
serverUrl: serverUrl.toString(),
});
initStore(atomicStore);
};
export const getStore = () => {
let store = get(atomicStore);
if (store === undefined) {
init();
store = get(atomicStore);
}
return store;
};
We should update the svelte docs or better: fix the init code!
Perhaps we need an initSvelteKit
function?
But perhaps solving this before the runes refactor isn't the best idea.
Sample in a doc will be fine - I managed to get it working by adding code to main.ts and to App.svelte, I just don't know which code works.