Merge branch 'fix/onNodeAdd' into 'release/0.9.0'

fix: props.getNode 防死循环

防止死循环调用

See merge request !907974
This commit is contained in:
康为 2020-07-27 12:16:33 +08:00
commit 89c6abbb5c
3 changed files with 32 additions and 7 deletions

View File

@ -313,9 +313,10 @@ export class NodeChildren {
return;
}
const callbacks = owner.componentMeta.getMetadata().experimental?.callbacks;
if (callbacks?.onSubtreeModified) {
if (callbacks?.onSubtreeModified && options?.type !== 'insert') {
try {
callbacks?.onSubtreeModified.call(node, owner, options);
// 此处传入的 owner节点需要对getChildren进行处理兼容老的数据结构
callbacks?.onSubtreeModified.call(node, owner.getVisionCapabledNode(), options);
} catch (e) {
console.error('error when excute experimental.callbacks.onNodeAdd', e);
}
@ -323,7 +324,7 @@ export class NodeChildren {
if (callbacks?.onNodeAdd && options?.type === 'insert') {
try {
callbacks?.onNodeAdd.call(owner, node, owner);
callbacks?.onNodeAdd.call(owner, node.getVisionCapabledNode(), owner);
} catch (e) {
console.error('error when excute experimental.callbacks.onNodeAdd', e);
}

View File

@ -818,6 +818,33 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
toString() {
return this.id;
}
/**
*
* @deprecated
*/
getVisionCapabledNode() {
// 判断是否已经是 nodeForVision
if (!this.isVisionNode) {
const children = this.getChildren();
this.getChildren = () => {
return children?.getChildrenArray() || [];
};
this.getProps = () => {
const props = this.props.export();
props.getPropValue = (key) => {
return this.props.getPropValue(key);
};
props.getNode = () => {
return this;
};
return props;
};
this.isVisionNode = true;
}
return this;
}
}
export interface ParentalNode<T extends NodeSchema = NodeSchema> extends Node<T> {

View File

@ -335,10 +335,7 @@ export class Props implements IPropParent {
* vision体系
*/
getNode() {
const nodeForVision = this.owner;
nodeForVision.getChildren = () => {
return this.owner?.getChildren()?.getChildrenArray() || [];
};
const nodeForVision = this.owner?.getVisionCapabledNode();
return nodeForVision;
}
}