chore: review + lint

This commit is contained in:
Chi Vinh Le
2020-08-13 18:44:21 +02:00
parent 76a5450af7
commit d22c846993
6 changed files with 39 additions and 34 deletions
@@ -7,7 +7,7 @@ export default async function injectConditionalPolyfills() {
// Polyfill Intl.
let intlPromise = Promise.resolve();
if (!browser.supportsIntl) {
if (!browser.supports.intl) {
intlPromise = (async () => {
const IntlPolyfill = (await import("intl")).default;
Intl.NumberFormat = IntlPolyfill.NumberFormat;
@@ -17,24 +17,24 @@ export default async function injectConditionalPolyfills() {
}
pending.push(
intlPromise.then(() => {
if (!browser.supportsIntlPluralRules) {
if (!browser.supports.intlPluralRules) {
return import("fluent-intl-polyfill");
}
return;
})
);
// Polyfill Intersection Observer.
if (!browser.supportsIntersectionObserver) {
if (!browser.supports.intersectionObserver) {
pending.push(import("intersection-observer"));
}
if (!browser.supportsProxyObject) {
if (!browser.supports.proxyObject) {
pending.push(import("proxy-polyfill"));
}
if (!browser.supportsFetch) {
if (!browser.supports.fetch) {
pending.push(import("whatwg-fetch"));
}
if (!browser.supportsCSSVariables) {
if (!browser.supports.cssVariables) {
pending.push(polyfillCSSVars());
}
await Promise.all(pending);
@@ -6,7 +6,7 @@ import { getBrowserInfo } from "../lib/browserInfo";
* through new CSS.
*/
export default function polyfillCSSVars() {
if (!getBrowserInfo().supportsCSSVariables) {
if (!getBrowserInfo().supports.cssVariables) {
return import("css-vars-ponyfill").then((module) => module.default());
}
return Promise.resolve();
@@ -5,7 +5,7 @@ import { getBrowserInfo } from "../lib/browserInfo";
* This is only needed when we use the Intl Polyfill.
*/
export default async function polyfillIntlLocale(locales: string[]) {
if (!getBrowserInfo().supportsIntl) {
if (!getBrowserInfo().supports.intl) {
await Promise.all(
locales.map((locale) =>
import("intl/locale-data/jsonp/" + locale + ".js")
+21 -18
View File
@@ -5,12 +5,14 @@ export interface BrowserInfo {
ios: boolean;
msie: boolean;
mobile: boolean;
supportsCSSVariables: boolean;
supportsFetch: boolean;
supportsProxyObject: boolean;
supportsIntl: boolean;
supportsIntlPluralRules: boolean;
supportsIntersectionObserver: boolean;
supports: {
cssVariables: boolean;
fetch: boolean;
proxyObject: boolean;
intl: boolean;
intlPluralRules: boolean;
intersectionObserver: boolean;
};
}
let browserInfo: BrowserInfo | null = null;
@@ -24,18 +26,19 @@ export function getBrowserInfo(): BrowserInfo {
const version = Number.parseFloat(browser.getBrowserVersion());
browserInfo = {
version,
supportsIntl: typeof Intl !== "undefined",
supportsIntlPluralRules:
typeof Intl !== "undefined" && Boolean(Intl.PluralRules),
supportsProxyObject: Boolean(window.Proxy),
supportsCSSVariables:
window.CSS && CSS.supports("color", "var(--fake-var)"),
supportsFetch: Boolean(window.fetch),
supportsIntersectionObserver:
"IntersectionObserver" in window &&
"IntersectionObserverEntry" in window &&
"intersectionRatio" in
(window as any).IntersectionObserverEntry.prototype,
supports: {
intl: typeof Intl !== "undefined",
intlPluralRules:
typeof Intl !== "undefined" && Boolean(Intl.PluralRules),
proxyObject: Boolean(window.Proxy),
cssVariables: window.CSS && CSS.supports("color", "var(--fake-var)"),
fetch: Boolean(window.fetch),
intersectionObserver:
"IntersectionObserver" in window &&
"IntersectionObserverEntry" in window &&
"intersectionRatio" in
(window as any).IntersectionObserverEntry.prototype,
},
ios,
msie,
mobile,
@@ -56,7 +56,7 @@ const createProxy = <T = any>(
// IE11 does not have Proxy support and the polyfill only supports
// a subset of features under special circumstances.
// https://github.com/GoogleChrome/proxy-polyfill
if (!getBrowserInfo().supportsProxyObject) {
if (!getBrowserInfo().supports.proxyObject) {
target = recordSource;
delete proxy.ownKeys;
delete proxy.getOwnPropertyDescriptor;
@@ -96,13 +96,15 @@ export default function createTestRenderer<
rest: new RestClient("http://localhost/api"),
postMessage: new PostMessageService(),
browserInfo: params.browserInfo || {
supportsCSSVariables: true,
supportsIntersectionObserver: true,
supportsFetch: true,
supportsIntl: true,
supportsIntlPluralRules: true,
supportsProxyObject: true,
version: "10.0",
supports: {
cssVariables: true,
intersectionObserver: true,
fetch: true,
intl: true,
intlPluralRules: true,
proxyObject: true,
},
version: 10.0,
ios: false,
mobile: false,
msie: false,