-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
addition/proposalNew features or enhancementsNew features or enhancementsneeds implementer interestMoving the issue forward requires implementers to express interestMoving the issue forward requires implementers to express interest
Description
What problem are you trying to solve?
Often, the flow of navigation evolves as the navigation goes along.
This is not well represented in the navigation API, where precommit handlers and post-commit handlers are separate and defined in advance:
navigateEvent.intercept({
precommitHandler,
handler
})The above API works well when those flows are separate, or if only one is needed. However, if the precommit and post-commit flows are intertwined, it's a bit awkward to use.
What solutions exist today?
It's possible to create a more integrated experience by using Promise.withResolvers():
navigation.addEventListener("navigate", async e => {
const commit = Promise.withResolvers();
const done = Promise.withResolvers();
event.intercept({
precommitHandler: () => commit.promise,
handler: () => done.promise
});
await do_precommit_stuff();
commit.resolve();
await do_post_commit_stuff();
done.resolve();
}How would you solve it?
Allow registering a new handler from within the precommit handler:
event.intercept({
precommitHandler: (controller) => {
do_precommit_stuff();
controller.addHandler(async() => {
await postcommit_stuff();
});
await do_more_precommit_stuff();
}
});This makes registering handlers during precommit more dynamic, and doesn't require wrapping everything.
Anything else?
No response
jakearchibald
Metadata
Metadata
Assignees
Labels
addition/proposalNew features or enhancementsNew features or enhancementsneeds implementer interestMoving the issue forward requires implementers to express interestMoving the issue forward requires implementers to express interest