-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
better fetch-browser that preserves original fetch if it was there
- Loading branch information
Showing
1 changed file
with
9 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |