Skip to content
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

Make module available without polyfill #46

Closed
qubyte opened this issue Dec 24, 2014 · 8 comments
Closed

Make module available without polyfill #46

qubyte opened this issue Dec 24, 2014 · 8 comments

Comments

@qubyte
Copy link

qubyte commented Dec 24, 2014

It would be nice to be able to require fetch without it being appended to window in a similar way to the es6-promise polyfill. If fetch can be assigned to a variable, then this means that when a broken or otherwise incompatible version of the fetch API become available in a browser, code that uses fetch won't break.

In other words:

// This fetch can be used as is.
var fetch = require('fetch');

// Do this only if you want to polyfill fetch on the window object.
fetch.polyfill();

I realise however that this breaks the existing API.

@josh
Copy link
Contributor

josh commented Dec 24, 2014

You might want to checkout
https://github.com/matthew-andrews/isomorphic-fetch

This library is just going to be a standard polyfill implementation.
On Tue, Dec 23, 2014 at 8:34 PM Mark S. Everitt notifications@github.com
wrote:

It would be nice to be able to require fetch without it being appended to
window in a similar way to the es6-promise polyfill. If fetch can be
assigned to a variable, then this means that when a broken or otherwise
incompatible version of the fetch API become available in a browser, code
that uses fetch won't break.


Reply to this email directly or view it on GitHub
#46.

@qubyte
Copy link
Author

qubyte commented Dec 24, 2014

That module just does the same as this one, but works in Node too. i.e. the behaviour in the browser is identical.

One last try to convince... doing this will allow your users to protect themselves from differences in implementation and changes in spec as browsers evolve.

Else, I can close (or please feel free to).

@qubyte
Copy link
Author

qubyte commented Dec 24, 2014

This is what I'm using at the moment. Seriously ugly, but has the behaviour I want: https://gist.github.com/qubyte/21cade5e28c924c48bc1

@schickling
Copy link

+1

@qubyte qubyte mentioned this issue Dec 29, 2014
@qubyte
Copy link
Author

qubyte commented Dec 29, 2014

I put that gist into a library. It has one potential showstopping problem though... It means that the brfs transform must be used globally. https://github.com/qubyte/fetch-ponyfill

@domenic
Copy link

domenic commented Dec 29, 2014

@qubyte you can specify transforms on a per-package basis (e.g. in your fetch-ponyfill package.json) to avoid the global-ness.

@qubyte
Copy link
Author

qubyte commented Dec 29, 2014

@domenic Wow. I really should have realised that. Thanks for the tip!

@josh
Copy link
Contributor

josh commented Jan 9, 2015

#9 (comment)

@josh josh closed this as completed Jan 9, 2015
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants