Created
February 16, 2016 17:31
-
-
Save HenrikJoreteg/be9a5672b35c6c13a552 to your computer and use it in GitHub Desktop.
Polyfill module with callback. Original idea credit: Ryan Florence
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
export default (cb) => { | |
ensurePromise(() => { | |
ensureFetch(cb) | |
}) | |
} | |
const ensurePromise = (cb) => { | |
if (typeof Promise === 'undefined') { | |
require.ensure([], (require) => { | |
require('imports?this=>window!es6-promise') | |
cb() | |
}) | |
} else { | |
cb() | |
} | |
} | |
const ensureFetch = (cb) => { | |
if (typeof fetch === 'undefined') { | |
require.ensure([], (require) => { | |
require('whatwg-fetch') | |
cb() | |
}) | |
} else { | |
cb() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment