UNPKG

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