joshnuss / svelte-persisted-store

A Svelte store that persists to localStorage

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Remove the local storage item

zwz opened this issue · comments

commented

I expect the store have an API to remove the local storage item.

Have you considered just calling localStorage.removeItem(key)?

If the store provided a .remove() function, what would it's value be when the item has been removed?

Thinking further about this, I think it's not something this library should provide. Because this store is only useful if it is backed by local storage. If the user wants to remove the key from local storage, they shouldn't be keeping a reference to this store.

Example:

const myStore = writable('mykey', initial)

function remove() {
  // stop using the store
  myStore = null 

  // remove from local storage
  localStorage.removeItem('mykey')
}

Closing the issue for now, let me know if you have any further comments/suggestions.