From eca55a6de757bd2f6347cc3593b950a4b8cdd1b6 Mon Sep 17 00:00:00 2001 From: Benjamin Goering Date: Thu, 7 May 2015 18:13:12 -0700 Subject: [PATCH] better fetch-browser that preserves original fetch if it was there --- fetch-browser.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/fetch-browser.js b/fetch-browser.js index 6f53df7..de9c9d9 100644 --- a/fetch-browser.js +++ b/fetch-browser.js @@ -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; +}