1 | (function (global, factory) {
|
2 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@lumino/algorithm'), require('@lumino/signaling')) :
|
3 | typeof define === 'function' && define.amd ? define(['exports', '@lumino/algorithm', '@lumino/signaling'], factory) :
|
4 | (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.lumino_disposable = {}, global.lumino_algorithm, global.lumino_signaling));
|
5 | }(this, (function (exports, algorithm, signaling) { 'use strict';
|
6 |
|
7 | /*! *****************************************************************************
|
8 | Copyright (c) Microsoft Corporation.
|
9 |
|
10 | Permission to use, copy, modify, and/or distribute this software for any
|
11 | purpose with or without fee is hereby granted.
|
12 |
|
13 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
14 | REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
15 | AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
16 | INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
17 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
18 | OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
19 | PERFORMANCE OF THIS SOFTWARE.
|
20 | ***************************************************************************** */
|
21 | /* global Reflect, Promise */
|
22 |
|
23 | var extendStatics = function(d, b) {
|
24 | extendStatics = Object.setPrototypeOf ||
|
25 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
26 | function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
27 | return extendStatics(d, b);
|
28 | };
|
29 |
|
30 | function __extends(d, b) {
|
31 | if (typeof b !== "function" && b !== null)
|
32 | throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
33 | extendStatics(d, b);
|
34 | function __() { this.constructor = d; }
|
35 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
36 | }
|
37 |
|
38 | /**
|
39 | * A disposable object which delegates to a callback function.
|
40 | */
|
41 | var DisposableDelegate = /** @class */ (function () {
|
42 | /**
|
43 | * Construct a new disposable delegate.
|
44 | *
|
45 | * @param fn - The callback function to invoke on dispose.
|
46 | */
|
47 | function DisposableDelegate(fn) {
|
48 | this._fn = fn;
|
49 | }
|
50 | Object.defineProperty(DisposableDelegate.prototype, "isDisposed", {
|
51 | /**
|
52 | * Test whether the delegate has been disposed.
|
53 | */
|
54 | get: function () {
|
55 | return !this._fn;
|
56 | },
|
57 | enumerable: true,
|
58 | configurable: true
|
59 | });
|
60 | /**
|
61 | * Dispose of the delegate and invoke the callback function.
|
62 | */
|
63 | DisposableDelegate.prototype.dispose = function () {
|
64 | if (!this._fn) {
|
65 | return;
|
66 | }
|
67 | var fn = this._fn;
|
68 | this._fn = null;
|
69 | fn();
|
70 | };
|
71 | return DisposableDelegate;
|
72 | }());
|
73 | /**
|
74 | * An observable disposable object which delegates to a callback function.
|
75 | */
|
76 | var ObservableDisposableDelegate = /** @class */ (function (_super) {
|
77 | __extends(ObservableDisposableDelegate, _super);
|
78 | function ObservableDisposableDelegate() {
|
79 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
80 | _this._disposed = new signaling.Signal(_this);
|
81 | return _this;
|
82 | }
|
83 | Object.defineProperty(ObservableDisposableDelegate.prototype, "disposed", {
|
84 | /**
|
85 | * A signal emitted when the delegate is disposed.
|
86 | */
|
87 | get: function () {
|
88 | return this._disposed;
|
89 | },
|
90 | enumerable: true,
|
91 | configurable: true
|
92 | });
|
93 | /**
|
94 | * Dispose of the delegate and invoke the callback function.
|
95 | */
|
96 | ObservableDisposableDelegate.prototype.dispose = function () {
|
97 | if (this.isDisposed) {
|
98 | return;
|
99 | }
|
100 | _super.prototype.dispose.call(this);
|
101 | this._disposed.emit(undefined);
|
102 | signaling.Signal.clearData(this);
|
103 | };
|
104 | return ObservableDisposableDelegate;
|
105 | }(DisposableDelegate));
|
106 | /**
|
107 | * An object which manages a collection of disposable items.
|
108 | */
|
109 | exports.DisposableSet = /** @class */ (function () {
|
110 | function DisposableSet() {
|
111 | this._isDisposed = false;
|
112 | this._items = new Set();
|
113 | }
|
114 | Object.defineProperty(DisposableSet.prototype, "isDisposed", {
|
115 | /**
|
116 | * Test whether the set has been disposed.
|
117 | */
|
118 | get: function () {
|
119 | return this._isDisposed;
|
120 | },
|
121 | enumerable: true,
|
122 | configurable: true
|
123 | });
|
124 | /**
|
125 | * Dispose of the set and the items it contains.
|
126 | *
|
127 | * #### Notes
|
128 | * Items are disposed in the order they are added to the set.
|
129 | */
|
130 | DisposableSet.prototype.dispose = function () {
|
131 | if (this._isDisposed) {
|
132 | return;
|
133 | }
|
134 | this._isDisposed = true;
|
135 | this._items.forEach(function (item) {
|
136 | item.dispose();
|
137 | });
|
138 | this._items.clear();
|
139 | };
|
140 | /**
|
141 | * Test whether the set contains a specific item.
|
142 | *
|
143 | * @param item - The item of interest.
|
144 | *
|
145 | * @returns `true` if the set contains the item, `false` otherwise.
|
146 | */
|
147 | DisposableSet.prototype.contains = function (item) {
|
148 | return this._items.has(item);
|
149 | };
|
150 | /**
|
151 | * Add a disposable item to the set.
|
152 | *
|
153 | * @param item - The item to add to the set.
|
154 | *
|
155 | * #### Notes
|
156 | * If the item is already contained in the set, this is a no-op.
|
157 | */
|
158 | DisposableSet.prototype.add = function (item) {
|
159 | this._items.add(item);
|
160 | };
|
161 | /**
|
162 | * Remove a disposable item from the set.
|
163 | *
|
164 | * @param item - The item to remove from the set.
|
165 | *
|
166 | * #### Notes
|
167 | * If the item is not contained in the set, this is a no-op.
|
168 | */
|
169 | DisposableSet.prototype.remove = function (item) {
|
170 | this._items.delete(item);
|
171 | };
|
172 | /**
|
173 | * Remove all items from the set.
|
174 | */
|
175 | DisposableSet.prototype.clear = function () {
|
176 | this._items.clear();
|
177 | };
|
178 | return DisposableSet;
|
179 | }());
|
180 | /**
|
181 | * The namespace for the `DisposableSet` class statics.
|
182 | */
|
183 | (function (DisposableSet) {
|
184 | /**
|
185 | * Create a disposable set from an iterable of items.
|
186 | *
|
187 | * @param items - The iterable or array-like object of interest.
|
188 | *
|
189 | * @returns A new disposable initialized with the given items.
|
190 | */
|
191 | function from(items) {
|
192 | var set = new DisposableSet();
|
193 | algorithm.each(items, function (item) {
|
194 | set.add(item);
|
195 | });
|
196 | return set;
|
197 | }
|
198 | DisposableSet.from = from;
|
199 | })(exports.DisposableSet || (exports.DisposableSet = {}));
|
200 | /**
|
201 | * An observable object which manages a collection of disposable items.
|
202 | */
|
203 | exports.ObservableDisposableSet = /** @class */ (function (_super) {
|
204 | __extends(ObservableDisposableSet, _super);
|
205 | function ObservableDisposableSet() {
|
206 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
207 | _this._disposed = new signaling.Signal(_this);
|
208 | return _this;
|
209 | }
|
210 | Object.defineProperty(ObservableDisposableSet.prototype, "disposed", {
|
211 | /**
|
212 | * A signal emitted when the set is disposed.
|
213 | */
|
214 | get: function () {
|
215 | return this._disposed;
|
216 | },
|
217 | enumerable: true,
|
218 | configurable: true
|
219 | });
|
220 | /**
|
221 | * Dispose of the set and the items it contains.
|
222 | *
|
223 | * #### Notes
|
224 | * Items are disposed in the order they are added to the set.
|
225 | */
|
226 | ObservableDisposableSet.prototype.dispose = function () {
|
227 | if (this.isDisposed) {
|
228 | return;
|
229 | }
|
230 | _super.prototype.dispose.call(this);
|
231 | this._disposed.emit(undefined);
|
232 | signaling.Signal.clearData(this);
|
233 | };
|
234 | return ObservableDisposableSet;
|
235 | }(exports.DisposableSet));
|
236 | /**
|
237 | * The namespace for the `ObservableDisposableSet` class statics.
|
238 | */
|
239 | (function (ObservableDisposableSet) {
|
240 | /**
|
241 | * Create an observable disposable set from an iterable of items.
|
242 | *
|
243 | * @param items - The iterable or array-like object of interest.
|
244 | *
|
245 | * @returns A new disposable initialized with the given items.
|
246 | */
|
247 | function from(items) {
|
248 | var set = new ObservableDisposableSet();
|
249 | algorithm.each(items, function (item) {
|
250 | set.add(item);
|
251 | });
|
252 | return set;
|
253 | }
|
254 | ObservableDisposableSet.from = from;
|
255 | })(exports.ObservableDisposableSet || (exports.ObservableDisposableSet = {}));
|
256 |
|
257 | exports.DisposableDelegate = DisposableDelegate;
|
258 | exports.ObservableDisposableDelegate = ObservableDisposableDelegate;
|
259 |
|
260 | Object.defineProperty(exports, '__esModule', { value: true });
|
261 |
|
262 | })));
|
263 | //# sourceMappingURL=index.js.map
|