sperate props upgrade & init logic

This commit is contained in:
kangwei 2020-07-13 22:23:18 +08:00
parent 6dc9ff8426
commit 0777c3c9d9
4 changed files with 12 additions and 7 deletions

View File

@ -520,7 +520,7 @@ export class DocumentModel {
}; };
} }
setRendererReady(renderer) { setRendererReady(renderer: any) {
this.emitter.emit('lowcode_engine_renderer_ready', renderer); this.emitter.emit('lowcode_engine_renderer_ready', renderer);
} }

View File

@ -157,17 +157,19 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
this.props = new Props(this, props, extras); this.props = new Props(this, props, extras);
this._children = new NodeChildren(this as ParentalNode, this.initialChildren(children)); this._children = new NodeChildren(this as ParentalNode, this.initialChildren(children));
this._children.interalInitParent(); this._children.interalInitParent();
this.props.import(this.transformProps(props || {}), this.transformProps(extras || {})); this.props.import(this.upgradeProps(this.initProps(props || {})), this.upgradeProps(extras || {}));
this.setupAutoruns(); this.setupAutoruns();
} }
this.settingEntry = this.document.designer.createSettingEntry([ this ]); this.settingEntry = this.document.designer.createSettingEntry([ this ]);
} }
private transformProps(props: any): any { private initProps(props: any): any {
// FIXME! support PropsList
return this.document.designer.transformProps(props, this, TransformStage.Init); return this.document.designer.transformProps(props, this, TransformStage.Init);
} }
private upgradeProps(props: any): any {
return this.document.designer.transformProps(props, this, TransformStage.Upgrade);
}
private autoruns?: Array<() => void>; private autoruns?: Array<() => void>;
private setupAutoruns() { private setupAutoruns() {
@ -545,7 +547,7 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
const addon = this._addons[key]; const addon = this._addons[key];
if (addon) { if (addon) {
if (addon.isProp) { if (addon.isProp) {
(props as any)[key] = addon.exportData(); (props as any)[getConvertedExtraKey(key)] = addon.exportData();
} else { } else {
_extras_[key] = addon.exportData(); _extras_[key] = addon.exportData();
} }

View File

@ -74,14 +74,16 @@ function upgradePropsReducer(props: any) {
return newProps; return newProps;
} }
// 升级 Props // 升级 Props
designer.addPropsReducer(upgradePropsReducer, TransformStage.Init); designer.addPropsReducer(upgradePropsReducer, TransformStage.Upgrade);
// 节点 props 初始化 // 节点 props 初始化
designer.addPropsReducer((props, node) => { designer.addPropsReducer((props, node) => {
// run initials // run initials
const initials = node.componentMeta.getMetadata().experimental?.initials; const initials = node.componentMeta.getMetadata().experimental?.initials;
if (initials) { if (initials) {
const newProps: any = {}; const newProps: any = {
...props,
};
initials.forEach((item) => { initials.forEach((item) => {
// FIXME! this implements SettingTarget // FIXME! this implements SettingTarget
try { try {

View File

@ -4,4 +4,5 @@ export enum TransformStage {
Save = 3, Save = 3,
Clone = 4, Clone = 4,
Init = 5, Init = 5,
Upgrade = 6,
} }