alerty
alerty copied to clipboard
What about promise-based API?
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))
}
That's awesome. I am ready to rewrite alerty using TypeScript and ES6. Also welcome your ideas and contribution.