-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
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
[Suggestion] Wrapped "v-on" invokers should return internal result #7628
Comments
See #7465 |
@coolzjy Thanks for the response, but I think my issue is not regarding I am just saying that the expected return value for handlers in
and
should be exactly what the method |
I think this makes sense. The behaviour should be consistent. |
Thank you for this suggestion! I'm making a similar control and have spent all morning trying to figure out why I couldn't await an async event handler from |
@cypherix93 I'm facing the same problem, sorry for late to find your issue. vue/src/compiler/codegen/events.js Line 104 in 76fd45c
to return `function($event){return ${handler.value}}` // inline statement and same for the modifier one below vue/src/compiler/codegen/events.js Line 139 in 76fd45c
I love javascript because it is so easy to quickly feature the open source code and change it for my usage |
Closed via 0ebb0f3 |
What problem does this feature solve?
I am trying to implement a "loading button" component that internally keeps track of specified event handlers and changes state based on the resolution state of said handlers. Assuming that the event handler is a
function
that returns aPromise
, the button internally waits for the promise to resolve, shows loading state, and handles theresolve
/reject
accordingly.Approach
Inside the
PromiseButton
component, I am keeping track of the event handler that is passed in (let's say we only want to look for'click'
handlers).Inside the event handler of the internal button, I am wrapping this function, and change state something like:
And in the consumer I am using the
@click
binding like so:All this is fine and works as expected.
Problem
However, when I try to use the same component but I use an inline method handler (with an optional parameter):
Somehow I lose context of the
Promise
being returned. It was a curious issue, so I dug a bit deeper and I found the pain point to be inside the wrapper function of the inline handler:It's not returning the
Promise
returned by mysomeHandler
.What does the proposed API look like?
My suggestion is that it should return the result of the internal handler really, that's all. That way, regardless of how the handler is written, I can get context internally of what the result of the handler was.
It also makes sense to me that it wouldn't just swallow the returned value of the wrapped function:
I am thinking this should solve the problem I am having. Please advise if I am wrong regarding this, or I should take a different approach.
Thanks for your time.
P.S. I didn't get time yet to dive into the source of Vue, but I plan to do that, and fine the actual source of this problem in the code.
The text was updated successfully, but these errors were encountered: