A modern Svelte binding library for Gun.js with full Svelte 5 compatibility.
npm install svelte-as-gun
import { GunStore } from "https://deno.land/x/svelte_as_gun/mod.ts";
<script>
import { GunStore } from 'svelte-as-gun';
import Gun from 'gun';
const gun = new Gun();
// Create a reactive store from Gun data
const nameStore = new GunStore(gun.get('profile').get('name'));
// Subscribe to changes
$: name = $nameStore;
// Update Gun data
function updateName() {
nameStore.set('New Name');
}
</script>
<input type="text" bind:value={$nameStore} />
<button on:click={updateName}>Update</button>
<script>
import { useGun } from 'svelte-as-gun';
import Gun from 'gun';
const gun = new Gun();
// Create a reactive state variable from Gun data
const { value: name } = useGun(gun.get('profile').get('name'));
</script>
<input type="text" bind:value={name} />
<script>
import { gun, gunList } from 'svelte-as-gun';
import Gun from 'gun';
const gun = new Gun();
const users = gun.get('users');
</script>
<!-- Simple binding -->
<input type="text" use:gun={gun.get('profile').get('name')} />
<!-- List binding with template -->
<ul use:gunList={users}>
<li data-gun-template="true">
<span name="name">User name</span>
<input type="text" name="email" placeholder="Email" />
</li>
</ul>
GunStore<T>(gunChain, options?)
: Create a Svelte store from a Gun chaincreateGunStore<T>(gunChain, options?)
: Type-safe factory functionuseGun<T>(gunChain, options?)
: Create a reactive state from a Gun chaingun
: Action for binding Gun data to HTML elementsgunList
: Action for handling collections of Gun data itemsMIT