-
Notifications
You must be signed in to change notification settings - Fork 30
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
Handling failed navigations #16
Comments
In continuation of our discussion on Navigation through the app history list, let me suggest an const enum NavigateFailureReason
{
NoError // entry was set successfully
, Error // navigate() threw an exception
, Cancelled // navigate() was cancelled
, InvalidHistoryEntry // non-existend key
, OutOfHistory // .back()/forward() beyond entry array
} |
I like 3) here - I think the Promise should reject in any case where the navigation did NOT occur as intended. So if your back is not possible, it didn't happen, and the Promise should reject. I do think that the rejection reason should be helpful and tell the caller WHY the navigation didn't occur (cancelled by the router, not possible given the stack, etc.) |
I'm working on this now. I don't think we'll distinguish between an invalid key passed to navigateTo(), and being unable to go back()/forward(), because they're basically the same: you're trying to go to an entry that doesn't exist. We can revisit that if there are strong use cases (e.g. example code based on a real application). |
There are a few cases where navigations can fail:
appHistory.back()
when the current entry is the 0th entryappHistory.forward()
when the current entry is the last entryappHistory.navigateTo(someKey)
wheresomeKey
is not the key of any entry in the list (e.g., it's one that's been permanently evicted, as discussed in this section; or, it's just a random string like"not-a-key"
)Currently the proposal indicates that (1)-(3) will have the promise immediately fulfill with
undefined
, in a way that's indistinguishable from a success. The proposal explains you can check after the fact as to whether the navigation actually worked:It's unclear whether the current proposal gives a good design. I think at least (3) should result in a rejected promise.
I'm less sure about (1) or (2). Possibilities include:
canGoBack
andcanGoForward
sugar from Adding sugar for current index/can go back/can go forward #6.)I don't have a strong opinion on which of these is best.
The text was updated successfully, but these errors were encountered: