-
-
Notifications
You must be signed in to change notification settings - Fork 366
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
Avoid use of globals where possible #74
Conversation
We still need URL and URLSearchParams until we stop testing on Node 8.
I like this approach, except for not using |
@sindresorhus I think this is ready to go, unless you notice anything else. Note that I included an unrelated fix for the Travis failures. It was still running Node 8. |
This is looking great! 👌 @sholladay Would you be interested in joining the project as a maintainer? You have done some really good PRs and you seem interested in the project. |
@sindresorhus Yes, would love to join. It's an awesome project. :) |
Yay. Welcome to the project! 🎉 |
Fixes #64
This is similar to PR #69, however I've taken a different approach. Some of my goals include:
fetch()
handle URL resolution where possible.ReferenceError
s by not accessing globals when we don't need them.global
,window
, andself
as not mutually exclusive.This should make things significantly easier in non-browser environments. In my testing on Node 10+, I was able to remove everything except for
fetch
andResponse
in test/_require.js and the test suite passed.Previously, Ky would find the global object and then assume everything lived on that object, which makes things cumbersome in non-DOM / no-browser environments. Now, we lookup each global we need in each namespace. So for example, in Node you don't have to implement all of
window
anymore. If you assign a fetch implementation towindow.fetch
but nothing else, Ky will still be able to findURL
in modern versions of Node where it lives onglobal
and you won't have to assign it manually - it will just work.Further, in all environments, globals are conditionally accessed to avoid unnecessary
ReferenceError
s. Ky also no longer relies on theHeaders
class.