From 45cd088e607fc5101b43dd1a12e089768b68f0cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8A=9B=E7=9A=93?= Date: Thu, 10 Jun 2021 15:43:15 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=A2=9E=E5=8A=A0=E5=A2=9E?= =?UTF-8?q?=E9=87=8F=E6=9B=B4=E6=96=B0=E6=9C=BA=E5=88=B6=E7=9A=84=E9=83=A8?= =?UTF-8?q?=E5=88=86=E9=99=90=E5=88=B6=E6=9D=A1=E4=BB=B6,=20=E5=B9=B6?= =?UTF-8?q?=E5=B0=86=E9=97=A8=E6=A7=9B=E8=B0=83=E6=95=B4=E5=88=B0=20200=20?= =?UTF-8?q?=E8=8A=82=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../react-simulator-renderer/src/renderer.ts | 6 ++--- .../src/utils/misc.ts | 23 +++++++++++++++---- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/packages/react-simulator-renderer/src/renderer.ts b/packages/react-simulator-renderer/src/renderer.ts index 92b8ff08e..c70800190 100644 --- a/packages/react-simulator-renderer/src/renderer.ts +++ b/packages/react-simulator-renderer/src/renderer.ts @@ -48,8 +48,8 @@ export class DocumentInstance { this.disposeFunctions.push(host.onActivityEvent((data: ActivityData, ctx: any) => { if (host.mutedActivityEvent || (ctx && ctx.doc !== this.document)) return; - // 当节点数小数 300 个时,不走入增量更新逻辑,后面优化、细化逻辑后逐步放开限制 - if (this.document.nodesMap.size < 300) return; + // 当节点数小数 200 个时,不走入增量更新逻辑,后面优化、细化逻辑后逐步放开限制 + if (this.document.nodesMap.size < 200) return; if (tid) clearTimeout(tid); // 临时关闭全量计算 schema 的逻辑,在增量计算结束后,来一次全量计算 @@ -59,7 +59,7 @@ export class DocumentInstance { if (supportsQuickPropSetting(data, this)) { setInstancesProp(data, this); } else { - this._schema = applyActivities(this._schema!, data); + // this._schema = applyActivities(this._schema!, data); } } else if (data.type === ActivityType.ADDED) { // FIXME: 待补充 节点增加 逻辑 diff --git a/packages/react-simulator-renderer/src/utils/misc.ts b/packages/react-simulator-renderer/src/utils/misc.ts index 9777c4047..a4cd86848 100644 --- a/packages/react-simulator-renderer/src/utils/misc.ts +++ b/packages/react-simulator-renderer/src/utils/misc.ts @@ -1,6 +1,7 @@ import { ReactInstance } from 'react'; import { ActivityData, isJSSlot } from '@ali/lowcode-types'; import { DocumentInstance } from '../renderer'; +import { isReactClass } from '@ali/lowcode-utils'; interface UtilsMetadata { name: string; @@ -55,9 +56,9 @@ function haveForceUpdate(instances: any[]): boolean { export function supportsQuickPropSetting(data: ActivityData, doc: DocumentInstance) { const { payload } = data; const { schema, prop } = payload; - const nodeId = schema.id!; + const { componentName, id: nodeId } = schema; // const key = data.payload.prop.key; - const instances = doc.instancesMap.get(nodeId); + const instances = doc.instancesMap.get(nodeId!); const propKey = getUppermostPropKey(prop); let value = (schema.props as any)[propKey]; @@ -65,14 +66,28 @@ export function supportsQuickPropSetting(data: ActivityData, doc: DocumentInstan nodeId && Array.isArray(instances) && instances.length > 0 && - haveForceUpdate(instances) && propKey && // 不是 extraProp !propKey.startsWith('___') && - !isJSSlot(value) + !isJSSlot(value) && + // functional component 不支持 ref.props 直接设值,是 readonly 的 + isReactClass((doc.container?.components as any)[componentName]) && + haveForceUpdate(instances) && + // 黑名单组件通常会把 schema / children 魔改,导致直接设置 props 失效 + isAllowedComponent(componentName) ); } +// 不允许走快捷设置的组件黑名单 +const DISABLED__QUICK_SETTING_COMPONENT_NAMES = [ + 'Filter', // 查询组件 + 'Filter2', // 查询组件 + 'TableField', // 明细组件 +]; +function isAllowedComponent(name: string): boolean { + return !DISABLED__QUICK_SETTING_COMPONENT_NAMES.includes(name); +} + /** * 设置属性值 * @param data