Skip to content

Conversation

bpolaszek
Copy link

@bpolaszek bpolaszek commented Jul 7, 2023

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().

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

Successfully merging this pull request may close these issues.

1 participant