I suggest an API change to be able to reject the underlying promise of a dialog, by calling either resolveDialog() or rejectDialog() instead of closeDialog().
When rejectDialog() is invoked (when clicking on a cancel button, for instance), it rejects the underlying promise with a DismissedDialog error.
Useful when chaining dialogs, this allows turning this:
async function addBook() {
let book = await openBookNameDialog(BookNameDialog, {});
if (null === book) {
return;
}
book = await openBookISBNDialog(BookISBNDialog, {book});
if (null === book) {
return;
}
book = await openBookAuthorDialog(BookAuthorDialog, {book});
if (null === book) {
return;
}
books.add(book)
}
into this:
async function addBook() {
try {
let book = await openBookNameDialog(BookNameDialog, {});
book = await openBookISBNDialog(BookISBNDialog, {book});
book = await openBookAuthorDialog(BookAuthorDialog, {book});
books.add(book);
} catch (e) {
if (!(e instanceof DismissedDialog)) {
throw e;
}
}
}
I kept closeDialog() for BC - when you pass an Error into closeDialog(), it will internally call rejectDialog().
I suggest an API change to be able to reject the underlying promise of a dialog, by calling either
resolveDialog()
orrejectDialog()
instead ofcloseDialog()
.When
rejectDialog()
is invoked (when clicking on a cancel button, for instance), it rejects the underlying promise with aDismissedDialog
error.Useful when chaining dialogs, this allows turning this:
into this:
I kept
closeDialog()
for BC - when you pass anError
intocloseDialog()
, it will internally callrejectDialog()
.