From d22c8469934f3199fa06c87f66eb2d2d332c28c8 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Thu, 13 Aug 2020 18:44:21 +0200 Subject: [PATCH] chore: review + lint --- .../helpers/injectConditionalPolyfills.tsx | 12 +++--- .../framework/helpers/polyfillCSSVars.tsx | 2 +- .../framework/helpers/polyfillIntlLocale.tsx | 2 +- src/core/client/framework/lib/browserInfo.ts | 39 ++++++++++--------- src/core/client/framework/lib/relay/lookup.ts | 2 +- .../testHelpers/createTestRenderer.tsx | 16 ++++---- 6 files changed, 39 insertions(+), 34 deletions(-) diff --git a/src/core/client/framework/helpers/injectConditionalPolyfills.tsx b/src/core/client/framework/helpers/injectConditionalPolyfills.tsx index b64c2a898..f2b98e144 100644 --- a/src/core/client/framework/helpers/injectConditionalPolyfills.tsx +++ b/src/core/client/framework/helpers/injectConditionalPolyfills.tsx @@ -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); diff --git a/src/core/client/framework/helpers/polyfillCSSVars.tsx b/src/core/client/framework/helpers/polyfillCSSVars.tsx index fc9cd2e88..3fd3bf91c 100644 --- a/src/core/client/framework/helpers/polyfillCSSVars.tsx +++ b/src/core/client/framework/helpers/polyfillCSSVars.tsx @@ -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(); diff --git a/src/core/client/framework/helpers/polyfillIntlLocale.tsx b/src/core/client/framework/helpers/polyfillIntlLocale.tsx index 5eeffe740..b0086d7de 100644 --- a/src/core/client/framework/helpers/polyfillIntlLocale.tsx +++ b/src/core/client/framework/helpers/polyfillIntlLocale.tsx @@ -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") diff --git a/src/core/client/framework/lib/browserInfo.ts b/src/core/client/framework/lib/browserInfo.ts index d3e22fa2d..f15ba77f0 100644 --- a/src/core/client/framework/lib/browserInfo.ts +++ b/src/core/client/framework/lib/browserInfo.ts @@ -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, diff --git a/src/core/client/framework/lib/relay/lookup.ts b/src/core/client/framework/lib/relay/lookup.ts index b62a44fad..ec9b07b67 100644 --- a/src/core/client/framework/lib/relay/lookup.ts +++ b/src/core/client/framework/lib/relay/lookup.ts @@ -56,7 +56,7 @@ const createProxy = ( // 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; diff --git a/src/core/client/framework/testHelpers/createTestRenderer.tsx b/src/core/client/framework/testHelpers/createTestRenderer.tsx index ca1f8ae89..a0629e6bc 100644 --- a/src/core/client/framework/testHelpers/createTestRenderer.tsx +++ b/src/core/client/framework/testHelpers/createTestRenderer.tsx @@ -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,