mirror of
https://gitee.com/antv/g6.git
synced 2024-11-29 18:28:19 +08:00
refactor: emit graph destroy event (#5680)
This commit is contained in:
parent
5028413d0f
commit
63261258cf
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@ -3,6 +3,7 @@
|
||||
"AABB",
|
||||
"afteranimate",
|
||||
"aftercanvasinit",
|
||||
"afterdestroy",
|
||||
"afterdraw",
|
||||
"afterelementcreate",
|
||||
"afterelementdestroy",
|
||||
@ -20,6 +21,7 @@
|
||||
"bbox",
|
||||
"beforeanimate",
|
||||
"beforecanvasinit",
|
||||
"beforedestroy",
|
||||
"beforedraw",
|
||||
"beforeelementcreate",
|
||||
"beforeelementdestroy",
|
||||
|
@ -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',
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user