Skip to content

Commit eca55a6

Browse files
committed
better fetch-browser that preserves original fetch if it was there
1 parent a1420e8 commit eca55a6

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

fetch-browser.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
// the whatwg-fetch polyfill installs the fetch() function
22
// on the global object (window or self)
3-
//
4-
// Return that as the export for use in Webpack, Browserify etc.
3+
var fetchWasDefined = 'fetch' in global;
4+
var originalGlobalFetch = global.fetch;
5+
56
require('whatwg-fetch');
6-
var globalFetch = fetch;
7-
delete global.fetch;
7+
module.exports = fetch;
88

9-
module.exports = globalFetch;
9+
if (fetchWasDefined) {
10+
global.fetch = originalGlobalFetch;
11+
} else {
12+
delete global.fetch;
13+
}

0 commit comments

Comments
 (0)