state-adapt
state-adapt copied to clipboard
[FEATURE]: Svelte Support
Creating this issue to track progress and get feedback.
So far I see two potential ways to work with runes:
Option 1: Exposing getter properties
import { adapt } from '../state-adapt';
import { countAdapter } from './count.adapter';
const count = useAdapt(0, countAdapter);
count.double; // evaluated once
const triple = $derived(count.current * 3);
const quadruple = $derived(count.double * 2); // `double` selector
Option 2: Exposing plain functions
import { adapt } from '../state-adapt';
import { countAdapter } from './count.adapter';
const count = useAdapt(0, countAdapter);
count.double; // function that can be called anywhere for up-to-date values
const triple = $derived(count.state() * 3); // Original state selector name
const quadruple = $derived(count.double() * 2); // `double` selector
And I updated the Svelte starter example to include a component with this experiment: https://stackblitz.com/edit/vitejs-vite-szsd3d?file=src%2Flib%2FRuneCounter.svelte
No type-checking, and that's annoying. If anyone knows how to fix that, please comment.
Asking for feedback directly on X too https://x.com/mfpears/status/1936012137954213907
Option 1 seems more svelte
I think I'll do store in components, and adapt for stores you can import. It's similar to the createSubscriber functionality. I don't want eager subs so I need 2 ways to creates stores, and a way to activate the shared ones in components.