fix: 修复最小渲染单元问题 & 修复设计态使用数据源引擎的情况下,dataSourceMap 会被清除

This commit is contained in:
liujuping.liujupin 2021-11-17 17:18:50 +08:00
parent 33f0fb43c9
commit f921f3c7b0
4 changed files with 27 additions and 27 deletions

View File

@ -18,6 +18,7 @@
"@ali/lib-mtop": "^2.5.1", "@ali/lib-mtop": "^2.5.1",
"@ali/lowcode-datasource-engine": "^1.0.22", "@ali/lowcode-datasource-engine": "^1.0.22",
"@ali/lowcode-types": "1.0.72", "@ali/lowcode-types": "1.0.72",
"@ali/lowcode-utils": "1.0.72",
"classnames": "^2.2.6", "classnames": "^2.2.6",
"debug": "^4.1.1", "debug": "^4.1.1",
"fetch-jsonp": "^1.1.3", "fetch-jsonp": "^1.1.3",

View File

@ -9,12 +9,7 @@ export function compWrapper(Comp: any) {
// } // }
render() { render() {
const { forwardRef, ...rest } = this.props; return createElement(Comp, this.props);
return createElement(Comp, {
...rest,
ref: forwardRef,
});
} }
} }

View File

@ -316,12 +316,12 @@ export function leafWrapper(Comp: types.IBaseRenderer, {
} }
} }
makeUnitRender() { makeUnitRender = () => {
this.beforeRender(RerenderType.MinimalRenderUnit); this.beforeRender(RerenderType.MinimalRenderUnit);
const nextProps = getProps(this.leaf?.export?.(TransformStage.Render) as types.ISchema, scope, Comp, componentInfo); const nextProps = getProps(this.leaf?.export?.(TransformStage.Render) as types.ISchema, scope, Comp, componentInfo);
const children = getChildren(this.leaf?.export?.(TransformStage.Render) as types.ISchema, scope, Comp); const children = getChildren(this.leaf?.export?.(TransformStage.Render) as types.ISchema, scope, Comp);
const nextState = { const nextState = {
nextProps, nodeProps: nextProps,
nodeChildren: children, nodeChildren: children,
childrenInState: true, childrenInState: true,
}; };
@ -331,7 +331,7 @@ export function leafWrapper(Comp: types.IBaseRenderer, {
__debug(`${this.leaf?.componentName}(${this.props.componentId}) MinimalRenderUnit Render!`); __debug(`${this.leaf?.componentName}(${this.props.componentId}) MinimalRenderUnit Render!`);
this.setState(nextState); this.setState(nextState);
} };
componentWillReceiveProps(nextProps: any) { componentWillReceiveProps(nextProps: any) {
let { _leaf, componentId } = nextProps; let { _leaf, componentId } = nextProps;

View File

@ -224,20 +224,26 @@ export default function baseRenererFactory() {
const dataSource = (schema && schema.dataSource) || {}; const dataSource = (schema && schema.dataSource) || {};
// requestHandlersMap 存在才走数据源引擎方案 // requestHandlersMap 存在才走数据源引擎方案
if (props?.__appHelper?.requestHandlersMap) { if (props?.__appHelper?.requestHandlersMap) {
const { dataSourceMap, reloadDataSource } = createDataSourceEngine(dataSource, (this as any), { this.__dataHelper = {
requestHandlersMap: props.__appHelper.requestHandlersMap, updateConfig: (updateDataSource: any) => {
}); const { dataSourceMap, reloadDataSource } = createDataSourceEngine(updateDataSource, (this as any), {
this.dataSourceMap = dataSourceMap; requestHandlersMap: props.__appHelper.requestHandlersMap,
this.reloadDataSource = () => new Promise((resolve) => { });
this.__debug('reload data source');
// this.__showPlaceholder = true; this.reloadDataSource = () => new Promise((resolve) => {
reloadDataSource().then(() => { this.__debug('reload data source');
// this.__showPlaceholder = false; // this.__showPlaceholder = true;
// @TODO 是否需要 forceUpate reloadDataSource().then(() => {
// this.forceUpdate(); // this.__showPlaceholder = false;
resolve({}); // @TODO 是否需要 forceUpate
}); // this.forceUpdate();
}); resolve({});
});
});
return dataSourceMap;
},
};
this.dataSourceMap = this.__dataHelper.updateConfig(dataSource);
} else { } else {
const appHelper = props.__appHelper; const appHelper = props.__appHelper;
this.__dataHelper = new DataHelper(this, dataSource, appHelper, (config: any) => this.__parseData(config)); this.__dataHelper = new DataHelper(this, dataSource, appHelper, (config: any) => this.__parseData(config));
@ -531,7 +537,7 @@ export default function baseRenererFactory() {
props.key = props.__id; props.key = props.__id;
} }
let child: any = parentInfo.componentChildren || this.__getSchemaChildrenVirtualDom(schema, scope, Comp); let child: any = this.__getSchemaChildrenVirtualDom(schema, scope, Comp);
const renderComp = (props: any) => engine.createElement(Comp, props, child); const renderComp = (props: any) => engine.createElement(Comp, props, child);
// 设计模式下的特殊处理 // 设计模式下的特殊处理
if (engine && [DESIGN_MODE.EXTEND, DESIGN_MODE.BORDER].includes(engine.props.designMode)) { if (engine && [DESIGN_MODE.EXTEND, DESIGN_MODE.BORDER].includes(engine.props.designMode)) {
@ -590,7 +596,7 @@ export default function baseRenererFactory() {
.map((d: IComponentHoc) => d.hoc); .map((d: IComponentHoc) => d.hoc);
} }
__getSchemaChildrenVirtualDom = (schema: ISchema, scope: any, Comp: any, childrenMap?: Map<any, any>) => { __getSchemaChildrenVirtualDom = (schema: ISchema, scope: any, Comp: any) => {
let _children = this.getSchemaChildren(schema); let _children = this.getSchemaChildren(schema);
let children: any = []; let children: any = [];
@ -606,8 +612,6 @@ export default function baseRenererFactory() {
{ {
schema, schema,
Comp, Comp,
// 有 childrenMap 情况下children 只计算第一层,不需要遍历多层。
componentChildren: childrenMap?.get(_child.id)?.props.children || null,
}, },
); );