PersistedState: add remove to remove persisted state from storage#283
PersistedState: add remove to remove persisted state from storage#283ibilux wants to merge 3 commits intosvecosystem:mainfrom
remove to remove persisted state from storage#283Conversation
This add a `remove` function to remove persisted state from storage like `window.localstorage.removeitem`
🦋 Changeset detectedLatest commit: 8d3c5af 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 |
|
Maybe lets call it reset? |
I think |
| #version = $state(0); | ||
|
|
||
| constructor(key: string, initialValue: T, options: PersistedStateOptions<T> = {}) { | ||
| constructor(key: string, initialValue: T | null, options: PersistedStateOptions<T> = {}) { |
There was a problem hiding this comment.
Why should it be potentially null? Shouldn't that be a part of T?
There was a problem hiding this comment.
The removeItem() method of the Storage interface sets the item to null when it's removed. So if the user chooses a null value it won't be saved to the local storage (this is just a work around).
The #current: T | undefined; is already typed as T | undefined i didn't want to use undefined and used null instead so it won't interfere with the current codebase.
|
Closing this in favor of the recent changes: #359. Thanks for the contribution! |
This add a
removefunction to remove persisted state from storage likewindow.localstorage.removeitemfor #208.If the
initialValueis set tonullthePersistedStatewill not create alocalstorageitem. Ex:If the
PersistedStateis removed thecurrentvalue will be set tonull. Ex: