diff --git a/.vscode/settings.json b/.vscode/settings.json
index caaff0a3f57..d1db4d757d6 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -3,6 +3,7 @@
"AABB",
"afteranimate",
"aftercanvasinit",
+ "afterdestroy",
"afterdraw",
"afterelementcreate",
"afterelementdestroy",
@@ -20,6 +21,7 @@
"bbox",
"beforeanimate",
"beforecanvasinit",
+ "beforedestroy",
"beforedraw",
"beforeelementcreate",
"beforeelementdestroy",
diff --git a/packages/g6/src/constants/events/graph.ts b/packages/g6/src/constants/events/graph.ts
index cb3bad35379..bc633d08a7f 100644
--- a/packages/g6/src/constants/events/graph.ts
+++ b/packages/g6/src/constants/events/graph.ts
@@ -51,4 +51,8 @@ export enum GraphEvent {
BATCH_START = 'batchstart',
/** 批处理结束 | Batch processing ends */
BATCH_END = 'batchend',
+ /** 销毁开始之前 | Before destruction */
+ BEFORE_DESTROY = 'beforedestroy',
+ /** 销毁结束之后 | After destruction */
+ AFTER_DESTROY = 'afterdestroy',
}
diff --git a/packages/g6/src/runtime/graph.ts b/packages/g6/src/runtime/graph.ts
index 151315efb5d..67682753f12 100644
--- a/packages/g6/src/runtime/graph.ts
+++ b/packages/g6/src/runtime/graph.ts
@@ -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));
}
/**
diff --git a/packages/g6/src/utils/event/events.ts b/packages/g6/src/utils/event/events.ts
index 29361a232d6..7b921581768 100644
--- a/packages/g6/src/utils/event/events.ts
+++ b/packages/g6/src/utils/event/events.ts
@@ -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);