-
-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add PersistedState #113
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 41f9495 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
built with Refined Cloudflare Pages Action⚡ Cloudflare Pages Deployment
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Self-review notes:
- Maybe just rename to
Persisted
? Simpler and consistent with thesvelte-persisted-store
package naming - Maybe add a
reset()
method likesvelte-persisted-store
? Very much a nice-to-have addition useful for only a small set of use cases, with the trade-off that it comes with a small memory overhead of needing to store the initial state. Can ultimately be achieved without needing the explicit method either way. svelte-persisted-store
also contains the following optional props for error handling and data transformation that I omitted. Don't personally feel they are necessary, though they could easily be added in a later PR if desired.
onWriteError: (error) => {/* handle or rethrow */}, // Defaults to console.error with the error object
onParseError: (raw, error) => {/* handle or rethrow */}, // Defaults to console.error with the error object
beforeRead: (value) => {/* change value after serialization but before setting store to return value*/},
beforeWrite: (value) => {/* change value after writing to store, but before writing return value to local storage*/},
I haven't had a chance to give this a thorough review, but I love what I see. Regarding the name, I think For something like this, I wonder if we can take it a step further and accept a custom 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 |
@huntabyte thanks! Agree the adapter might be good for future extensibility, I've had a crack at it in this branch: #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 :) |
Going to give this a review this week, I promise @Not-Jayden! Thanks for your patience! |
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 😃 |
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