Skip to content

Instantly share code, notes, and snippets.

@Ahrengot
Last active February 18, 2016 15:46
Show Gist options
  • Save Ahrengot/a601aff04e6889db7608 to your computer and use it in GitHub Desktop.
Save Ahrengot/a601aff04e6889db7608 to your computer and use it in GitHub Desktop.
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