From abb7fc3d2c3b7a767bf26bc19dd4a16adc689339 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=B8=85?= Date: Wed, 3 Jul 2019 11:49:12 +0800 Subject: [PATCH] remove window as any (#4715) --- src/components/CopyBlock/index.tsx | 2 +- src/models/global.ts | 4 +- src/models/setting.ts | 65 ------------------------------ src/typings.d.ts | 16 ++++++++ 4 files changed, 19 insertions(+), 68 deletions(-) diff --git a/src/components/CopyBlock/index.tsx b/src/components/CopyBlock/index.tsx index 810e9c1d..ccdda639 100644 --- a/src/components/CopyBlock/index.tsx +++ b/src/components/CopyBlock/index.tsx @@ -20,7 +20,7 @@ const onBlockCopy = (label: string) => { return; } - const ga = window && (window as any).ga; + const ga = window && window.ga; if (ga) { ga('send', 'event', { eventCategory: 'block', diff --git a/src/models/global.ts b/src/models/global.ts index 0142139d..a12d3298 100644 --- a/src/models/global.ts +++ b/src/models/global.ts @@ -128,8 +128,8 @@ const GlobalModel: GlobalModelType = { setup({ history }): void { // Subscribe history(url) change, trigger `load` action if pathname is `/` history.listen(({ pathname, search }): void => { - if (typeof (window as any).ga !== 'undefined') { - (window as any).ga('send', 'pageview', pathname + search); + if (typeof window.ga !== 'undefined') { + window.ga('send', 'pageview', pathname + search); } }); }, diff --git a/src/models/setting.ts b/src/models/setting.ts index 860b9dd6..7209d9b5 100644 --- a/src/models/setting.ts +++ b/src/models/setting.ts @@ -20,71 +20,6 @@ const updateTheme = (newPrimaryColor?: string) => { } }; -/* -let lessNodesAppended: boolean; - -const updateTheme: (primaryColor?: string) => void = primaryColor => { - // Don't compile less in production! - // preview.pro.ant.design only do not use in your production; - // preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。 - if (ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION !== 'site') { - return; - } - // Determine if the component is remounted - if (!primaryColor) { - return; - } - const hideMessage = message.loading('正在编译主题!', 0); - function buildIt() { - if (!(window as any).less) { - console.log('no less'); - return; - } - setTimeout(() => { - (window as any).less - .modifyVars({ - '@primary-color': primaryColor, - }) - .then(() => { - hideMessage(); - return true; - }) - .catch(() => { - message.error('Failed to update theme'); - hideMessage(); - }); - }, 200); - } - if (!lessNodesAppended) { - // insert less.js and color.less - const lessStyleNode = document.createElement('link'); - const lessConfigNode = document.createElement('script'); - const lessScriptNode = document.createElement('script'); - lessStyleNode.setAttribute('rel', 'stylesheet/less'); - lessStyleNode.setAttribute('href', '/color.less'); - lessConfigNode.innerHTML = ` - window.less = { - async: true, - env: 'production', - javascriptEnabled: true - }; - `; - lessScriptNode.src = 'https://gw.alipayobjects.com/os/lib/less.js/3.8.1/less.min.js'; - lessScriptNode.async = true; - lessScriptNode.onload = () => { - buildIt(); - lessScriptNode.onload = null; - }; - document.body.appendChild(lessStyleNode); - document.body.appendChild(lessConfigNode); - document.body.appendChild(lessScriptNode); - lessNodesAppended = true; - } else { - buildIt(); - } -}; -*/ - const updateColorWeak: (colorWeak: boolean) => void = colorWeak => { const root = document.getElementById('root'); if (root) { diff --git a/src/typings.d.ts b/src/typings.d.ts index 1815fe62..e1ae4ed5 100644 --- a/src/typings.d.ts +++ b/src/typings.d.ts @@ -20,6 +20,22 @@ declare module 'nzh/cn'; declare module 'webpack-theme-color-replacer'; declare module 'webpack-theme-color-replacer/client'; +// google analytics interface +interface GAFieldsObject { + eventCategory: string; + eventAction: string; + eventLabel?: string; + eventValue?: number; + nonInteraction?: boolean; +} +interface Window { + ga: ( + command: 'send', + hitType: 'event' | 'pageview', + fieldsObject: GAFieldsObject | string, + ) => void; +} + declare let ga: Function; // preview.pro.ant.design only do not use in your production ;