aboutsummaryrefslogtreecommitdiffstats
path: root/node_modules/xterm/src/common/Lifecycle.ts
diff options
context:
space:
mode:
authorAnthony Schneider <tonyschneider3@gmail.com>2022-02-11 19:40:35 -0600
committerAnthony Schneider <tonyschneider3@gmail.com>2022-02-11 19:40:35 -0600
commitb52feccdcc58c1f4583c8542632d6c026335dea7 (patch)
tree5e242dd13ed4bbfff85a07109ef826f80874e2a6 /node_modules/xterm/src/common/Lifecycle.ts
parent94862321e2e4a58e3209c037e8061f0435b3aa82 (diff)
Changed javascript to be in its own file. Began (messy) setup for terminal.
Diffstat (limited to 'node_modules/xterm/src/common/Lifecycle.ts')
-rw-r--r--node_modules/xterm/src/common/Lifecycle.ts68
1 files changed, 68 insertions, 0 deletions
diff --git a/node_modules/xterm/src/common/Lifecycle.ts b/node_modules/xterm/src/common/Lifecycle.ts
new file mode 100644
index 0000000..56bcfdc
--- /dev/null
+++ b/node_modules/xterm/src/common/Lifecycle.ts
@@ -0,0 +1,68 @@
+/**
+ * Copyright (c) 2018 The xterm.js authors. All rights reserved.
+ * @license MIT
+ */
+
+import { IDisposable } from 'common/Types';
+
+/**
+ * A base class that can be extended to provide convenience methods for managing the lifecycle of an
+ * object and its components.
+ */
+export abstract class Disposable implements IDisposable {
+ protected _disposables: IDisposable[] = [];
+ protected _isDisposed: boolean = false;
+
+ constructor() {
+ }
+
+ /**
+ * Disposes the object, triggering the `dispose` method on all registered IDisposables.
+ */
+ public dispose(): void {
+ this._isDisposed = true;
+ for (const d of this._disposables) {
+ d.dispose();
+ }
+ this._disposables.length = 0;
+ }
+
+ /**
+ * Registers a disposable object.
+ * @param d The disposable to register.
+ * @returns The disposable.
+ */
+ public register<T extends IDisposable>(d: T): T {
+ this._disposables.push(d);
+ return d;
+ }
+
+ /**
+ * Unregisters a disposable object if it has been registered, if not do
+ * nothing.
+ * @param d The disposable to unregister.
+ */
+ public unregister<T extends IDisposable>(d: T): void {
+ const index = this._disposables.indexOf(d);
+ if (index !== -1) {
+ this._disposables.splice(index, 1);
+ }
+ }
+}
+
+/**
+ * Dispose of all disposables in an array and set its length to 0.
+ */
+export function disposeArray(disposables: IDisposable[]): void {
+ for (const d of disposables) {
+ d.dispose();
+ }
+ disposables.length = 0;
+}
+
+/**
+ * Creates a disposable that will dispose of an array of disposables when disposed.
+ */
+export function getDisposeArrayDisposable(array: IDisposable[]): IDisposable {
+ return { dispose: () => disposeArray(array) };
+}