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