-
Notifications
You must be signed in to change notification settings - Fork 3
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 replaceRoute api #10
base: master
Are you sure you want to change the base?
Conversation
@@ -6,6 +6,7 @@ | |||
* | |||
*/ | |||
|
|||
import historyPolyfill from 'html5-history-api'; |
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.
If you need to support old browsers, you could also load this separately and put it in the global namespace. Many users don't have to support old browsers so this would add extra weight.
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.
hmm, not sure i follow about the global namespace implementation? not sure how that would make the build smaller if were still requiring it in? Mind explaining in a little more detail?
And i just assumed since this library supports legacy browsers that new APIs should do the same. I think it would be inconsistent behavior if some APIs supported legacy browsers while others did not.
eg. setRoute vs. replaceRoute. setRoute supports older versions of IE but without the history polyfill, replaceRoute would only support up to IE 10 or 11 I think.
What do you think?
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.
not sure how that would make the build smaller if were still requiring it in?
It wouldn't make the build smaller for users that choose to include the polyfill, but it would make the build smaller for users who don't have to support these old browsers because they just won't include it. I don't like including a 10kb polyfill (minified) in my app that I don't even need. That would make Tarantino twice as big.
You're right in that Tarantino does support legacy browsers, but that is only for the hash-based router since basic support for that is already present in those browsers (albeit with some inconsistencies, which this library fixes).
Note that I'm also new to this library, so bear with me if I made any mistakes.
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.
Ah, I think I see what you're saying. Just to clarify and make sure we're on the same page, you want each individual project to require in the polyfill (if they need it) vs. tarantino doing it by default?
And then inside tarantino, it would either use the polyfill or default to the window.history.replaceState
or something of that sort correct?
eg.
replaceHash: function(s) {
if (window.historyPolyfill) {
window.historyPolyfill.replaceState({}, document.title, s);
} else {
window.history.replaceState({}, document.title, s);
}
this.fire();
return this;
}
Am I understanding this correctly? If I am, the only caveat is that we need to provide explicit instructions on how to inject the polyfill into the global namespace.
eg.
import historyPolyfill from 'html5-history-api;
// will not work and will trigger null pointer at window.history.replaceState
window.polyfill = historyPolyfill;
Thoughts?
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.
I'd recommend users to overwrite window.history
with the polyfill if the object is undefined
. The polyfill you found, html5-history-api, is spec compliant, so this wouldn't cause any issues. This is how most libraries handle polyfills now AFAIK.
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.
See my comment above.
Looks fine to me otherwise :). Could you also add tests? Only way to ensure someone (me) doesn't break it later! After that it's about good to go I think.
No description provided.