Packages
@lia-labs/sdk-svelte
Copy page
Svelte stores for the Lia SDK, for Svelte 4 and 5. Lia's state as stores, and buttons for a component's life.
npm install @lia-labs/sdk @lia-labs/sdk-svelteSvelte 4 or 5. Everything from @lia-labs/sdk is re-exported.
#An app
<script lang="ts">
import { initStore, isLia, mockLia, pay, ready, stores, useMainButton } from '@lia-labs/sdk-svelte';
if (!isLia()) mockLia();
const lia = initStore();
const { language, colorScheme } = stores;
$: if ($lia.status === 'ready') ready();
useMainButton({ text: 'Buy extra lives', onClick: () => pay('extra-lives') });
</script>
{#if $lia.status === 'ready'}
<h1>Hello, @{$lia.result.player.name} ({$language}, {$colorScheme})</h1>
{/if}#Stores and helpers
| Export | Gives you |
|---|---|
initStore(options?) | A store of { status, result, error } that calls init(). |
stores | Lia's state as stores: player, mode, language, rtl, colorScheme, themeParams, viewport, safeArea, contentSafeArea, isFullscreen, startParam, soundOn, notificationsAllowed, initialized. |
toStore(value) | Any SDK value as a store. |
useLiaEvent(event, handler) | Listens to one of Lia's events for the component's life; returns a stop function. |
useMainButton(options), useSecondaryButton(options) | Shows the button for the component's life. Returns { update(options), dispose() }. |
useBackButton(onBack), useSettingsButton(onOpen) | Shows the header button for the component's life. Returns { update, dispose }. |
useClosingConfirmation(), useVerticalSwipesDisabled() | For the component's life; return a function that ends it early. |
Call the use* helpers while a component is being set up so they end with it. Called anywhere else (an event handler, a module), they work the same but you call dispose() yourself:
let back: { dispose(): void } | null = null;
function openDetail() {
back = useBackButton(closeDetail);
}
function closeDetail() {
back?.dispose();
}