GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — refactor: minor refactors for render-core/renderer/base. remove usele… · xzlinux/lowcode-engine@282a30a

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages
    • renderer-core/src
      • renderer
        • base.tsx
      • types
        • index.ts
    • types/src
      • schema.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/renderer-core/src/renderer/base.tsx‎

Copy file name to clipboardExpand all lines: packages/renderer-core/src/renderer/base.tsx
+66-65Lines changed: 66 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import {
2929
isVariable,
3030
isJSSlot,
3131
} from '../utils';
32-
import { IBaseRendererProps, IInfo, IBaseRenderComponent, IBaseRendererContext, IGeneralConstructor, IRendererAppHelper, DataSource } from '../types';
32+
import { IBaseRendererProps, INodeInfo, IBaseRenderComponent, IBaseRendererContext, IGeneralConstructor, IRendererAppHelper, DataSource } from '../types';
3333
import { compWrapper } from '../hoc';
3434
import { IComponentConstruct, IComponentHoc, leafWrapper } from '../hoc/leaf';
3535
import logger from '../utils/logger';
@@ -59,6 +59,8 @@ export default function baseRendererFactory(): IBaseRenderComponent {
5959
PREVIEW: 'preview',
6060
};
6161
const OVERLAY_LIST = ['Dialog', 'Overlay', 'Animate', 'ConfigProvider'];
62+
const DEFAULT_LOOP_ARG_ITEM = 'item';
63+
const DEFAULT_LOOP_ARG_INDEX = 'index';
6264
let scopeIdx = 0;
6365

