Skip to content

Commit

Permalink
refactor: adjust destroy clean-up logic (#1853)
Browse files Browse the repository at this point in the history
* refactor: adjust destroy clean-up logic

* chore: commit changeset
  • Loading branch information
Aarebecca authored Nov 27, 2024
1 parent 6f347e4 commit 8159c66
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/empty-falcons-occur.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@antv/g-lite': patch
---

refactor: adjust destroy clean-up logic
2 changes: 1 addition & 1 deletion __tests__/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ plot();
async function plot() {
if (currentContainer) {
currentContainer.remove();
if (canvas) canvas.destroy();
if (canvas) canvas.destroy(false);
if (prevAfter) prevAfter();
}
currentContainer = document.createElement('div');
Expand Down
12 changes: 5 additions & 7 deletions packages/g-lite/src/Canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,12 +394,10 @@ export class Canvas extends EventTarget implements ICanvas {
}

/**
* `cleanUp` means clean all the internal services of Canvas which happens when calling `canvas.destroy()`.
* @param cleanUp - whether to clean up all the internal services of Canvas
* @param skipTriggerEvent - whether to skip trigger destroy event
*/
destroy(cleanUp = true, skipTriggerEvent?: boolean) {
if (skipTriggerEvent === undefined)
skipTriggerEvent = this.getConfig().fastCleanExistingCanvas;

if (!skipTriggerEvent) {
this.dispatchEvent(new CustomEvent(CanvasEvent.BEFORE_DESTROY));
}
Expand All @@ -409,9 +407,9 @@ export class Canvas extends EventTarget implements ICanvas {

// unmount all children
const root = this.getRoot();
this.unmountChildren(root);

if (cleanUp) {
this.unmountChildren(root);
// destroy Document
this.document.destroy();
this.getEventService().destroy();
Expand All @@ -421,8 +419,8 @@ export class Canvas extends EventTarget implements ICanvas {
this.getRenderingService().destroy();
this.getContextService().destroy();

// clear root after renderservice destroyed
if (cleanUp && this.context.rBushRoot) {
// clear root after render service destroyed
if (this.context.rBushRoot) {
// clear rbush
this.context.rBushRoot.clear();
this.context.rBushRoot = null;
Expand Down

0 comments on commit 8159c66

Please sign in to comment.