Last active
February 18, 2016 15:46
-
-
Save Ahrengot/a601aff04e6889db7608 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import Promise from 'promise' | |
export const loadPolyfills = () => { | |
return new Promise((resolve) => { | |
let promises = [] | |
if ( !global.fetch ) { | |
promises.push(new Promise((subResolve) => { | |
require(['whatwg-fetch'], subResolve) | |
})) | |
} | |
if ( !Object.assign ) { | |
promises.push(new Promise((subResolve) => { | |
require(['./object-assign-polyfill'], subResolve) | |
})) | |
} | |
if ( promises.length ) { | |
Promise.all(promises).then(resolve) | |
} else { | |
resolve() | |
} | |
}); | |
} | |
/* | |
Elsewhere in your app: | |
const renderApp = () => { | |
// Render your application | |
} | |
import { loadPolyfills } from './polyfill-loader' | |
loadPolyfills().then(renderApp); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment