From 3a902412fec46311762797d293d395f42c7b85be Mon Sep 17 00:00:00 2001 From: liujuping Date: Mon, 11 Apr 2022 11:33:59 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BD=8E=E4=BB=A3=E7=A0=81=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E6=94=AF=E6=8C=81=E7=94=9F=E5=91=BD=E5=91=A8=E6=9C=9F?= =?UTF-8?q?=E5=92=8C=E5=87=BD=E6=95=B0=E6=89=A7=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rax-simulator-renderer/src/renderer.ts | 2 -- .../react-simulator-renderer/src/renderer.ts | 2 -- .../renderer-core/src/renderer/component.tsx | 9 ++++++++ packages/utils/src/schema.ts | 22 +++++++++++++++++++ 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/packages/rax-simulator-renderer/src/renderer.ts b/packages/rax-simulator-renderer/src/renderer.ts index 41a96897b..0d2c86d34 100644 --- a/packages/rax-simulator-renderer/src/renderer.ts +++ b/packages/rax-simulator-renderer/src/renderer.ts @@ -498,8 +498,6 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer { const _schema: any = { ...compatibleLegaoSchema(schema), }; - _schema.methods = {}; - _schema.lifeCycles = {}; if (schema.componentName === 'Component' && (schema as ComponentSchema).css) { const doc = window.document; diff --git a/packages/react-simulator-renderer/src/renderer.ts b/packages/react-simulator-renderer/src/renderer.ts index db64f5b75..3981faa52 100644 --- a/packages/react-simulator-renderer/src/renderer.ts +++ b/packages/react-simulator-renderer/src/renderer.ts @@ -428,8 +428,6 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer { const _schema: any = { ...compatibleLegaoSchema(schema), }; - _schema.methods = {}; - _schema.lifeCycles = {}; if (schema.componentName === 'Component' && (schema as ComponentSchema).css) { const doc = window.document; diff --git a/packages/renderer-core/src/renderer/component.tsx b/packages/renderer-core/src/renderer/component.tsx index e6d936901..f6d4e1748 100644 --- a/packages/renderer-core/src/renderer/component.tsx +++ b/packages/renderer-core/src/renderer/component.tsx @@ -32,6 +32,8 @@ export default function componentRendererFactory() { const noContainer = this.__parseData(__schema.props?.noContainer); + this.__bindCustomMethods(); + if (noContainer) { return this.__renderContextProvider({ compContext: this }); } @@ -44,5 +46,12 @@ export default function componentRendererFactory() { return this.__renderComp(Component, this.__renderContextProvider({ compContext: this })); } + + /** 需要重载下面几个方法,如果在低代码组件中绑定了对应的生命周期时会出现死循环 */ + componentDidMount() {} + getSnapshotBeforeUpdate() {} + componentDidUpdate() {} + componentWillUnmount() {} + componentDidCatch() {} }; } diff --git a/packages/utils/src/schema.ts b/packages/utils/src/schema.ts index 83646386c..e1652bd9d 100644 --- a/packages/utils/src/schema.ts +++ b/packages/utils/src/schema.ts @@ -2,6 +2,15 @@ import { isJSBlock, isJSSlot, ActivityType, NodeSchema, PageSchema, RootSchema } import { isVariable } from './misc'; import { isPlainObject } from './is-plain-object'; +function isJsObject(props: any) { + if (typeof props === 'object' && props !== null) { + return props.type && props.source && props.compiled; + } +} +function isActionRef(props: any): boolean { + return props.type && props.type === 'actionRef'; +} + /** * 将「乐高版本」协议升级成 JSExpression / JSSlot 等标准协议的结构 * @param props @@ -40,6 +49,19 @@ export function compatibleLegaoSchema(props: any): any { mock: props.value, }; } + if (isJsObject(props)) { + return { + type: 'JSExpression', + value: props.compiled, + extType: 'function', + }; + } + if (isActionRef(props)) { + return { + type: 'JSExpression', + value: `${props.id}.bind(this)`, + }; + } const newProps: any = {}; Object.keys(props).forEach((key) => { if (/^__slot__/.test(key) && props[key] === true) {