Svelte integration RFC #276
Replies: 4 comments 4 replies
-
|
Okay, firstly, this is fantastic to see proposed. The spec and example code are clean, easy to understand, but I would stick to Svelte 5 rather than 4 unless you find it's easy enough to support both. Everything I do now is in Svelte 5 and TypeScript with the Bun runtime, so I am particularly interested. Building a community web portal that updates the UI in real-time right now via PostgreSQL's LISTEN/NOTIFY for backed stuff and Pocketbase for client-specific. Not really ideal. Site note: I am aiming to begin shipping all my SvelteKit applications as a compiled binary. Some dependencies break this ability, so I would like to also see if the proposed RFC if implemented, would work in this scenario as well. Not a deal break, but it would be nice. |
Beta Was this translation helpful? Give feedback.
-
|
OK so here's how I assume we could update this proposal to follow more of a rune-based pattern for Svelte v5. Instead of store factories, we'd provide hooks that return reactive values directly: Which you could then use like: Am I thinking about that right? One question that I would love the community to guide me on is... would we also need to provide v4 support? Or is everyone moving this way now? |
Beta Was this translation helpful? Give feedback.
-
|
my two cents: no need to provide Svelte 4 support. is tinybase normally a client or server/SSR package? sync/async? depending on the answers to those questions it could mean that you mat want to look into the new async svelte API |
Beta Was this translation helpful? Give feedback.
-
|
Have you considered a class based implementation like what ai-sdk had done with their Svelte module. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello everyone!
I'm proposing a new
ui-sveltemodule for TinyBase that would provide first-class Svelte integration, similar to how the existingui-reactmodule provides React integration. This would enable Svelte developers to build reactive, local-first applications with TinyBase using idiomatic Svelte patterns.Motivation
TinyBase currently has comprehensive React support through the
ui-reactmodule, which provides:However, Svelte is growing rapidly as a framework, particularly in the local-first and lightweight application space where TinyBase likes to live. Svelte's compile-time reactivity model and minimal runtime overhead make it a natural fit for TinyBase's philosophy of being tiny, fast, and developer-friendly.
Currently, Svelte developers can use TinyBase directly, but I suspect they miss out on the ergonomic, framework-specific bindings that make development smoother and more idiomatic.
Proposed Solution
I'd like to create a
ui-sveltemodule that adapts TinyBase's reactive capabilities to Svelte's reactivity model. The module would provide three main categories of functionality:1. Reactive Stores
Instead of React hooks, we'd provide factory functions that return Svelte readable/writable stores. These would automatically subscribe to TinyBase changes and clean up listeners on unsubscription.
Example - basic data access:
Usage in Svelte:
Example - more advanced features:
2. Writable Stores for Mutations
For two-way data binding (leveraging Svelte's
bind:directive):Usage:
3. Svelte Components
Pre-built components for declarative rendering:
Component hierarchy:
CellView,RowView,TableView,TablesViewValueView,ValuesViewResultCellView,ResultRowView,ResultTableViewSliceView,IndexViewLinkedRowsView,LocalRowsView,RemoteRowViewMetricViewCheckpointView,BackwardCheckpointsView,ForwardCheckpointsView4. Context Provider
Svelte's context API for dependency injection:
Usage:
Then in child components:
5. Action Creators
For callback-based mutations:
Usage:
6. Store Creation Utilities
Memoized store creation (similar to
useCreateStorein React):Advantages
Hopefully these things would give you some advantages over direct TinyBase usage in Svelte:
$reactive references andbind:directivesui-reactComparison: ui-react vs ui-svelte
useCell,useRow)cell,row).sveltecomponentsbind:directiveImplementation goals
TypeScript Support
I would hope we can provide full type definitions with:
Testing
Gotta keep the 100% test coverage record up! So...
Documentation
ui-reactOpen questions for you all
tinybaseCell) to avoid conflicts?ui-react-dom)?ui-svelte(core) andui-svelte-components(likeui-react-dom)?Community feedback requested!
This is a community RFC - I'm interested in feedback before committing to implementation. I'd love to hear from the community, especially:
Some specific questions:
Conclusion
A
ui-sveltemodule would bring TinyBase's powerful reactive data management to the Svelte ecosystem with idiomatic, ergonomic bindings. It would reduce boilerplate, improve developer experience, and leverage Svelte's compile-time reactivity for optimal performance.I believe this would be a valuable addition to TinyBase and would help grow adoption in the Svelte community, which aligns well with TinyBase's tiny and, er, svelte philosophies!
Looking forward to your thoughts and feedback.
Beta Was this translation helpful? Give feedback.
All reactions