refactor: emit graph destroy event (#5680)

This commit is contained in:
Aaron 2024-04-25 19:10:18 +08:00 committed by GitHub
parent 5028413d0f
commit 63261258cf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 13 additions and 1 deletions

View File

@ -3,6 +3,7 @@
"AABB",
"afteranimate",
"aftercanvasinit",
"afterdestroy",
"afterdraw",
"afterelementcreate",
"afterelementdestroy",
@ -20,6 +21,7 @@
"bbox",
"beforeanimate",
"beforecanvasinit",
"beforedestroy",
"beforedraw",
"beforeelementcreate",
"beforeelementdestroy",

View File

@ -51,4 +51,8 @@ export enum GraphEvent {
BATCH_START = 'batchstart',
/** <zh/> 批处理结束 | <en/> Batch processing ends */
BATCH_END = 'batchend',
/** <zh/> 销毁开始之前 | <en/> Before destruction */
BEFORE_DESTROY = 'beforedestroy',
/** <zh/> 销毁结束之后 | <en/> After destruction */
AFTER_DESTROY = 'afterdestroy',
}

View File

@ -929,6 +929,8 @@ export class Graph extends EventEmitter {
* @apiCategory instance
*/
public destroy(): void {
emit(this, new GraphLifeCycleEvent(GraphEvent.BEFORE_DESTROY));
const { layout, element, model, canvas, behavior, plugin } = this.context;
plugin?.destroy();
behavior?.destroy();
@ -944,6 +946,8 @@ export class Graph extends EventEmitter {
window.removeEventListener('resize', this.onResize);
this.destroyed = true;
emit(this, new GraphLifeCycleEvent(GraphEvent.AFTER_DESTROY));
}
/**

View File

@ -26,7 +26,9 @@ export class GraphLifeCycleEvent extends BaseEvent implements IGraphLifeCycleEve
| GraphEvent.BEFORE_SIZE_CHANGE
| GraphEvent.AFTER_SIZE_CHANGE
| GraphEvent.BATCH_START
| GraphEvent.BATCH_END,
| GraphEvent.BATCH_END
| GraphEvent.BEFORE_DESTROY
| GraphEvent.AFTER_DESTROY,
public data?: any,
) {
super(type);