Skip to content
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

fix(useIDBKeyval): incorrect value init set #2416

Merged
merged 1 commit into from Nov 13, 2022
Merged

fix(useIDBKeyval): incorrect value init set #2416

merged 1 commit into from Nov 13, 2022

Conversation

sun0day
Copy link
Member

@sun0day sun0day commented Nov 10, 2022

Description

useIDBKeyval has some problems in L58-L59. This PR purpose is to solve these problems below.

  • Only undefined and null rawInit should be ignored to set
  • Since set is an async method, it is unsafe without await(L65-L67 can't catch error when set error).

async function read() {
try {
const rawValue = await get<T>(key)
if (rawValue === undefined) {
if (rawInit)
set(key, rawInit)
}
else {
data.value = rawValue
}
}
catch (e) {
onError(e)
}
}
read()

Additional context

Unit test covered.


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@sun0day
Copy link
Member Author

sun0day commented Nov 10, 2022

@sxzz @antfu cc

@antfu antfu merged commit 1d8413d into main Nov 13, 2022
@antfu antfu deleted the fix/useIdbKeyval branch November 13, 2022 01:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants