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 e0d846aa2..5cdfe004e 100644 --- a/packages/react-simulator-renderer/src/renderer.ts +++ b/packages/react-simulator-renderer/src/renderer.ts @@ -429,8 +429,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) {