alerty icon indicating copy to clipboard operation
alerty copied to clipboard

What about promise-based API?

Open naholyr opened this issue 7 years ago • 1 comments

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))
}

naholyr avatar Apr 13 '17 13:04 naholyr

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

undead25 avatar Apr 13 '17 19:04 undead25