UNPKG

4.67 kBTypeScriptView Raw
1import { IterableOrArrayLike } from '@phosphor/algorithm';
2import { ISignal } from '@phosphor/signaling';
3/**
4 * An object which implements the disposable pattern.
5 */
6export interface IDisposable {
7 /**
8 * Test whether the object has been disposed.
9 *
10 * #### Notes
11 * This property is always safe to access.
12 */
13 readonly isDisposed: boolean;
14 /**
15 * Dispose of the resources held by the object.
16 *
17 * #### Notes
18 * If the object's `dispose` method is called more than once, all
19 * calls made after the first will be a no-op.
20 *
21 * #### Undefined Behavior
22 * It is undefined behavior to use any functionality of the object
23 * after it has been disposed unless otherwise explicitly noted.
24 */
25 dispose(): void;
26}
27/**
28 * A disposable object with an observable `disposed` signal.
29 */
30export interface IObservableDisposable extends IDisposable {
31 /**
32 * A signal emitted when the object is disposed.
33 */
34 readonly disposed: ISignal<this, void>;
35}
36/**
37 * A disposable object which delegates to a callback function.
38 */
39export declare class DisposableDelegate implements IDisposable {
40 /**
41 * Construct a new disposable delegate.
42 *
43 * @param fn - The callback function to invoke on dispose.
44 */
45 constructor(fn: () => void);
46 /**
47 * Test whether the delegate has been disposed.
48 */
49 readonly isDisposed: boolean;
50 /**
51 * Dispose of the delegate and invoke the callback function.
52 */
53 dispose(): void;
54 private _fn;
55}
56/**
57 * An observable disposable object which delegates to a callback function.
58 */
59export declare class ObservableDisposableDelegate extends DisposableDelegate implements IObservableDisposable {
60 /**
61 * A signal emitted when the delegate is disposed.
62 */
63 readonly disposed: ISignal<this, void>;
64 /**
65 * Dispose of the delegate and invoke the callback function.
66 */
67 dispose(): void;
68 private _disposed;
69}
70/**
71 * An object which manages a collection of disposable items.
72 */
73export declare class DisposableSet implements IDisposable {
74 /**
75 * Construct a new disposable set.
76 */
77 constructor();
78 /**
79 * Test whether the set has been disposed.
80 */
81 readonly isDisposed: boolean;
82 /**
83 * Dispose of the set and the items it contains.
84 *
85 * #### Notes
86 * Items are disposed in the order they are added to the set.
87 */
88 dispose(): void;
89 /**
90 * Test whether the set contains a specific item.
91 *
92 * @param item - The item of interest.
93 *
94 * @returns `true` if the set contains the item, `false` otherwise.
95 */
96 contains(item: IDisposable): boolean;
97 /**
98 * Add a disposable item to the set.
99 *
100 * @param item - The item to add to the set.
101 *
102 * #### Notes
103 * If the item is already contained in the set, this is a no-op.
104 */
105 add(item: IDisposable): void;
106 /**
107 * Remove a disposable item from the set.
108 *
109 * @param item - The item to remove from the set.
110 *
111 * #### Notes
112 * If the item is not contained in the set, this is a no-op.
113 */
114 remove(item: IDisposable): void;
115 /**
116 * Remove all items from the set.
117 */
118 clear(): void;
119 private _isDisposed;
120 private _items;
121}
122/**
123 * The namespace for the `DisposableSet` class statics.
124 */
125export declare namespace DisposableSet {
126 /**
127 * Create a disposable set from an iterable of items.
128 *
129 * @param items - The iterable or array-like object of interest.
130 *
131 * @returns A new disposable initialized with the given items.
132 */
133 function from(items: IterableOrArrayLike<IDisposable>): DisposableSet;
134}
135/**
136 * An observable object which manages a collection of disposable items.
137 */
138export declare class ObservableDisposableSet extends DisposableSet implements IObservableDisposable {
139 /**
140 * A signal emitted when the set is disposed.
141 */
142 readonly disposed: ISignal<this, void>;
143 /**
144 * Dispose of the set and the items it contains.
145 *
146 * #### Notes
147 * Items are disposed in the order they are added to the set.
148 */
149 dispose(): void;
150 private _disposed;
151}
152/**
153 * The namespace for the `ObservableDisposableSet` class statics.
154 */
155export declare namespace ObservableDisposableSet {
156 /**
157 * Create an observable disposable set from an iterable of items.
158 *
159 * @param items - The iterable or array-like object of interest.
160 *
161 * @returns A new disposable initialized with the given items.
162 */
163 function from(items: IterableOrArrayLike<IDisposable>): ObservableDisposableSet;
164}