pikax / vue-composable

Vue composition-api composable components. i18n, validation, pagination, fetch, etc. +50 different composables
https://pikax.me/vue-composable/
MIT License
1.18k stars 64 forks source link

Feat/improved local and session storage #1003

Closed KrosFire closed 2 years ago

KrosFire commented 3 years ago

https://pikax.me/vue-composable/composable/storage/localStorage.html

In current documentation, remove function is described as an equivalent to storage.value = undefined, but it's false. When we set starage.value = undefined, this undefined is being stored in localStorage as 'undefined' (string), which lead to issues when reloading the app.

Another issue is when we pass a ref as a defaultValue (which is acceptable), then the ref itself (object) is saved into localStorage, rather that it's value.

There's also a thing that is missing for me personally and that is instant save into storage. Debounce is great but when I tried to use your library to store accessToken in localStorage I had an issue. In some requests the key was missing, so I believe that an option to fully sync storage with ref would be nice.

I also don't see any reason to provide setSync function in sessionStorage, when it's useless.

I've fixed those and few other things in this pull req

pikax commented 3 years ago

Thank you, sorry for the delay, tests failing on expect(storage1.value).toMatchObject(storage2.value);

KrosFire commented 3 years ago

I believe I've fixed tests. It was just typescript screaming about possible undefined.

KrosFire commented 3 years ago

@pikax Could you run pipeline once again?

KrosFire commented 3 years ago

@pikax I think test failed regardless of my changes and just needs a rerun