diff --git a/src/components/TreeReactFlow/dispose.ts b/src/components/TreeReactFlow/dispose.ts deleted file mode 100644 index a8ffa118..00000000 --- a/src/components/TreeReactFlow/dispose.ts +++ /dev/null @@ -1,45 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -export interface IDisposable { - dispose(): void; -} - -export function disposeAll(disposables: IDisposable[]) { - while (disposables.length) { - const item = disposables.pop(); - if (item) { - item.dispose(); - } - } -} - -export abstract class Disposable { - private _isDisposed = false; - - protected _disposables: IDisposable[] = []; - - // eslint-disable-next-line @typescript-eslint/no-explicit-any - public dispose(): any { - if (this._isDisposed) { - return; - } - this._isDisposed = true; - disposeAll(this._disposables); - } - - protected _register(value: T): T { - if (this._isDisposed) { - value.dispose(); - } else { - this._disposables.push(value); - } - return value; - } - - protected get isDisposed() { - return this._isDisposed; - } -} diff --git a/src/components/TreeReactFlow/layoutTree.ts b/src/components/TreeReactFlow/layoutTree.ts index 5c8f22b6..9be13074 100644 --- a/src/components/TreeReactFlow/layoutTree.ts +++ b/src/components/TreeReactFlow/layoutTree.ts @@ -35,7 +35,7 @@ export const layoutTree = < const [treeTidy0, nodeInfos, edgeInfos] = primerToTidy(primerTree); const treeTidy = layout.set_root(treeTidy0); layout.layout(true); - layout.dispose(); + layout[Symbol.dispose](); const nodeMap = makeNodeMap( nodeInfos, edgeInfos, diff --git a/src/components/TreeReactFlow/tidy.ts b/src/components/TreeReactFlow/tidy.ts index 1230be96..dc737cd7 100644 --- a/src/components/TreeReactFlow/tidy.ts +++ b/src/components/TreeReactFlow/tidy.ts @@ -31,7 +31,6 @@ import { Tidy as TidyWasm, WasmLayoutType as LayoutType, } from "@hackworthltd/tidyt-wasm"; -import { Disposable } from "./dispose"; export { LayoutType }; @@ -73,7 +72,7 @@ const NULL_ID = () => { } return nullId; }; -export class TidyLayout extends Disposable { +export class TidyLayout implements Disposable { private tidy: TidyWasm; private nextId = 1; private root: InnerNode | undefined; @@ -91,7 +90,6 @@ export class TidyLayout extends Disposable { parent_child_margin: number, peer_margin: number ) { - super(); if (type === LayoutType.Basic) { this.tidy = TidyWasm.with_basic_layout(parent_child_margin, peer_margin); } else if (type === LayoutType.Tidy) { @@ -101,11 +99,10 @@ export class TidyLayout extends Disposable { } else { throw new Error("not implemented"); } - this._register({ - dispose: () => { - this.tidy.free(); - }, - }); + } + + [Symbol.dispose]() { + this.tidy.free(); } changeLayoutType(type: LayoutType) {