-
Notifications
You must be signed in to change notification settings - Fork 303
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
Support for promises #126
Comments
Yes! Promises highly needed! |
I made a quick and dirty wrapper to make const promisifyPrompt = (title, description, defaultValue) => new Promise((resolve, reject) => {
alertify.prompt(
title,
description,
defaultValue,
(e, value) => resolve(value),
reject
);
}); You can use it like: promisifyPrompt(title, description, defaultValue)
.then(
value => {/* success handler */},
err => {/* error handler */}
); or promisifyPrompt(title, description, defaultValue)
.then(value => {/* success handler */})
.catch(err => {/* error handler */}) |
Thanks @juliepanda If you need the event, simply resolve a result promisifyPrompt('title', 'description', 'defaultValue')
.then(({e, value}) => {/* success handler */})
.catch(err => {/* error handler */}) |
Just thought this would help someone. I took a little different approach. Now the below is using a confirm dialog box. It is also using import * as alertify from 'alertifyjs';
export enum ConfirmResult {
Ok = 1,
Cancel
}
export function promisifyConfirm(title: string, message: string, options = {}): Promise<ConfirmResult> {
return new Promise<ConfirmResult>((resolve) => {
alertify.confirm(
title,
message,
() => resolve(ConfirmResult.Ok),
() => resolve(ConfirmResult.Cancel)).set(Object.assign({}, {
closableByDimmer: false,
defaultFocus: 'cancel',
frameless: false,
closable: false
}, options));
});
} Now using promisifyConfirm: async myFunction() {
const confirmResult = await promisifyConfirm('My title', 'My message');
// confirmResult wil be ConfirmResult.Ok for Ok and ConfirmResult.Cancel for Cancel
} |
It would be nice if .confirm() and .prompt() could return a promise instead of having to provide callbacks.
The text was updated successfully, but these errors were encountered: