-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(useStorageAsync): add onReady
option and Promise return
#4158
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but honestly, for the given use case, why not use the sync useStorage
? I'm approving this though since other functions (like useWebSocket
) supports similar callbacks as well.
For example, the capacitorStorage is asynchronous. And sometimes people may write their own storage adapter since useStorageAsync and useStorage allows custom storage interface as an argument. |
Co-authored-by: Robin <robin.kehl@singular-it.de>
onReady
option
Co-authored-by: Robin <robin.kehl@singular-it.de>
Co-authored-by: Robin <robin.kehl@singular-it.de>
I feel that exposing a It can be both: const accessToken = await useStorageAsync('access.token', '', SomeAsyncStorage) or const accessToken = useStorageAsync('access.token', '', SomeAsyncStorage)
accessToken.then(() => {
// ...
}) |
Maybe accessToken.ready.then() Some libraries use this way. |
So is there any update? Do we need to change to the new pattern? |
@antfu @OrbisK Sorry to bother but I think this function is required for peoples since there are some issues discussion about this feature. If wee need more changes, please leave some messages or a final decision so that I can modify the code. Currently there has no any workaround to solve the async initialize issue without this PR. |
It feels like using const { isFetching, error, data } = await useFetch(url) @asika32764 Sorry for the late reply. Would you be open to exploring how we could support something like this? |
I implemented the Promise to the return value. But I still keep const accessToken = useStorageAsync('access.token', '', SomeAsyncStorage, {
onReady(value) {
// ...
}
})
accessToken.value // Origin way, may be empty if storage not prepared
const resolvedToken = await accessToken
resolvedToken.value // Resolved, still needs a .value to get value |
onReady
optiononReady
option and Promise return
Before submitting the PR, please make sure you do the following
fixes #123
).Description
This PR is aim to solve the issue #2895
Currently,
useStorageAsync
is impossible to wait the first value loaded, sometimes when app initializing, if we must use the storage, we may get the default initial value since the async storage not prepared.This PR add an
onLoad
event to let developer can solve this problem by manually resolve promises in this callback.Additional context