DisposableStore
Defined in: src/lib/disposable.ts:45
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
isDisposed
Get Signature
get isDisposed(): boolean;Defined in: src/lib/disposable.ts:115
Check if the store has been disposed.
Returns
boolean
Implementation of
size
Get Signature
get size(): number;Defined in: src/lib/disposable.ts:122
The number of disposables currently in the store.
Returns
number
Methods
[dispose]()
dispose: void;Defined in: src/lib/disposable.ts:100
Native TypeScript Disposable support.
Allows use with using declarations.
Returns
void
Implementation of
IDisposable.[dispose]add()
add\<T\>(disposable: T): T;Defined in: src/lib/disposable.ts:54
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
| Parameter | Type |
|---|---|
disposable | T |
Returns
T
The same disposable for chaining.
clear()
clear(): void;Defined in: src/lib/disposable.ts:108
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:76
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 featuredispose()
dispose(): void;Defined in: src/lib/disposable.ts:86
Dispose all stored disposables and mark the store as disposed. Further calls to add() will immediately dispose the added item.
Returns
void