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

What about promise-based API? #4

Open
naholyr opened this issue Apr 13, 2017 · 1 comment
Open

What about promise-based API? #4

naholyr opened this issue Apr 13, 2017 · 1 comment

Comments

@naholyr
Copy link

naholyr commented Apr 13, 2017

It's pretty much all in the title, how about this:

alerty.alert().then(onOk)

alerty.confirm().then(ok => ok ? onOk() : onCancel())
// or
alerty.confirm().then(onOk, onCancel)

alerty.prompt().then(onOk, onCancel)

alerty.toast().then(callback)

for backward compatibility it could be an addition, like a namespace alerty.promise, it's actually easy to implement:

alerty.promise = {
  alert: (...args) => new Promise(resolve => alerty.alert(...args, resolve)),
  confirm: (...args) => new Promise((resolve, reject) => alerty.confirm(...args, resolve, reject)),
  prompt: (...args) => new Promise((resolve, reject) => alerty.prompt(...args, resolve, reject)),
  toasts: (...args) => new Promise(resolve => alerty.toasts(...args, resolve))
}
@undead25
Copy link
Owner

That's awesome. I am ready to rewrite alerty using TypeScript and ES6. Also welcome your ideas and contribution.

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

2 participants