fix: 修改 renderer 需等待 document 才开始渲染

This commit is contained in:
力皓 2020-09-18 14:44:56 +08:00
parent 62fb4cff3b
commit e7cc9bc7d8
6 changed files with 36 additions and 11 deletions

View File

@ -1309,6 +1309,26 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
return nearBy;
}
_innerWaitForCurrentDocument(): Promise<any> {
const timeGap = 200;
return new Promise((resolve) => {
setTimeout(() => {
if (this.project.currentDocument) {
resolve();
}
}, timeGap);
}).catch(() => {
return this.waitForCurrentDocument();
});
}
waitForCurrentDocument(): Promise<any> {
if (this.project.currentDocument) {
return Promise.resolve();
}
return this._innerWaitForCurrentDocument();
}
// #endregion
}

View File

@ -203,13 +203,13 @@ function compatiableReducer(props: any) {
};
}
// 为了能降级到老版本,建议在后期版本去掉以下代码
// if (isJSExpression(props) && !props.events) {
// return {
// type: 'variable',
// value: props.mock,
// variable: props.value,
// }
// }
if (isJSExpression(props) && !props.events) {
return {
type: 'variable',
value: props.mock,
variable: props.value,
};
}
const newProps: any = {};
Object.entries<any>(props).forEach(([key, val]) => {
newProps[key] = compatiableReducer(val);

View File

@ -80,7 +80,7 @@ export interface ObjectOf {
[k: string]: any;
}
export interface Shape {
type: 'shape';
type: "shape";
value: {
name?: string;
propType?: PropType;
@ -89,7 +89,7 @@ export interface Shape {
[k: string]: any;
}
export interface Exact {
type: 'exact';
type: "exact";
value: {
name?: string;
propType?: PropType;

View File

@ -54,5 +54,5 @@
"publishConfig": {
"registry": "http://registry.npm.alibaba-inc.com"
},
"homepage": "https://unpkg.alibaba-inc.com/@ali/lowcode-react-renderer@1.0.9-2/build/index.html"
"homepage": "https://unpkg.alibaba-inc.com/@ali/lowcode-react-renderer@1.0.9-5/build/index.html"
}

View File

@ -177,7 +177,8 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer {
}
constructor() {
this.dispose = host.connect(this, () => {
this.dispose = host.connect(this, async () => {
await host.waitForCurrentDocument();
// sync layout config
this._layout = host.project.get('config').layout;

View File

@ -1,3 +1,7 @@
export function isObject(value: any): value is Record<string, unknown> {
return value !== null && typeof value === 'object';
}
export function isI18NObject(value: any): boolean {
return isObject(value) && value.type === 'i18n';
}