svecosystem / runed

Magical utilities for your Svelte applications (WIP)
https://runed.dev
MIT License
387 stars 21 forks source link

feat: add PersistedState #113

Open Not-Jayden opened 4 weeks ago

Not-Jayden commented 4 weeks ago

Creates reactive state that is persisted and synced across sessions and browser tabs. Inspired by https://github.com/joshnuss/svelte-persisted-store

See docs: https://not-jayden-persisted-state.runed.pages.dev/docs/utilities/persisted-state

changeset-bot[bot] commented 4 weeks ago

🦋 Changeset detected

Latest commit: 41f949510d9628e9c1f7ee7a8bdcc362b8bf6229

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package | Name | Type | | ----- | ----- | | runed | Minor |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

github-actions[bot] commented 4 weeks ago
built with Refined Cloudflare Pages Action

âš¡ Cloudflare Pages Deployment

Name Status Preview Last Commit
runed ✅ Ready (View Log) Visit Preview 41f949510d9628e9c1f7ee7a8bdcc362b8bf6229
huntabyte commented 2 weeks ago

I haven't had a chance to give this a thorough review, but I love what I see.

Regarding the name, I think Persisted is cleaner, though I'll defer to the others if dropping the State makes what it does less obvious.

For something like this, I wonder if we can take it a step further and accept a custom Storage type rather than just the custom serializer/deserializer. We can include adapters for session and local storage out of the box while allowing users to BYOS any storage system they wish as long as it follows our Storage interface.

I'm currently imagining a situation where we could leverage this along with something like Supabase or any real-time DB to bind specific values. If something changes in the DB, it updates, and if something changes that value in the app, it updates the DB. Having a flexible StorageAdapter would be sick for something like this!

Not-Jayden commented 2 weeks ago

I haven't had a chance to give this a thorough review, but I love what I see.

Regarding the name, I think Persisted is cleaner, though I'll defer to the others if dropping the State makes what it does less obvious.

For something like this, I wonder if we can take it a step further and accept a custom Storage type rather than just the custom serializer/deserializer. We can include adapters for session and local storage out of the box while allowing users to BYOS any storage system they wish as long as it follows our Storage interface.

I'm currently imagining a situation where we could leverage this along with something like Supabase or any real-time DB to bind specific values. If something changes in the DB, it updates, and if something changes that value in the app, it updates the DB. Having a flexible StorageAdapter would be sick for something like this!

@huntabyte thanks! Agree the adapter might be good for future extensibility, I've had a crack at it in this branch: https://github.com/svecosystem/runed/pull/118

Seems to be working fine but will sanity check it over the weekend to be sure and update docs if all looks good. If you have any feedback in the meantime it would be appreciated to make sure I don't sink too much time into going the wrong direction :)

huntabyte commented 2 weeks ago

Going to give this a review this week, I promise @Not-Jayden!

Thanks for your patience!

huntabyte commented 1 week ago

Discussing the storage adapter PR with the other maintainers as we speak! Hopefully we can polish it and get this shipped sooner rather than later 😃