Skip to content
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

RFC: Clear storage functionality #13

Open
yumauri opened this issue Jan 30, 2021 · 2 comments
Open

RFC: Clear storage functionality #13

yumauri opened this issue Jan 30, 2021 · 2 comments
Labels
help wanted Extra attention is needed rfc Request for comments

Comments

@yumauri
Copy link
Owner

yumauri commented Jan 30, 2021

Do we need ability to clear storage in this library, or this is out-of-scope?

I see three possible cases:

  1. Clearing the whole storage, with or without affecting all persisted stores
  2. Clearing single key, with or without affecting store, persisted with this key
  3. Option to clear single key when un-persisting store (when we call a function, returned by persist function)

Thoughts?

@yumauri yumauri added help wanted Extra attention is needed rfc Request for comments labels Jan 30, 2021
@yumauri
Copy link
Owner Author

yumauri commented Aug 12, 2021

Generally, I have two concerns:

1. API

How this should looks like?

  • Clear whole storage
    ¯\_(ツ)_/¯ Separate function, maybe? Or event?
import { clear } from 'effector-storage/local'

forward({
  from: clearButtonClicked,
  to: clear
})
  • Clear single key
    As long as persist ties store to single localStorage key, maybe we can add an option to persist?
import { persist } from 'effector-storage/local'

persist({
  store: $store,
  key: 'key',
  clear: clearButtonClicked
})

But I don't like inconsistency with the 1st point (clear whole localStorage) though, maybe this should be done using separate function/event as well?

import { clear } from 'effector-storage/local'

forward({
  from: clearButtonClicked,
  to: clear.prepend(() => 'key')
})

Should there be possibility to clear any key, or just ones, used previously in persist calls?

  • Clear single key when un-persisting
    Do we need this in the first place?
import { persist } from 'effector-storage/local'

const unpersist = persist({
  store: $store,
  key: 'key',
})

unpersist(true) // optional parameter to clear `localStorage` key?

2. Behaviour

What should happen on clearing localStorage?
Should persisted stores receive nulls? Or stay unchanged?
If this is to be two possible option — how this should looks like in API?
What should happen with persisted stores on the other browser tab?

@yumauri
Copy link
Owner Author

yumauri commented Mar 18, 2024

Second concert (behaviour on clearing the storage) was covered in #39 and released in version 6.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed rfc Request for comments
Projects
None yet
Development

No branches or pull requests

1 participant