Opens an overlay and returns a promise for its acceptance.
It's useful to think of overlays as promises which may either be fulfilled (accepted) or rejected (dismissed).
Instead of using up.layer.open()
and passing callbacks, you may use up.layer.ask()
.
up.layer.ask()
returns a promise for the acceptance value, which you can await
:
let user = await up.layer.ask({ url: '/users/new' })
console.log("New user is " + user)
To handle the case that the overlay wasn't completed successful, you
can catch
the rejected promise reason:
try {
let user = await up.layer.ask({ url: '/users/new' })
console.log("New user is", user)
} catch (reason) {
console.error("Could not register:", reason)
}
A promise that settles when the overlay closes.
When the overlay was accepted, the promise will fulfill with the overlay's acceptance value.
When the overlay was dismissed, the promise will reject with the overlay's dismissal reason.