feat(editor): 复制组件时收集依赖性能优化改造
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user