fix: 修正freed节点被restore样式的问题

This commit is contained in:
黎智洲 2022-03-10 15:29:33 +08:00
parent e238087f3f
commit 4bb64214e7
4 changed files with 29 additions and 28 deletions

View File

@ -6,6 +6,7 @@ import { SVLink } from '../Model/SVLink';
import { SVModel } from '../Model/SVModel';
import { SVNode } from '../Model/SVNode';
import { SVAddressLabel, SVMarker, SVNodeAppendage } from '../Model/SVNodeAppendage';
import { handleUpdate } from '../sources';
import { Animations } from './animation';
import { Renderer } from './renderer';
@ -272,7 +273,7 @@ export class Reconcile {
Animations.APPEND(item.G6Item, {
duration,
timingFunction,
callback: () => item.afterRender()
callback: () => item.afterRender(),
});
}
});
@ -422,13 +423,13 @@ export class Reconcile {
* @param diffResult
* @param isFirstRender
*/
public patch(diffResult: DiffResult,handleUpdata: any) {
public patch(diffResult: DiffResult, handleUpdate: handleUpdate) {
const { APPEND, REMOVE, FREED, LEAKED, UPDATE, CONTINUOUS, ACCUMULATE_LEAK } = diffResult;
this.handleAccumulateLeakModels(ACCUMULATE_LEAK);
// 第一次渲染和进入函数的时候不高亮变化的元素
if (this.isFirstPatch === false && !handleUpdata.isEnterFunction && !handleUpdata.isFirstDebug) {
// 第一次渲染和进入函数的时候不高亮变化的元素
if (this.isFirstPatch === false && !handleUpdate?.isEnterFunction && !handleUpdate?.isFirstDebug) {
this.handleChangeModels(UPDATE);
}

View File

@ -16,6 +16,7 @@ import {
SolveNodeAppendagesDrag,
SolveZoomCanvasWithLeak,
} from '../BehaviorHelper/behaviorIssueHelper';
import { handleUpdate } from '../sources';
export class ViewContainer {
private engine: Engine;
@ -140,13 +141,18 @@ export class ViewContainer {
* @param models
* @param layoutFn
*/
render(layoutGroupTable: LayoutGroupTable, isSameSources: boolean, handleUpdata: any) {
render(layoutGroupTable: LayoutGroupTable, isSameSources: boolean, handleUpdate: handleUpdate) {
const modelList = Util.convertGroupTable2ModelList(layoutGroupTable);
// 如果数据没变的话
// 如果数据没变的话
if (isSameSources) {
modelList.forEach(item => item.restoreHighlight());
return;
modelList.forEach(item => {
// 不是free节点才进行还原
if(!item.freed) {
item.restoreHighlight()
}
});
return;
}
const diffResult = this.reconcile.diff(
@ -154,7 +160,7 @@ export class ViewContainer {
this.prevModelList,
modelList,
this.accumulateLeakModels,
handleUpdata.isEnterFunction
handleUpdate?.isEnterFunction
),
renderModelList = [...modelList, ...diffResult.REMOVE, ...diffResult.LEAKED, ...diffResult.ACCUMULATE_LEAK];
@ -182,7 +188,7 @@ export class ViewContainer {
this.beforeRender();
this.renderer.render(renderModelList); // 渲染视图
this.reconcile.patch(diffResult,handleUpdata); // 对视图上的某些变化进行对应的动作,比如:节点创建动画,节点消失动画等
this.reconcile.patch(diffResult, handleUpdate); // 对视图上的某些变化进行对应的动作,比如:节点创建动画,节点消失动画等
this.afterRender();
this.layoutGroupTable = layoutGroupTable;

View File

@ -1,4 +1,4 @@
import { Sources } from "./sources";
import { handleUpdate, Sources } from "./sources";
import { LayoutGroupTable, ModelConstructor } from "./Model/modelConstructor";
import { AnimationOptions, BehaviorOptions, EngineOptions, LayoutGroupOptions, ViewOptions } from "./options";
import { EventBus } from "./Common/eventBus";
@ -59,7 +59,7 @@ export class Engine {
return;
}
let handleUpdate = source.handleUpdate,
let handleUpdate: handleUpdate = source.handleUpdate,
stringSource = JSON.stringify(source);
if (this.prevStringSource === stringSource) {

View File

@ -1,4 +1,3 @@
// 连接目标信息
export type LinkTarget = number | string;
@ -10,24 +9,19 @@ export type sourceMarkerData = string | string[];
// 源数据单元
export interface SourceNode {
id: string | number;
[key: string]: any | sourceLinkData | sourceMarkerData;
id: string | number;
[key: string]: any | sourceLinkData | sourceMarkerData;
}
export interface handleUpdata {
isEnterFunction: boolean,
isFirstDebug: boolean
export interface handleUpdate {
isEnterFunction: boolean;
isFirstDebug: boolean;
}
export type Sources = {
[key: string]: {
data: SourceNode[];
layouter: string;
};
handleUpdata?:any
[key: string]: {
data: SourceNode[];
layouter: string;
};
handleUpdate?: handleUpdate | any;
};