Skip to main content

DisposableStore

Defined in: src/lib/disposable.ts:43

A container that manages multiple disposables. Useful for collecting event subscriptions and other cleanup tasks in a module. Supports nesting: a DisposableStore can be added to another DisposableStore.

Implements both our IDisposable and native TypeScript Disposable interfaces.

Implements

Constructors

Constructor

new DisposableStore(): DisposableStore;

Returns

DisposableStore

Accessors

disposed

Get Signature

get disposed(): boolean;

Defined in: src/lib/disposable.ts:113

Check if the store has been disposed.

Returns

boolean


size

Get Signature

get size(): number;

Defined in: src/lib/disposable.ts:120

The number of disposables currently in the store.

Returns

number

Methods

[dispose]()

dispose: void;

Defined in: src/lib/disposable.ts:98

Native TypeScript Disposable support. Allows use with using declarations.

Returns

void

Implementation of

Disposable.[dispose]

add()

add\<T\>(disposable: T): T;

Defined in: src/lib/disposable.ts:52

Add a disposable to the store. If the store is already disposed, the disposable will be disposed immediately.

Type Parameters

Type Parameter
T extends IDisposable

Parameters

ParameterType
disposableT

Returns

T

The same disposable for chaining.


clear()

clear(): void;

Defined in: src/lib/disposable.ts:106

Clear the store without disposing the items. Use this if you want to transfer ownership of disposables elsewhere.

Returns

void


createChild()

createChild(): DisposableStore;

Defined in: src/lib/disposable.ts:74

Create a child DisposableStore that is automatically added to this store. When this store is disposed, the child will also be disposed. Useful for temporary features or scoped cleanup.

Returns

DisposableStore

Example

const root = new DisposableStore();
const feature = root.createChild();
feature.add(someEvent.on(() => { ... }));
// Later: root.dispose() will also dispose feature

dispose()

dispose(): void;

Defined in: src/lib/disposable.ts:84

Dispose all stored disposables and mark the store as disposed. Further calls to add() will immediately dispose the added item.

Returns

void

Implementation of

IDisposable.dispose