-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Update Histories #1363
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
Update Histories #1363
Conversation
@taurose This is a most welcome PR, thank you! I'll review today. |
This looks great! Thank you! I think I'd prefer to omit I'm also thinking about the server-side API where we ask people to create their own serveApp(function (req, res) {
var location = new Location(req.url, req.query);
// ...
}); Does that make sense @taurose? |
Yeah, that makes sense now. I was a bit confused by not having I simply moved
The check also ensures that |
This looks great! One other thing I'd like to add to the histories is the ability to add a listener "before change". This would essentially be faking the functionality of I was adding this functionality earlier today before I saw this PR, but I stopped when I saw that you were changing a bunch of things to avoid conflicts. However, I really think we need it so we can use it to give users a chance to prevent transitions before they happen. I want to change all of the "will transition from" hooks to use this instead of using It may be out of scope for this PR, but I just thought I'd mention it while you're in that code. If you feel like adding this on, I'd really appreciate it. Since you wrote most of this code @taurose, you probably have the best idea where it could go. If you do add the functionality here, I can modify |
@taurose Also, if you do your work on a branch in the rackt Github org then I can potentially push to the same branch. That would make it a little easier to collaborate on stuff like this :) |
Also related: #1358 |
Moved it to this repo. See #1376. |
This PR attempts to fix/improve the current Histories in a couple of ways:
sessionStorage
based onkey
withBrowserHistory
as wellHashHistory
ignoring hashChange after transitioning to the same path that's currently activeWhile trying to do all those things, I felt like the History classes needed some refactoring. So
History
is now responsible for managing keys and state, and performing navigations.Subclasses now have to do the following:
push(path, key): entry
andreplace(path, key): entry
instead ofpushState
andreplaceState
. These should only apply the given path (and optionally key) to whatever they're working with, but not callthis._notifyChange
or setthis.location
this.location
and callingthis._notifyChange
themselves, they now have to callthis.handlePop(path, entry)
setup()
by callingsuper.setup(path, entry)
, after whichthis.location
can be safely readThe (optional)
entry
object will be merged intostate
, allowing subclasses to pass arbitrary information to the user based on the current entry. It's also used to signalHistory
thatkey
(and thusstate
) is supported. In the future, we could add additional props like that, such ascurrent
andlength
.Also, I had to change the scrolling test to include timeouts; otherwise, the hashchange event timings would have been off, I think. Not sure why I couldn't reproduce this with the old code (not exactly fun to debug 😄). Anyway, as far as I can tell, the scrolling didn't even work before and the test passed due to native browser scrolling (which is still the case..).
Let me know what you think; I'm also open to applying these changes to the old API if you don't agree with them.
@mjackson @ryanflorence @gaearon