rocicorp / replicache

Realtime Sync for Any Backend Stack
https://doc.replicache.dev
1.01k stars 37 forks source link

Svelte support #1015

Open aboodman opened 2 years ago

aboodman commented 2 years ago

Right now it is theoretically possible to use Replicache with svelte but not easy as there is no sample. It's also possible feature work is necessary to make it work well (for example, for Solid, we know that #1010 is required).

We should create a sample/quickstart for Svelte and make sure it works well.

csenio commented 1 year ago

Svelte has a small pitfall when the scan function isn't pure. Need to manually clean those up in a reactive statement like this:

    let unsub
    $: {
        unsub?.()
        unsub = rep.subscribe(tx => tx.scan({prefix: `users/${currentTeam}`}).values().toArray())
    }
    onDestroy(unsub)

The best abstraction I found was making a renderless component out of it and then using it like this:

<Rep
  prefix={`channels/${$activeTeam.id}`}
  onData={(data) => {
    // do whatever you want with the data
  }}
/>

There is an issue for it but it's closed: https://github.com/sveltejs/svelte/issues/5283