-
Notifications
You must be signed in to change notification settings - Fork 26
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
Add appHistory.transition with first-class rollback #90
Conversation
This gives insight into any "ongoing" navigation, i.e. a navigation that hasn't yet reached navigationsuccess/navigationerror because the promise passed to respondWith() has not yet settled. Additionally: * Removes the finished property from every AppHistoryEntry, which is nice because it only ever really made sense on the current entry; it was about the transition. Instead, the presence or nullness of appHistory.transition can be used. * Adds a type property to AppHistoryNavigateEvent since we're going to have it on appHistory.transition anyway so having it earlier (before respondWith() is called) seems very reasonable. Closes #86. Closes #11 by adding the appHistory.transition.finished promise. Helps with #41 as you can retrieve data from the replaced entry, at least during the transition, with appHistory.transition.previous. Probably helps with #14 (although currentchange needs a bit of an overhaul) since appHistory.transition has the sort of useful information discussed there, such as the previous entry or the type of navigation.
Yay bike-shedding:
|
README.md
Outdated
- `finished`: a promise which fulfills with undefined when the `navigatesuccess` event fires on `appHistory`, or rejects with the corresponding error when the `navigateerror` event fires on `appHistory` | ||
- `rollback()`: a promise-returning method which allows easy rollback to the `previous` entry | ||
|
||
Note that `appHistory.transition.rollback()` is not the same as `appHistory.back()`: for example, if the user goes back two steps, then `appHistory.rollback()` will actually go forward to steps. Similarly, it handles rolling back replace navigations by doing another replace back to the previous URL and app history state, and it rolls back push navigations by actually removing the entry that was previously pushed instead of leaving it there for the user to reach by pressing their forward button. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does rollback
trigger a navigate
event? I think it would be good to mention that here either way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, it does! Will mention.
"traverse" is definitely better than "traversal", so I've at least updated in that direction. I'm still willing to be swayed toward "go". I like "from" a good bit better than "previous" so I'll switch to that for now. It has the appropriate connotations of being "in the past" while also clearly conveying the direction. |
Pretty late to the party, but looking at implementing this and came across this question: For replace navigations, e.g. AppHistory.transtion.from === AppHistory.current // true? etc. [edit] oops sorry, forgot that we use |
If you call If so, what is the Should perhaps an additional |
I like the idea of
If I'm understanding this correctly, it means that if someone wants to call Additionally, since For example: try {
const navigationPromise = appHistory.navigate('/url')
// since there are two promises we have to handle, and since .transition is not created until we call .navigate()
// we have call .navigate() but not await it so we can then access .transition
await Promise.all([navigationPromise, appHistory.transition.finished])
catch(err){
// handle errors
} Or am I misunderstanding this completely? I could be wrong here. |
For some reason the unhandled promise reject function I setup in jest wasn't working, so it took forever to find. I'm not entirely sure I like how you have to handle errors like this, and left a comment WICG/navigation-api#90 (comment)
Yeah, I think that's the idea!
Correct.
Rolling back a traverse (e.g. -2) is done with a traverse (e.g. +2). Rolling back a replace is done by replacing (with the previous URL/state/etc. values). And rolling back a push is done with a traverse (-1).
Good catch. We'd mark the promise as handled (equivalent to immediately doing |
With the caveat that the rolled-back entry is removed, and you can no longer go forward as well - so, slightly different behavior than a normal (-1) traversal. Not sure if that’s an important enough distinction for developers to know about or not though.
Ah ok that sounds good. Thank you! |
This gives insight into any "ongoing" navigation, i.e. a navigation that hasn't yet reached navigationsuccess/navigationerror because the promise passed to respondWith() has not yet settled.
Additionally:
Closes #86. Closes #11 by adding the appHistory.transition.finished promise.
Helps with #41 as you can retrieve data from the replaced entry, at least during the transition, with appHistory.transition.previous.
Probably helps with #14 (although currentchange needs a bit of an overhaul) since appHistory.transition has the sort of useful information discussed there, such as the previous entry or the type of navigation.
I omitted the
initiated
timestamp for now because: (a) it's still unclear what we're doing with time measurement in general, per #33 and #59; (b) the "transition" was initiated when you calledrespondWith()
, and that seems a bit less useful than the time that the user clicked their mouse or the time when you didlocation.href
or whatever. Usually they'll be close, but especially with input lag not always...Potential bikeshed points I'd be happy to get feedback on:
appHistory.transition
vs.appHistory.ongoing
vs.appHistory.currentNavigation
vs. ..."traversal"
vs."go"
appHistory.transition.previous
vs.appHistory.transition.source
vs. ...