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

Can let emit return a Promise array?please #635

Closed
LastHeaven opened this issue Jan 19, 2020 · 3 comments
Closed

Can let emit return a Promise array?please #635

LastHeaven opened this issue Jan 19, 2020 · 3 comments
Labels
✨ feature request New feature or request

Comments

@LastHeaven
Copy link

What problem does this feature solve?

That can do something after emit event。

What does the proposed API look like?

const loading = ref(false)
const onClick = async () =>  {
 // doSomething
  loading.value = false
  // emit event
  await Promise.all(emit('click'))
  // doSomething
  loading.value = false
}
@sqal
Copy link
Contributor

sqal commented Jan 19, 2020

A similar issue was reported in 2.x long time ago vuejs/vue#5443

however, emit in vue 3 works differently than $emit in 2.x. In vue 3, emit basically calls a prop which name starts with onXXX so emit('click') is equivalent to calling props.onClick(). As we can see in the source code emit currently doesn't return anything so you should probably try with calling the onClick prop directly:

await props.onClick()
// or
// Promise.all expects an array
await Promise.all([
  props.onClick()
])

@yyx990803
Copy link
Member

Now that I think about it, simply returning an array containing the values of all triggered handlers would make sense. It'd be best to submit an RFC for this though: https://github.com/vuejs/rfcs

@yyx990803
Copy link
Member

FYI this has been removed in 55566e8 (see commit message for details)

@github-actions github-actions bot locked and limited conversation to collaborators Nov 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
✨ feature request New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants