RFC: Clear storage functionality
Do we need ability to clear storage in this library, or this is out-of-scope?
I see three possible cases:
- Clearing the whole storage, with or without affecting all persisted stores
- Clearing single key, with or without affecting store, persisted with this key
- Option to clear single key when un-persisting store (when we call a function, returned by
persistfunction)
Thoughts?
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
persistties store to singlelocalStoragekey, maybe we can add an option topersist?
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?
Second concert (behaviour on clearing the storage) was covered in #39 and released in version 6.0.0