-
Notifications
You must be signed in to change notification settings - Fork 7
Async computed getter #22
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
base: master
Are you sure you want to change the base?
Async computed getter #22
Conversation
On hold while applying this to my own codebase |
Thank you for putting so much thought into this @boukeversteegh. At first glance, the only thing that i find potentially confusing is the naming of the asyncComputed() helper method. It has the same name as the @AsyncComputed decorator as well as the $asyncComputed object containing the async state and doesn't really describe what it is doing. It really is unwrapping the promise, so perhaps rename to asyncUnwrap() ? |
I've added a vue-async-computed-decorator/package.json Lines 7 to 14 in 0f529b5
This is needed because otherwise
You can try out this fork as follows:
Installing from github is slow, it may take a few minutes! |
You're welcome. It was a long-standing issue for my own project as well, so I felt like finally getting to the bottom of it. I understand your point that the name is not very clear. It's behavior is also a bit unusual, so it's hard to find a good name for it. It has a dual purpose:
In some way, it is unwrapping, but only the type, and 'unwrap' suggests it does more than just casting. Perhaps I've also been experimenting with an alternative decorator that just synchronizes a In any case, this PR is ready for testing. I'm still testing it myself within a big refactor, so it may take a while. |
This PR adds support to use
@AsyncComputed()
on getter methods:This allows for greatly improved type-checking and IDE support for AsyncComputed.
Benefits:
this.user.name
and will not expectthis.user().name
as is the case now.Drawbacks:
await
is not allowed in getters, so you must use only.then
and.catch
To work around these limitations, I suggest the following helper method. It is not included, but it could be if approved.
This can be used as follows: