@mathislair/mtbreactive-svelte
v0.1.0
Published
Svelte readable store on top of @mathislair/mtbreactive-client.
Maintainers
Readme
@mathislair/mtbreactive-svelte
Svelte readable store on top of @mathislair/mtbreactive-client. Returns a Readable<Row[]> that updates as snapshot/change frames arrive. Auto-unsubscribes from the server when the last Svelte subscriber detaches.
Install
npm install @mathislair/mtbreactive-svelte @mathislair/mtbreactive-clientUsage
// lib/client.ts
import { ReactiveClient } from '@mathislair/mtbreactive-client';
export const client = new ReactiveClient('ws://localhost:8080/ws');<script lang="ts">
import { reactiveStore } from '@mathislair/mtbreactive-svelte';
import { client } from '$lib/client';
export let roomId: number;
$: messages = reactiveStore<{ id: number; body: string }>(
client,
'message',
{ col: 'conversation_id', value: roomId },
);
</script>
{#each $messages as m (m.id)}
<div>{m.body}</div>
{/each}(The $: reactive declaration creates a fresh store when roomId changes — the previous one is auto-disposed when no longer referenced.)
Options
| Option | Purpose |
| ------------ | ------------------------------------------------------ |
| initial | Rows shown until the first frame arrives. |
| onError(c) | Notified when an error frame arrives. |
License
MIT
