refactor: prop 的子实例不再延迟初始化, 也不再 node 未初始化完成之前就调用 dispose 方法

This commit is contained in:
lihao.ylh 2021-09-01 21:10:02 +08:00
parent a10641daff
commit 3f2cd667d0
2 changed files with 10 additions and 6 deletions

View File

@ -157,7 +157,7 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
return this.componentMeta.icon;
}
private isInited = false;
isInited = false;
constructor(readonly document: DocumentModel, nodeSchema: Schema, options: any = {}) {
const { componentName, id, children, props, ...extras } = nodeSchema;
@ -168,9 +168,6 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
children: isDOMText(children) || isJSExpression(children) ? children : '',
});
} else {
// 这里 props 被初始化两次,一次 new一次 importnew 的实例需要给 propsReducer 的钩子去使用,
// import 是为了使用钩子返回的值,并非完全幂等的操作,部分行为执行两次会有 bug
// 所以在 props 里会对 new / import 做一些区别化的解析
this.props = new Props(this, props, extras);
this._children = new NodeChildren(this as ParentalNode, this.initialChildren(children));
this._children.internalInitParent();

View File

@ -55,6 +55,12 @@ export class Prop implements IPropParent {
if (value !== UNSET) {
this.setValue(value);
}
this.setupItems();
}
// TODO: 先用调用方式触发子 prop 的初始化,后续须重构
private setupItems() {
return this.items;
}
/**
@ -247,7 +253,9 @@ export class Prop implements IPropParent {
};
}
this.dispose();
if (this.owner.isInited) {
this.dispose();
}
if (oldValue !== this._value) {
editor?.emit('node.innerProp.change', {
@ -302,7 +310,6 @@ export class Prop implements IPropParent {
owner.addSlot(this._slotNode);
this._slotNode.internalSetSlotFor(this);
}
this.dispose();
}
/**