From 55dac3b56baa13b8b66de746d2af5a2bd3b5c065 Mon Sep 17 00:00:00 2001 From: * <8> Date: Mon, 21 Mar 2022 17:50:18 +0800 Subject: [PATCH 1/2] Match-id-580af01343fa5bba627a04ab667a638ec280a603 --- libs/horizon/src/renderer/components/BaseClassComponent.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libs/horizon/src/renderer/components/BaseClassComponent.ts b/libs/horizon/src/renderer/components/BaseClassComponent.ts index 74f6df80..b5b202c2 100644 --- a/libs/horizon/src/renderer/components/BaseClassComponent.ts +++ b/libs/horizon/src/renderer/components/BaseClassComponent.ts @@ -1,18 +1,22 @@ /** * Component的api setState和forceUpdate在实例生成阶段实现 */ + class Component
{ props: P; context: C; state: S | null; refs: any; - setState: any; forceUpdate: any; constructor(props: P, context: C) { this.props = props; this.context = context; } + + setState(state: S) { + console.error('Cant not call `this.setState` in the constructor of class component, it will do nothing') + } } // 兼容三方件 react-lifecycles-compat,它会读取 isReactComponent 属性值,不添加会导致 eview-ui 官网白屏 From ea44e30933164f272d7411e6d6b637d220a9083c Mon Sep 17 00:00:00 2001 From: * <8> Date: Tue, 22 Mar 2022 10:26:15 +0800 Subject: [PATCH 2/2] Match-id-5935bd5d4b80a4524d2b9a839ca106c4249ad3e5 --- .eslintignore | 1 + .eslintrc.js | 5 +++++ libs/horizon/index.d.ts | 5 ++++- libs/horizon/src/renderer/components/BaseClassComponent.ts | 7 +++++-- tsconfig.json | 4 ++-- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/.eslintignore b/.eslintignore index 25439044..60feb237 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,2 +1,3 @@ **/node_modules build/ +*.d.ts diff --git a/.eslintrc.js b/.eslintrc.js index 79557bf5..46239631 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,6 +1,8 @@ module.exports = { extends: [ 'eslint:recommended', + "plugin:@typescript-eslint/eslint-recommended", + "plugin:@typescript-eslint/recommended", 'prettier', ], root: true, @@ -41,6 +43,9 @@ module.exports = { 'no-for-of-loops/no-for-of-loops': 'error', 'no-function-declare-after-return/no-function-declare-after-return': 'error', }, + globals: { + isDev: true + }, overrides: [ { files: [ diff --git a/libs/horizon/index.d.ts b/libs/horizon/index.d.ts index 4c54c7c5..bab6684d 100644 --- a/libs/horizon/index.d.ts +++ b/libs/horizon/index.d.ts @@ -1 +1,4 @@ -declare var isDev: any; +/* + 区分是否开发者模式 + */ +declare var isDev: boolean; diff --git a/libs/horizon/src/renderer/components/BaseClassComponent.ts b/libs/horizon/src/renderer/components/BaseClassComponent.ts index b5b202c2..c8fcf9a9 100644 --- a/libs/horizon/src/renderer/components/BaseClassComponent.ts +++ b/libs/horizon/src/renderer/components/BaseClassComponent.ts @@ -2,7 +2,7 @@ * Component的api setState和forceUpdate在实例生成阶段实现 */ -class Component
{ +class Component
{ props: P; context: C; state: S | null; @@ -15,12 +15,15 @@ class Component
{ } setState(state: S) { - console.error('Cant not call `this.setState` in the constructor of class component, it will do nothing') + if (isDev) { + console.error('Cant not call `this.setState` in the constructor of class component, it will do nothing'); + } } } // 兼容三方件 react-lifecycles-compat,它会读取 isReactComponent 属性值,不添加会导致 eview-ui 官网白屏 Component.prototype.isReactComponent = true; + /** * 支持PureComponent */ diff --git a/tsconfig.json b/tsconfig.json index e05c4501..e85c8cac 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -34,8 +34,8 @@ }, "include": [ "./libs/**/src/**/*.ts", - "libs/index.d.ts" + "libs/horizon/index.d.ts" ], "exclude": ["node_modules", "**/*.spec.ts", "dev"], - "types": ["node"], + "types": ["node"] }