pinafore/src/routes/_utils/polyfills/loadPolyfills.js

32 wiersze
1006 B
JavaScript
Czysty Zwykły widok Historia

2018-01-28 00:31:26 +00:00
import {
importIntlListFormat,
importIntlLocale, importIntlPluralRules, importIntlRelativeTimeFormat,
importRequestIdleCallback
} from './asyncPolyfills'
2021-06-19 16:29:32 +00:00
import { mark, stop } from '../marks'
2018-01-28 00:31:26 +00:00
async function loadIntlPolyfillsIfNecessary () {
// Have to chain these so that they load in the proper order.
// Luckily these requests aren't done in serial, because we're using the same Webpack
// chunk name for each one.
if (typeof Intl.Locale !== 'function') {
await importIntlLocale()
}
if (typeof Intl.PluralRules !== 'function') {
await importIntlPluralRules()
}
await Promise.all([
typeof Intl.RelativeTimeFormat !== 'function' && importIntlRelativeTimeFormat(),
typeof Intl.ListFormat !== 'function' && importIntlListFormat()
])
}
2021-06-19 16:29:32 +00:00
export async function loadPolyfills () {
mark('loadPolyfills')
await Promise.all([
typeof requestIdleCallback !== 'function' && importRequestIdleCallback(),
loadIntlPolyfillsIfNecessary()
2018-01-28 00:31:26 +00:00
])
2021-06-19 16:29:32 +00:00
stop('loadPolyfills')
2018-02-09 06:29:29 +00:00
}