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

resolve化promise #16

Open
fisker opened this issue Oct 26, 2018 · 0 comments
Open

resolve化promise #16

fisker opened this issue Oct 26, 2018 · 0 comments

Comments

@fisker
Copy link
Owner

fisker commented Oct 26, 2018

在上一篇 promise化的confirm 应该总是 resolved 提到 confirm 的设计

那么对于已有的 resolve/reject 的设计,该怎么让函数永远返回 resolved 的 promise

花了点时间写了个库 p-resolvify

比如 Element-ui 的 confirm 我们就可以

Vue.prototype.$confirm = resolvify(Vue.prototype.$confirm)

或者

ELEMENT.MessageBox.confirm = resolvify(ELEMENT.MessageBox.confirm)

就可以

let result = await this.$confirm('确定?')

而不需要

let result

try {
   result = await this.$confirm('确定?')
} catch(err) {
  result = 'cancel'
}

https://jsfiddle.net/fisker/86qmcb72/8/

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

No branches or pull requests

1 participant