diff --git a/packages/x6/src/graph/view.ts b/packages/x6/src/graph/view.ts
index 165e233fb0b..1923f1942a5 100644
--- a/packages/x6/src/graph/view.ts
+++ b/packages/x6/src/graph/view.ts
@@ -18,6 +18,11 @@ export class GraphView extends View {
private restore: () => void
+ /** Graph's `this.container` is from outer, should not dispose */
+ protected get disposeContainer(): boolean {
+ return false
+ }
+
protected get options() {
return this.graph.options
}
diff --git a/packages/x6/src/view/view.ts b/packages/x6/src/view/view.ts
index 9e942243a7f..d6d255884de 100644
--- a/packages/x6/src/view/view.ts
+++ b/packages/x6/src/view/view.ts
@@ -13,6 +13,11 @@ export abstract class View extends Basecoat {
return 2
}
+ /** If need remove `this.container` DOM */
+ protected get disposeContainer() {
+ return true
+ }
+
constructor() {
super()
this.cid = Private.uniqueId()
@@ -39,8 +44,12 @@ export abstract class View extends Basecoat {
this.removeEventListeners(document)
this.onRemove()
delete View.views[this.cid]
+ if (this.disposeContainer) {
+ this.unmount(elem)
+ }
+ } else {
+ this.unmount(elem)
}
- this.unmount(elem)
return this
}
@@ -363,10 +372,10 @@ export abstract class View extends Basecoat {
return View.normalizeEvent(evt)
}
- // @View.dispose()
- // dispose() {
- // this.remove()
- // }
+ @View.dispose()
+ dispose() {
+ this.remove()
+ }
}
export namespace View {