1
0
mirror of synced 2025-12-11 04:07:55 +08:00

feat(editor): 复制组件时收集依赖性能优化改造

This commit is contained in:
parisma
2024-05-30 15:22:41 +08:00
committed by roymondchen
parent 50d238a48c
commit cd191f6815
8 changed files with 28 additions and 47 deletions

View File

@@ -114,7 +114,12 @@ export default class Watcher {
* @param deep 是否需要收集子节点
* @param type 强制收集指定类型的依赖
*/
public collect(nodes: TargetNode[], depExtendedData: DepExtendedData = {}, deep = false, type?: DepTargetType) {
public collect(
nodes: TargetNode[],
depExtendedData: DepExtendedData = {},
deep = false,
type?: DepTargetType | string,
) {
this.collectByCallback(nodes, type, ({ node, target }) => {
this.removeTargetDep(target, node);
this.collectItem(node, target, depExtendedData, deep);
@@ -123,7 +128,7 @@ export default class Watcher {
public collectByCallback(
nodes: TargetNode[],
type: DepTargetType | undefined,
type: DepTargetType | string | undefined,
cb: (data: { node: TargetNode; target: Target }) => void,
) {
traverseTarget(
@@ -144,7 +149,7 @@ export default class Watcher {
* 清除所有目标的依赖
* @param nodes 需要清除依赖的节点
*/
public clear(nodes?: TargetNode[], type?: DepTargetType) {
public clear(nodes?: TargetNode[], type?: DepTargetType | string) {
let { targetsList } = this;
if (type) {
@@ -179,7 +184,7 @@ export default class Watcher {
* @param type 类型
* @param nodes 需要清除依赖的节点
*/
public clearByType(type: DepTargetType, nodes?: TargetNode[]) {
public clearByType(type: DepTargetType | string, nodes?: TargetNode[]) {
this.clear(nodes, type);
}

View File

@@ -28,14 +28,6 @@ export interface TargetOptions {
isCollectByDefault?: boolean;
}
export interface CustomTargetOptions {
isTarget: IsTarget;
name?: string;
initialDeps?: DepData;
/** 是否默认收集默认为true当值为false时需要传入type参数给collect方法才会被收集 */
isCollectByDefault?: boolean;
}
export interface TargetList {
[type: string]: {
[targetId: string | number]: Target;

View File

@@ -193,7 +193,11 @@ export const createDataSourceMethodTarget = (ds: DataSourceSchema, initialDeps:
},
});
export const traverseTarget = (targetsList: TargetList, cb: (target: Target) => void, type?: DepTargetType) => {
export const traverseTarget = (
targetsList: TargetList,
cb: (target: Target) => void,
type?: DepTargetType | string,
) => {
Object.values(targetsList).forEach((targets) => {
Object.values(targets).forEach((target) => {
if (type && target.type !== type) {