-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Update Histories #1376
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 #1376
Conversation
Awesome. I'm really looking forward to getting this merged, @taurose. Are you planning on merging as-is? Or is there more work you'd like to put in here? Not sure if you saw my comment on #1363... |
Working on it :) Some thoughts:
|
@mjackson Added a new commit for Also, I think the History classes would be a bit cleaner if all the listener setup happened in |
Not at all :) When we made the switch from providing a singleton to requiring users to instantiate a |
I completely agree. That's why I want the "before change" listener, so users can choose to cancel navigation if they want to. Hooking into "before unload" is just one time we need to trigger "before change". We also need to trigger "before change" every time we're about to push/replace programmatically in case the user wants to abort that transition. Are we doing that yet? |
I also think this work will be an initial step in fixing #1356. We'll need to split up running transition hooks into two stages: "will transition" and "did transition". All redirects need to happen in the "will transition" stage, so we don't call hooks that users intend to run after the transition has been made twice. |
Not sure about Redirects, but it sounds like most of what you mentioned covered. history.onBeforeChange((location, navigate) => {
if (!location) {
// it's the dom unload event, so we can only return a message sync
// (I guess this part could be more expressive, but I kept it simple for now)
return "Do you really want to leave?";
}
// note that for PUSH&REPLACE, location.state does not contain entry information
// from subclasses (like key)
doSomething(location, (err) => {
if (err) {
handleError(err);
// abort by not navigating
return;
}
// this will perform the actual navigation
// URL change and saving state will only happen at this point
// except for Browser&HashHistory POP (URL is changed before event)
var navigationResult = navigate();
if (!navigationResult) {
// navigation was superceded
}
});
}); Writing this down, I feel like we also need Also, do you think a separate |
@taurose Can we get the tests passing here? I'd like to merge ASAP! :) |
@mjackson They should pass.. Travis failed because of some license error, I have no idea what that's about 😄 |
Thanks @taurose. I'm looking through the code right now, going to try to get it merged soon. I'm having a bit of trouble following the logic in some places, but I think it's probably more due to my use of subclasses than your code :) I may try to simplify it a little. |
@mjackson Sure, go ahead :) Let me know if you have any questions. I'd also write some tests and documentation, but I wasn't sure if the new design and API is what you wanted to see. Also, I agree that using class hierarchies feels a bit off at this point. |
I wonder if we could clean things up using components instead of classes. A few things about these classes makes me think we could, namely:
There may be a few other benefits as well. Should we give it a shot? We had considered history components briefly in the |
@mjackson I don't think using components will help much. There's nothing React components can do that can't be done with plain JS, so I think we'd just limit ourselves. Ideally, it should be easy to create wrapper components though. I've done some testing for However, I've once again come to the conclusion that we can't provide We might be able to provide |
Thanks for investigating this @taurose. I apologize for the silence. I was in Paris last week and things got kind of busy :) I almost have a commit ready to push onto this branch. I agree w/ you that components won't help much, so I'm sticking with the classes. I have, however, tried to reduce the amount of indirection in the code. There are just a few questions I have about your work before I push.
As far as |
Sounds good 😃
It's for #826. HashHistory is unable to push the current path (
You mean simply not expose it? I'm not sure that's a good idea. I think it best answers the question of "Where am I?". It might be useful as a React key for transitions based on navigation, or for using a storage different from sessionStorage which we provide. That said, I'd actually prefer it as
Isn't window.confirm a bit limited? I personally wouldn't want to use it unless I had to (eg. with
You mean push? history.back could take you off the app after jumping to the first entry. |
Me too. Let's do it.
What I meant is they use
Great point. I'll just have to manually revert to the last known location in that case. @taurose In general I think the histories are complex enough that they actually deserve their own repo and package. I've been working on them quite a bit, and it's really starting to feel like I wish we had something decoupled from the router repo to work with. Would you be ok if we 1) merged this PR and then 2) created a new repo with your code + any additions I have? |
Sure. I think it's a good idea. Can't wait to see your changes. I'm not sure exactly where you're going with removing |
@taurose I've created a new repo to contain all the history stuff at https://github.com/rackt/history. This should help us separate the responsibilities a little more cleanly. The history package doesn't know/care about routing at all. |
See #1363 for previous discussion.