mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-06-23 02:15:10 +08:00
feat(editor,dep): watcher新增方法:清除指定类型的依赖
This commit is contained in:
parent
2dc810a9fd
commit
d981014160
@ -120,7 +120,7 @@ export default class Watcher {
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除依赖
|
||||
* 清除所有目标的依赖
|
||||
* @param nodes 需要清除依赖的节点
|
||||
*/
|
||||
public clear(nodes?: Record<string | number, any>[]) {
|
||||
@ -143,6 +143,29 @@ export default class Watcher {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除指定类型的依赖
|
||||
* @param type 类型
|
||||
* @param nodes 需要清除依赖的节点
|
||||
*/
|
||||
public clearByType(type: DepTargetType, nodes?: Record<string | number, any>[]) {
|
||||
const clearedItemsNodeIds: (string | number)[] = [];
|
||||
const targetList = this.getTargets(type);
|
||||
Object.values(targetList).forEach((target) => {
|
||||
if (nodes) {
|
||||
nodes.forEach((node) => {
|
||||
target.removeDep(node);
|
||||
if (Array.isArray(node.items) && node.items.length && !clearedItemsNodeIds.includes(node.id)) {
|
||||
clearedItemsNodeIds.push(node.id);
|
||||
this.clear(node.items);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
target.removeDep();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private collectItem(node: Record<string | number, any>, target: Target, deep = false) {
|
||||
const collectTarget = (config: Record<string | number, any>, prop = '') => {
|
||||
const doCollect = (key: string, value: any) => {
|
||||
|
@ -62,6 +62,10 @@ class Dep extends BaseService {
|
||||
return this.watcher.clear(nodes);
|
||||
}
|
||||
|
||||
public clearByType(type: DepTargetType, nodes?: MNode[]) {
|
||||
return this.watcher.clearByType(type, nodes);
|
||||
}
|
||||
|
||||
public hasTarget(id: Id, type: string = DepTargetType.DEFAULT) {
|
||||
return this.watcher.hasTarget(id, type);
|
||||
}
|
||||
|
@ -644,7 +644,7 @@ class Editor extends BaseService {
|
||||
public copyWithRelated(config: MNode | MNode[]): void {
|
||||
const copyNodes: MNode[] = Array.isArray(config) ? config : [config];
|
||||
// 关联的组件也一并复制
|
||||
depService.getTarget(DepTargetType.RELATED_COMP_WHEN_COPY, DepTargetType.RELATED_COMP_WHEN_COPY)?.removeDep();
|
||||
depService.clearByType(DepTargetType.RELATED_COMP_WHEN_COPY);
|
||||
depService.collect(copyNodes, true, DepTargetType.RELATED_COMP_WHEN_COPY);
|
||||
const customTarget = depService.getTarget(
|
||||
DepTargetType.RELATED_COMP_WHEN_COPY,
|
||||
|
Loading…
x
Reference in New Issue
Block a user