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

Add the possibility of using a custom history implementation

Open meff34 opened this issue 4 years ago • 2 comments

Currently effector-storage/query uses global history and location implementations. There is bunch of people who uses custom history.

meff34 avatar Jul 23 '21 11:07 meff34

I've checked this module, as far as I understand, there are 3 different versions in the wild, 3x, 4x and 5x, they all have different API (3 and 4 a lot different), 5x is not compatible with native location/history...

Can you suggest, how do you see this, like propose API? Considering that effector-storage/query should be universal and supports different implementation with different API (maybe there are other different modules to work with history exists)?

yumauri avatar Jul 30 '21 09:07 yumauri

I have a project with router, backed by history package. I tried and this looks like completely possible to update query string with current adapter. method parameter accepts function with type

export type ChangeMethod = (
  params: URLSearchParams | string,
  erase?: boolean
) => void

So it is possible to define your own method, like this:

persist({
  store: $id,
  key: 'id',
  method: (params: URLSearchParams | string) =>
    history.push({ search: String(params) })
})

And it will work fine. I couldn't find a way to bypass history update listener though... But maybe this is fine in some cases, at least.

Also, this approach only covers writes to query string, but not reads, so I will not close this issue yet. But maybe it will be other new adapter in external package https://github.com/yumauri/effector-storage-extras.

yumauri avatar Jun 20 '23 15:06 yumauri