Skip to content

Commit

Permalink
better fetch-browser that preserves original fetch if it was there
Browse files Browse the repository at this point in the history
  • Loading branch information
gobengo committed May 8, 2015
1 parent a1420e8 commit eca55a6
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions fetch-browser.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
// the whatwg-fetch polyfill installs the fetch() function
// on the global object (window or self)
//
// Return that as the export for use in Webpack, Browserify etc.
var fetchWasDefined = 'fetch' in global;
var originalGlobalFetch = global.fetch;

require('whatwg-fetch');
var globalFetch = fetch;
delete global.fetch;
module.exports = fetch;

module.exports = globalFetch;
if (fetchWasDefined) {
global.fetch = originalGlobalFetch;
} else {
delete global.fetch;
}

0 comments on commit eca55a6

Please sign in to comment.