effector-storage icon indicating copy to clipboard operation
effector-storage copied to clipboard

RFC: Clear storage functionality

Open yumauri opened this issue 5 years ago • 2 comments

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 avatar Jan 30 '21 17:01 yumauri

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 avatar Aug 12 '21 19:08 yumauri

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

yumauri avatar Mar 18 '24 07:03 yumauri