6466
return class BaseRenderer extends Component {
@@ -377,7 +379,7 @@ export default function baseRendererFactory(): IBaseRenderComponent {
377379
if (engine) {
378380
engine.props.onCompGetCtx(schema, this);
379381
// 画布场景才需要每次渲染bind自定义方法
380-
if (engine.props.designMode === 'design') {
382+
if (this.__designModeIsDesign) {
381383
this.__bindCustomMethods(this.props);
382384
this.dataSourceMap = this.__dataHelper?.updateConfig(schema.dataSource);
383385
}
@@ -432,7 +434,7 @@ export default function baseRendererFactory(): IBaseRenderComponent {
432434
return this.__createVirtualDom(_children, scope, ({
433435
schema: __schema,
434436
Comp: this.__getHocComp(Comp, __schema, scope),
435-
} as IInfo));
437+
} as INodeInfo));
436438
};
437439

438440
/**
@@ -442,7 +444,7 @@ export default function baseRendererFactory(): IBaseRenderComponent {
442444
* @param parentInfo 父组件的信息,包含schema和Comp
443445
* @param idx 为循环渲染的循环Index
444446
*/
445-
__createVirtualDom = (originalSchema: NodeData | NodeData[] | undefined, originalScope: any, parentInfo: IInfo, idx: string | number = ''): any => {
447+
__createVirtualDom = (originalSchema: NodeData | NodeData[] | undefined, originalScope: any, parentInfo: INodeInfo, idx: string | number = ''): any => {
446448
if (!originalSchema) {
447449
return null;
448450
}
@@ -527,7 +529,7 @@ export default function baseRendererFactory(): IBaseRenderComponent {
527529

528530
if (schema.loop != null) {
529531
const loop = this.__parseData(schema.loop, scope);
530-
const useLoop = isUseLoop(loop, this._designModeIsDesign);
532+
const useLoop = isUseLoop(loop, this.__designModeIsDesign);
531533
if (useLoop) {
532534
return this.__createLoopVirtualDom(
533535
{
@@ -543,7 +545,7 @@ export default function baseRendererFactory(): IBaseRenderComponent {
543545
const condition = schema.condition == null ? true : this.__parseData(schema.condition, scope);
544546

545547
// DesignMode 为 design 情况下,需要进入 leaf Hoc,进行相关事件注册
546-
const displayInHook = engine.props?.designMode === 'design';
548+
const displayInHook = this.__designModeIsDesign;
547549
if (!condition && !displayInHook) {
548550
return null;
549551
}
@@ -579,7 +581,7 @@ export default function baseRendererFactory(): IBaseRenderComponent {
579581
if (engine.props?.designMode) {
580582
otherProps.__designMode = engine.props.designMode;
581583
}
582-
if (this._designModeIsDesign) {
584+
if (this.__designModeIsDesign) {
583585
otherProps.__tag = Math.random();
584586
}
585587
const componentInfo: any = {};
@@ -588,7 +590,7 @@ export default function baseRendererFactory(): IBaseRenderComponent {
588590
props: transformArrayToMap(componentInfo.props, 'name'),
589591
}) || {};
590592

591-
this.componentHoc.forEach((ComponentConstruct: IComponentConstruct) => {
593+
this.__componentHoc.forEach((ComponentConstruct: IComponentConstruct) => {
592594
Comp = ComponentConstruct(Comp, {
593595
schema,
594596
componentInfo,
@@ -671,7 +673,7 @@ export default function baseRendererFactory(): IBaseRenderComponent {
671673
}
672674
};
673675

674-
get componentHoc(): IComponentConstruct[] {
676+
get __componentHoc(): IComponentConstruct[] {
675677
const componentHoc: IComponentHoc[] = [
676678
{
677679
designMode: 'design',
@@ -691,31 +693,31 @@ export default function baseRendererFactory(): IBaseRenderComponent {
691693
}
692694

693695
__getSchemaChildrenVirtualDom = (schema: NodeSchema | undefined, scope: any, Comp: any) => {
694-
let _children = this.__getSchemaChildren(schema);
696+
let children = this.__getSchemaChildren(schema);
695697

696698
// @todo 补完这里的 Element 定义 @承虎
697-
let children: any = [];
698-
if (/*! isFileSchema(schema) && */_children) {
699-
if (!Array.isArray(_children)) {
700-
_children = [_children];
699+
let result: any = [];
700+
if (children) {
701+
if (!Array.isArray(children)) {
702+
children = [children];
701703
}
702704

703-
_children.forEach((_child: any) => {
704-
const _childVirtualDom = this.__createVirtualDom(
705-
isJSExpression(_child) ? this.parseExpression(_child, scope) : _child,
705+
children.forEach((child: any) => {
706+
const childVirtualDom = this.__createVirtualDom(
707+
isJSExpression(child) ? this.parseExpression(child, scope) : child,
706708
scope,
707709
{
708710
schema,
709711
Comp,
710712
},
711713
);
712714

713-
children.push(_childVirtualDom);
715+
result.push(childVirtualDom);
714716
});
715717
}
716718

717-
if (children && children.length) {
718-
return children;
719+
if (result && result.length > 0) {
720+
return result;
719721
}
720722
return null;
721723
};
@@ -734,14 +736,16 @@ export default function baseRendererFactory(): IBaseRenderComponent {
734736
}) || {};
735737
};
736738

737-
__createLoopVirtualDom = (schema: NodeSchema, scope: any, parentInfo: IInfo, idx: number | string) => {
739+
__createLoopVirtualDom = (schema: NodeSchema, scope: any, parentInfo: INodeInfo, idx: number | string) => {
738740
if (isFileSchema(schema)) {
739741
console.warn('file type not support Loop');
740742
return null;
741743
}
742-
if (!Array.isArray(schema.loop)) return null;
743-
const itemArg = (schema.loopArgs && schema.loopArgs[0]) || 'item';
744-
const indexArg = (schema.loopArgs && schema.loopArgs[1]) || 'index';
744+
if (!Array.isArray(schema.loop)) {
745+
return null;
746+
}
747+
const itemArg = (schema.loopArgs && schema.loopArgs[0]) || DEFAULT_LOOP_ARG_ITEM;
748+
const indexArg = (schema.loopArgs && schema.loopArgs[1]) || DEFAULT_LOOP_ARG_INDEX;
745749
const { loop } = schema;
746750
return loop.map((item: JSONValue | CompositeValue, i: number) => {
747751
const loopSelf: any = {
@@ -761,26 +765,29 @@ export default function baseRendererFactory(): IBaseRenderComponent {
761765
});
762766
};
763767

764-
get _designModeIsDesign() {
768+
get __designModeIsDesign() {
765769
const { engine } = this.context || {};
766770
return engine?.props?.designMode === 'design';
767771
}
768772

769-
__parseProps = (originalProps: any, scope: any, path: string, info: IInfo): any => {
773+
__parseProps = (originalProps: any, scope: any, path: string, info: INodeInfo): any => {
770774
let props = originalProps;
771775
const { schema, Comp, componentInfo = {} } = info;
772776
const propInfo = getValue(componentInfo.props, path);
773-
// FIXME! 将这行逻辑外置,解耦,线上环境不要验证参数,调试环境可以有,通过传参自定义
777+
// FIXME: 将这行逻辑外置,解耦,线上环境不要验证参数,调试环境可以有,通过传参自定义
774778
const propType = propInfo?.extra?.propType;
775-
const ignoreParse = schema?.__ignoreParse || [];
779+
776780
const checkProps = (value: any) => {
777-
if (!propType) return value;
781+
if (!propType) {
782+
return value;
783+
}
778784
return checkPropTypes(value, path, propType, componentInfo.name) ? value : undefined;
779785
};
780786

781787
const parseReactNode = (data: any, params: any) => {
782788
if (isEmpty(params)) {
783-
return checkProps(this.__createVirtualDom(data, scope, ({ schema, Comp } as IInfo)));
789+
const virtualDom = this.__createVirtualDom(data, scope, ({ schema, Comp } as INodeInfo));
790+
return checkProps(virtualDom);
784791
}
785792
return checkProps((...argValues: any[]) => {
786793
const args: any = {};
@@ -794,44 +801,35 @@ export default function baseRendererFactory(): IBaseRenderComponent {
794801
});
795802
}
796803
args.__proto__ = scope;
797-
return scope.__createVirtualDom(data, args, { schema, Comp });
804+
return scope.__createVirtualDom(data, args, ({ schema, Comp } as INodeInfo));
798805
});
799806
};
800807

801-
// 判断是否需要解析变量
802-
if (
803-
ignoreParse.some((item: any) => {
804-
if (item instanceof RegExp) {
805-
return item.test(path);
806-
}
807-
return item === path;
808-
})
809-
) {
810-
return checkProps(props);
811-
}
812808
if (isJSExpression(props)) {
813809
props = this.parseExpression(props, scope);
814810
// 只有当变量解析出来为模型结构的时候才会继续解析
815-
if (!isSchema(props) && !isJSSlot(props)) return checkProps(props);
811+
if (!isSchema(props) && !isJSSlot(props)) {
812+
return checkProps(props);
813+
}
816814
}
817815

818-
const handleLegaoI18n = (innerProps: any) => innerProps[innerProps.use || 'zh_CN'];
816+
const handleI18nData = (innerProps: any) => innerProps[innerProps.use || 'zh_CN'];
819817

820-
// 兼容乐高设计态 i18n 数据
818+
// @LEGACY 兼容老平台设计态 i18n 数据
821819
if (isI18nData(props)) {
822-
const i18nProp = handleLegaoI18n(props);
820+
const i18nProp = handleI18nData(props);
823821
if (i18nProp) {
824822
props = i18nProp;
825823
} else {
826824
return parseI18n(props, scope);
827825
}
828826
}
829827

830-
// 兼容乐高设计态的变量绑定
828+
// @LEGACY 兼容老平台设计态的变量绑定
831829
if (isVariable(props)) {
832830
props = props.value;
833831
if (isI18nData(props)) {
834-
props = handleLegaoI18n(props);
832+
props = handleI18nData(props);
835833
}
836834
}
837835

@@ -840,15 +838,15 @@ export default function baseRendererFactory(): IBaseRenderComponent {
840838
}
841839
if (isJSSlot(props)) {
842840
const { params, value } = props;
843-
if (!isSchema(value) || isEmpty(value)) return undefined;
841+
if (!isSchema(value) || isEmpty(value)) {
842+
return undefined;
843+
}
844844
return parseReactNode(value, params);
845845
}
846+
846847
// 兼容通过componentInfo判断的情况
847848
if (isSchema(props)) {
848-
const isReactNodeFunction = !!(
849-
propInfo?.type === 'ReactNode'
850-
&& propInfo?.props?.type === 'function'
851-
);
849+
const isReactNodeFunction = !!(propInfo?.type === 'ReactNode' && propInfo?.props?.type === 'function');
852850

853851
const isMixinReactNodeFunction = !!(
854852
propInfo?.type === 'Mixin'
@@ -874,7 +872,9 @@ export default function baseRendererFactory(): IBaseRenderComponent {
874872
return checkProps(props.bind(scope));
875873
}
876874
if (props && typeof props === 'object') {
877-
if (props.$$typeof) return checkProps(props);
875+
if (props.$$typeof) {
876+
return checkProps(props);
877+
}
878878
const res: any = {};
879879
forEach(props, (val: any, key: string) => {
880880
if (key.startsWith('__')) {
@@ -921,7 +921,7 @@ export default function baseRendererFactory(): IBaseRenderComponent {
921921

922922
__getHocComp(OriginalComp: any, schema: any, scope: any) {
923923
let Comp = OriginalComp;
924-
this.componentHoc.forEach((ComponentConstruct: IComponentConstruct) => {
924+
this.__componentHoc.forEach((ComponentConstruct: IComponentConstruct) => {
925925
Comp = ComponentConstruct(Comp || Div, {
926926
schema,
927927
componentInfo: {},
@@ -935,8 +935,7 @@ export default function baseRendererFactory(): IBaseRenderComponent {
935935

936936
__renderComp(OriginalComp: any, ctxProps: object) {
937937
let Comp = OriginalComp;
938-
const { __schema } = this.props;
939-
const { __ctx } = this.props;
938+
const { __schema, __ctx } = this.props;
940939
const scope: any = {};
941940
scope.__proto__ = __ctx || this;
942941
Comp = this.__getHocComp(Comp, __schema, scope);
@@ -952,7 +951,7 @@ export default function baseRendererFactory(): IBaseRenderComponent {
952951
return null;
953952
}
954953

955-
if (this._designModeIsDesign) {
954+
if (this.__designModeIsDesign) {
956955
otherProps.__tag = Math.random();
957956
}
958957

@@ -973,13 +972,15 @@ export default function baseRendererFactory(): IBaseRenderComponent {
973972

974973
__renderContent(children: any) {
975974
const { __schema } = this.props;
976-
const props = this.__parseData(__schema.props);
977-
const { id, className, style = {} } = props;
975+
const parsedProps = this.__parseData(__schema.props);
976+
const className = classnames(`lce-${this.__namespace}`, getFileCssName(__schema.fileName), parsedProps.className, this.props.className);
977+
const style = { ...(parsedProps.style || {}), ...(typeof this.props.style === 'object' ? this.props.style : {}) };
978+
const id = this.props.id || parsedProps.id;
978979
return createElement('div', {
979980
ref: this.__getRef,
980-
className: classnames(`lce-${this.__namespace}`, getFileCssName(__schema.fileName), className, this.props.className),
981-
id: this.props.id || id,
982-
style: { ...style, ...(typeof this.props.style === 'object' ? this.props.style : {}) },
981+
className,
982+
id,
983+
style,
983984
}, children);
984985
}
985986

@@ -989,8 +990,8 @@ export default function baseRendererFactory(): IBaseRenderComponent {
989990
extraComponents = [extraComponents];
990991
}
991992

992-
const buitin = capitalizeFirstLetter(this.__namespace);
993-
const componentNames = [buitin, ...extraComponents];
993+
const builtin = capitalizeFirstLetter(this.__namespace);
994+
const componentNames = [builtin, ...extraComponents];
994995
return !isSchema(schema) || !componentNames.includes(schema?.componentName ?? '');
995996
};
996997

Collapse file

‎packages/renderer-core/src/types/index.ts‎

Copy file name to clipboardExpand all lines: packages/renderer-core/src/types/index.ts
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ export interface IBaseRendererProps {
168168
device?: 'default' | 'mobile' | string;
169169
}
170170

171-
export interface IInfo {
171+
export interface INodeInfo {
172172
schema?: NodeSchema;
173173
Comp: any;
174174
componentInfo?: any;
@@ -254,9 +254,9 @@ export type IBaseRendererInstance = IGeneralComponent<
254254
): any;
255255
__getComponentProps(schema: NodeSchema | undefined, scope: any, Comp: any, componentInfo?: any): any;
256256
__createDom(): any;
257-
__createVirtualDom(schema: any, self: any, parentInfo: IInfo, idx: string | number): any;
258-
__createLoopVirtualDom(schema: any, self: any, parentInfo: IInfo, idx: number | string): any;
259-
__parseProps(props: any, self: any, path: string, info: IInfo): any;
257+
__createVirtualDom(schema: any, self: any, parentInfo: INodeInfo, idx: string | number): any;
258+
__createLoopVirtualDom(schema: any, self: any, parentInfo: INodeInfo, idx: number | string): any;
259+
__parseProps(props: any, self: any, path: string, info: INodeInfo): any;
260260
__initDebug?(): void;
261261
__debug(...args: any[]): void;
262262
__renderContextProvider(customProps?: object, children?: any): any;
Collapse file

‎packages/types/src/schema.ts‎

Copy file name to clipboardExpand all lines: packages/types/src/schema.ts
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ export interface NodeSchema {
6464

6565
/** @experimental 编辑态内部使用 */
6666
__ctx?: any;
67-
/** @experimental 编辑态内部使用 */
68-
__ignoreParse?: any[];
6967
}
7068

7169
export type PropsMap = CompositeObject;

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.