fix: 调整 upgrade 和 init 的流程

This commit is contained in:
mario.gk 2020-07-21 21:13:32 +08:00
parent 5cfd57d16b
commit 09fc1a06c9
3 changed files with 25 additions and 7 deletions

View File

@ -159,7 +159,7 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
this.props = new Props(this, props, extras);
this._children = new NodeChildren(this as ParentalNode, this.initialChildren(children));
this._children.interalInitParent();
this.props.import(this.initProps(this.upgradeProps(props || {})), this.upgradeProps(extras || {}));
this.props.import(this.upgradeProps(this.initProps(props || {})), this.upgradeProps(extras || {}));
this.setupAutoruns();
}

View File

@ -85,17 +85,35 @@ designer.addPropsReducer((props, node) => {
const newProps: any = {
...props,
};
const getRealValue = (propValue: any) => {
if (isVariable(propValue)) {
return propValue.value;
}
if (isJSExpression(propValue)) {
return propValue.mock;
}
return propValue;
};
initials.forEach((item) => {
// FIXME! this implements SettingTarget
try {
// FIXME! item.name could be 'xxx.xxx'
const ov = props[item.name];
const v = item.initial(node as any, isJSExpression(ov) ? ov.mock : ov);
const v = item.initial(node as any, getRealValue(ov));
if (v !== undefined) {
newProps[item.name] = isJSExpression(ov) ? {
...ov,
mock: v,
} : v;
if (isVariable(ov)) {
newProps[item.name] = {
...ov,
value: v,
};
} else if (isJSExpression(ov)) {
newProps[item.name] = {
...ov,
mock: v,
};
} else {
newProps[item.name] = v;
}
}
} catch (e) {
if (hasOwnProperty(props, item.name)) {

View File

@ -248,8 +248,8 @@ export class SimulatorRenderer implements BuiltinSimulatorRenderer {
const _leaf = host.document.designer.currentDocument?.createNode(schema);
const node = host.document.createNode(schema);
let { props } = schema;
props = host.document.designer.transformProps(props, node, TransformStage.Upgrade);
props = host.document.designer.transformProps(props, node, TransformStage.Init);
props = host.document.designer.transformProps(props, node, TransformStage.Upgrade);
props = processPropsSchema(props, propsMap);
props = host.document.designer.transformProps(props, node, TransformStage.Render);
return createElement(Com, { ...props, _leaf }, children);