Skip to content

Initial attempt of serializer for useIDBKeyval #4781

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

matthewjumpsoffbuildings
Copy link

@matthewjumpsoffbuildings matthewjumpsoffbuildings commented May 28, 2025

Description

Attempt to add serializer option to useIDBKeyval to bring it more in line with useStorage as per https://vueuse.org/core/useStorage/#custom-serialization

Closes #4780

@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. enhancement New feature or request labels May 28, 2025
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels May 28, 2025
@ilyaliao
Copy link
Member

ilyaliao commented Jun 4, 2025

Thank you for your PR. Can you add some tests for this feature to prevent future regressions?

Comment on lines +89 to +94
if (serializer) {
data.value = serializer.read(rawValue)
}
else {
data.value = rawValue
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we should do this via default serializer. Like:

Suggested change
if (serializer) {
data.value = serializer.read(rawValue)
}
else {
data.value = rawValue
}
data.value = serializer.read(rawValue)

and

  const {
    flush = 'pre',
    deep = true,
    shallow = false,
    onError = (e) => {
      console.error(e)
    },
    writeDefaults = true,
    serializer: {
      read: (val)=>val,
      write: (val)=>val, 
    }
  } = options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

useIDBKeyval | custom serialization as per useStorage
3 participants