@itwin/core-bentley 5.15.0-dev.7 → 5.16.0-dev.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -1
- package/lib/cjs/BeEvent.d.ts +93 -2
- package/lib/cjs/BeEvent.d.ts.map +1 -1
- package/lib/cjs/BeEvent.js +114 -29
- package/lib/cjs/BeEvent.js.map +1 -1
- package/lib/cjs/Id.d.ts +5 -5
- package/lib/cjs/Id.d.ts.map +1 -1
- package/lib/cjs/Id.js +7 -5
- package/lib/cjs/Id.js.map +1 -1
- package/lib/esm/BeEvent.d.ts +93 -2
- package/lib/esm/BeEvent.d.ts.map +1 -1
- package/lib/esm/BeEvent.js +112 -28
- package/lib/esm/BeEvent.js.map +1 -1
- package/lib/esm/Id.d.ts +5 -5
- package/lib/esm/Id.d.ts.map +1 -1
- package/lib/esm/Id.js +7 -5
- package/lib/esm/Id.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
# Change Log - @itwin/core-bentley
|
|
2
2
|
|
|
3
|
-
This log was last generated on Tue,
|
|
3
|
+
This log was last generated on Tue, 27 Oct 2026 12:20:35 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 5.14.5
|
|
6
|
+
Tue, 27 Oct 2026 12:19:48 GMT
|
|
7
|
+
|
|
8
|
+
_Version update only_
|
|
9
|
+
|
|
10
|
+
## 5.14.4
|
|
11
|
+
Fri, 23 Oct 2026 19:58:24 GMT
|
|
12
|
+
|
|
13
|
+
_Version update only_
|
|
14
|
+
|
|
15
|
+
## 5.14.3
|
|
16
|
+
Mon, 12 Oct 2026 17:37:54 GMT
|
|
17
|
+
|
|
18
|
+
_Version update only_
|
|
4
19
|
|
|
5
20
|
## 5.14.2
|
|
6
21
|
Tue, 06 Oct 2026 19:48:29 GMT
|
package/lib/cjs/BeEvent.d.ts
CHANGED
|
@@ -5,6 +5,11 @@
|
|
|
5
5
|
* @public
|
|
6
6
|
*/
|
|
7
7
|
export type Listener = (...arg: any[]) => void;
|
|
8
|
+
/**
|
|
9
|
+
* A function invoked when a BeAsyncEvent is raised.
|
|
10
|
+
* @beta
|
|
11
|
+
*/
|
|
12
|
+
export type AsyncListener = (...arg: any[]) => Promise<void>;
|
|
8
13
|
/**
|
|
9
14
|
* Manages a set of *listeners* for a particular event and notifies them when the event is raised.
|
|
10
15
|
* This class is usually instantiated inside of a container class and
|
|
@@ -74,8 +79,6 @@ export declare class BeUiEvent<TEventArgs> extends BeEvent<(args: TEventArgs) =>
|
|
|
74
79
|
*/
|
|
75
80
|
export declare class BeUnorderedEvent<T extends Listener> {
|
|
76
81
|
private _listeners;
|
|
77
|
-
private _emitDepth;
|
|
78
|
-
private _hasTombstones;
|
|
79
82
|
/** The number of listeners currently subscribed to the event.
|
|
80
83
|
* @note During `raiseEvent()`, this may include listeners that have been removed or are one-shot
|
|
81
84
|
* but are awaiting deferred cleanup. The count is accurate outside of `raiseEvent()`.
|
|
@@ -115,6 +118,93 @@ export declare class BeUnorderedUiEvent<TEventArgs> extends BeUnorderedEvent<(ar
|
|
|
115
118
|
/** Raises event with single strongly typed argument. */
|
|
116
119
|
emit(args: TEventArgs): void;
|
|
117
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Options for configuring the behavior of a BeAsyncEvent.
|
|
123
|
+
* @beta
|
|
124
|
+
*/
|
|
125
|
+
interface BeAsyncEventOptions {
|
|
126
|
+
/**
|
|
127
|
+
* If true, listeners will be invoked concurrently rather than in series. The listeners will all be invoked
|
|
128
|
+
* immediately, and the Promise returned by [[BeAsyncEvent.raiseEvent]] will be invoked after all listeners'
|
|
129
|
+
* Promises have resolved.
|
|
130
|
+
*
|
|
131
|
+
* If false, [[BeAsyncEvent.raiseEvent]] will wait for each listener's Promise to resolve before invoking the
|
|
132
|
+
* next listener.
|
|
133
|
+
*
|
|
134
|
+
* Note that "concurrent" does not necessarily imply the use of multiple threads.
|
|
135
|
+
* It just means that the next listener is invoked before the Promise returned by
|
|
136
|
+
* the previous listener has resolved.
|
|
137
|
+
*/
|
|
138
|
+
concurrent?: boolean;
|
|
139
|
+
/**
|
|
140
|
+
* If true, and a listener rejects its returned Promise, [[UnexpectedError.handle]] is invoked
|
|
141
|
+
* and the error is otherwise ignored; the Promise returned by [[BeAsyncEvent.raiseEvent]] will only
|
|
142
|
+
* reject if [[UnexpectedError.handle]] itself throws an exception.
|
|
143
|
+
*
|
|
144
|
+
* If false or unspecified, promise rejection is considered normal, so [[UnexpectedError.handle]] is not
|
|
145
|
+
* invoked. Instead, the Promise returned by [[BeAsyncEvent.raiseEvent]] will reject. If [[concurrent]] is true,
|
|
146
|
+
* all listener Promises are awaited before the rejection is propagated, so all listeners run to completion.
|
|
147
|
+
* If [[concurrent]] is false, the rejection is propagated immediately after the first listener's Promise rejects,
|
|
148
|
+
* and subsequent listeners are not invoked.
|
|
149
|
+
*/
|
|
150
|
+
promiseRejectionIsUnexpected?: boolean;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Manages a set of *listeners* for a particular event and notifies them when the event is raised.
|
|
154
|
+
* Each listener is async (return a Promise<void>). The listeners may be invoked in series
|
|
155
|
+
* or concurrently depending on the configuration of the instance.
|
|
156
|
+
*
|
|
157
|
+
* Like [[BeUnorderedEvent]], this class uses a `Set` internally to support more performant removal
|
|
158
|
+
* of old listeners. When a listener is removed during emit, it is marked for deferred removal instead
|
|
159
|
+
* of mutating the set immediately. Despite the "unordered" implication, items in a `Set` are enumerated
|
|
160
|
+
* in insertion order, which means that this class invokes the listeners in insertion order.
|
|
161
|
+
*
|
|
162
|
+
* Listeners are managed exclusively through the disposal closure returned by [[addListener]] and
|
|
163
|
+
* [[addOnce]]. There is no `removeListener` or `has` method — callers must capture the returned
|
|
164
|
+
* closure to unsubscribe.
|
|
165
|
+
* @beta
|
|
166
|
+
*/
|
|
167
|
+
export declare class BeAsyncEvent<T extends AsyncListener> {
|
|
168
|
+
private _listeners;
|
|
169
|
+
private _concurrent;
|
|
170
|
+
private _promiseRejectionIsUnexpected;
|
|
171
|
+
constructor(options?: BeAsyncEventOptions);
|
|
172
|
+
/** The number of listeners currently subscribed to the event.
|
|
173
|
+
* @note During `raiseEvent()`, this may include listeners that have been removed or are one-shot
|
|
174
|
+
* but are awaiting deferred cleanup. The count is accurate outside of `raiseEvent()`.
|
|
175
|
+
*/
|
|
176
|
+
get numberOfListeners(): number;
|
|
177
|
+
/**
|
|
178
|
+
* Registers a Listener to be executed whenever this event is raised.
|
|
179
|
+
* @param listener The function to be executed when the event is raised.
|
|
180
|
+
* @param scope An optional object scope to serve as the 'this' pointer when listener is invoked.
|
|
181
|
+
* @returns A function that will remove this event listener in O(1).
|
|
182
|
+
*/
|
|
183
|
+
addListener(listener: T, scope?: any): () => void;
|
|
184
|
+
/**
|
|
185
|
+
* Registers a callback function to be executed *only once* when the event is raised.
|
|
186
|
+
* @param listener The function to be executed once when the event is raised.
|
|
187
|
+
* @param scope An optional object scope to serve as the `this` pointer in which the listener function will execute.
|
|
188
|
+
* @returns A function that will remove this event listener in O(1).
|
|
189
|
+
*/
|
|
190
|
+
addOnce(listener: T, scope?: any): () => void;
|
|
191
|
+
/** Remove a specific context entry, deferring during emit. */
|
|
192
|
+
private _removeCtx;
|
|
193
|
+
/**
|
|
194
|
+
* Raises the event by calling each registered listener with the supplied arguments.
|
|
195
|
+
*
|
|
196
|
+
* See [[BeAsyncEventOptions]] for options that control the behavior of this method.
|
|
197
|
+
*
|
|
198
|
+
* @param args This method takes any number of parameters and passes them through to the listeners.
|
|
199
|
+
* @returns A Promise that settles when the event invocation is complete.
|
|
200
|
+
*/
|
|
201
|
+
raiseEvent(...args: Parameters<T>): Promise<void>;
|
|
202
|
+
/** Clear all listeners from this BeAsyncEvent.
|
|
203
|
+
* @note If called during `raiseEvent`, remaining listeners in the current iteration are skipped
|
|
204
|
+
* immediately rather than being tombstoned.
|
|
205
|
+
*/
|
|
206
|
+
clear(): void;
|
|
207
|
+
}
|
|
118
208
|
/**
|
|
119
209
|
* A list of BeEvent objects, accessible by an event name.
|
|
120
210
|
* This class may be used instead of explicitly declaring each BeEvent as a member of a containing class.
|
|
@@ -150,4 +240,5 @@ export type ListenerType<TEvent extends {
|
|
|
150
240
|
}> = TEvent extends {
|
|
151
241
|
addListener(listener: infer TListener): () => void;
|
|
152
242
|
} ? TListener : never;
|
|
243
|
+
export {};
|
|
153
244
|
//# sourceMappingURL=BeEvent.d.ts.map
|
package/lib/cjs/BeEvent.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BeEvent.d.ts","sourceRoot":"","sources":["../../src/BeEvent.ts"],"names":[],"mappings":"AAIA;;GAEG;AAIH;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"BeEvent.d.ts","sourceRoot":"","sources":["../../src/BeEvent.ts"],"names":[],"mappings":"AAIA;;GAEG;AAIH;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;AAE/C;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAQ7D;;;;;GAKG;AACH,qBAAa,OAAO,CAAC,CAAC,SAAS,QAAQ;IACrC,OAAO,CAAC,UAAU,CAAsB;IACxC,OAAO,CAAC,UAAU,CAAa;IAE/B,iEAAiE;IACjE,IAAW,iBAAiB,WAAqC;IAEjE;;;;;;OAMG;IACI,WAAW,CAAC,QAAQ,EAAE,CAAC,EAAE,KAAK,CAAC,EAAE,GAAG,GAAG,MAAM,IAAI;IAKxD;;;;;;OAMG;IACI,OAAO,CAAC,QAAQ,EAAE,CAAC,EAAE,KAAK,CAAC,EAAE,GAA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AC;CACpD,GAAG,SAAS,GAAG,KAAK,CAAC"}
|
package/lib/cjs/BeEvent.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* @module Events
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.BeEventList = exports.BeUnorderedUiEvent = exports.BeUnorderedEvent = exports.BeUiEvent = exports.BeEvent = void 0;
|
|
10
|
+
exports.BeEventList = exports.BeAsyncEvent = exports.BeUnorderedUiEvent = exports.BeUnorderedEvent = exports.BeUiEvent = exports.BeEvent = void 0;
|
|
11
11
|
const UnexpectedErrors_1 = require("./UnexpectedErrors");
|
|
12
12
|
/**
|
|
13
13
|
* Manages a set of *listeners* for a particular event and notifies them when the event is raised.
|
|
@@ -81,8 +81,13 @@ class BeEvent {
|
|
|
81
81
|
dropped = true;
|
|
82
82
|
}
|
|
83
83
|
else {
|
|
84
|
+
const listener = context.listener;
|
|
85
|
+
if (context.once) {
|
|
86
|
+
context.listener = undefined;
|
|
87
|
+
dropped = true;
|
|
88
|
+
}
|
|
84
89
|
try {
|
|
85
|
-
|
|
90
|
+
listener.apply(context.scope, args);
|
|
86
91
|
}
|
|
87
92
|
catch (e) {
|
|
88
93
|
UnexpectedErrors_1.UnexpectedErrors.handle(e);
|
|
@@ -91,10 +96,6 @@ class BeEvent {
|
|
|
91
96
|
// listener was removed during its own callback
|
|
92
97
|
dropped = true;
|
|
93
98
|
}
|
|
94
|
-
else if (context.once) {
|
|
95
|
-
context.listener = undefined;
|
|
96
|
-
dropped = true;
|
|
97
|
-
}
|
|
98
99
|
}
|
|
99
100
|
}
|
|
100
101
|
this._emitDepth--;
|
|
@@ -140,8 +141,6 @@ exports.BeUiEvent = BeUiEvent;
|
|
|
140
141
|
*/
|
|
141
142
|
class BeUnorderedEvent {
|
|
142
143
|
_listeners = new Set();
|
|
143
|
-
_emitDepth = 0;
|
|
144
|
-
_hasTombstones = false;
|
|
145
144
|
/** The number of listeners currently subscribed to the event.
|
|
146
145
|
* @note During `raiseEvent()`, this may include listeners that have been removed or are one-shot
|
|
147
146
|
* but are awaiting deferred cleanup. The count is accurate outside of `raiseEvent()`.
|
|
@@ -171,43 +170,26 @@ class BeUnorderedEvent {
|
|
|
171
170
|
}
|
|
172
171
|
/** Remove a specific context entry, deferring during emit. */
|
|
173
172
|
_removeCtx(ctx) {
|
|
174
|
-
|
|
175
|
-
ctx.listener = undefined; // tombstone for deferred cleanup
|
|
176
|
-
this._hasTombstones = true;
|
|
177
|
-
}
|
|
178
|
-
else {
|
|
179
|
-
this._listeners.delete(ctx);
|
|
180
|
-
}
|
|
173
|
+
this._listeners.delete(ctx);
|
|
181
174
|
}
|
|
182
175
|
/**
|
|
183
176
|
* Raises the event by calling each registered listener with the supplied arguments.
|
|
184
177
|
* @param args This method takes any number of parameters and passes them through to the listeners.
|
|
185
178
|
*/
|
|
186
179
|
raiseEvent(...args) {
|
|
187
|
-
this._emitDepth++;
|
|
188
180
|
for (const ctx of this._listeners) {
|
|
189
181
|
if (!ctx.listener) {
|
|
190
182
|
continue;
|
|
191
183
|
}
|
|
184
|
+
if (ctx.once) {
|
|
185
|
+
this._listeners.delete(ctx);
|
|
186
|
+
}
|
|
192
187
|
try {
|
|
193
188
|
ctx.listener.apply(ctx.scope, args);
|
|
194
189
|
}
|
|
195
190
|
catch (e) {
|
|
196
191
|
UnexpectedErrors_1.UnexpectedErrors.handle(e);
|
|
197
192
|
}
|
|
198
|
-
if (ctx.listener && ctx.once) {
|
|
199
|
-
ctx.listener = undefined;
|
|
200
|
-
this._hasTombstones = true;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
this._emitDepth--;
|
|
204
|
-
// Only clean up tombstoned entries when we're back at the outermost emit
|
|
205
|
-
if (this._hasTombstones && this._emitDepth === 0) {
|
|
206
|
-
this._hasTombstones = false;
|
|
207
|
-
for (const ctx of this._listeners) {
|
|
208
|
-
if (ctx.listener === undefined)
|
|
209
|
-
this._listeners.delete(ctx);
|
|
210
|
-
}
|
|
211
193
|
}
|
|
212
194
|
}
|
|
213
195
|
/** Clear all listeners from this BeUnorderedEvent.
|
|
@@ -225,6 +207,109 @@ class BeUnorderedUiEvent extends BeUnorderedEvent {
|
|
|
225
207
|
emit(args) { this.raiseEvent(args); }
|
|
226
208
|
}
|
|
227
209
|
exports.BeUnorderedUiEvent = BeUnorderedUiEvent;
|
|
210
|
+
/**
|
|
211
|
+
* Manages a set of *listeners* for a particular event and notifies them when the event is raised.
|
|
212
|
+
* Each listener is async (return a Promise<void>). The listeners may be invoked in series
|
|
213
|
+
* or concurrently depending on the configuration of the instance.
|
|
214
|
+
*
|
|
215
|
+
* Like [[BeUnorderedEvent]], this class uses a `Set` internally to support more performant removal
|
|
216
|
+
* of old listeners. When a listener is removed during emit, it is marked for deferred removal instead
|
|
217
|
+
* of mutating the set immediately. Despite the "unordered" implication, items in a `Set` are enumerated
|
|
218
|
+
* in insertion order, which means that this class invokes the listeners in insertion order.
|
|
219
|
+
*
|
|
220
|
+
* Listeners are managed exclusively through the disposal closure returned by [[addListener]] and
|
|
221
|
+
* [[addOnce]]. There is no `removeListener` or `has` method — callers must capture the returned
|
|
222
|
+
* closure to unsubscribe.
|
|
223
|
+
* @beta
|
|
224
|
+
*/
|
|
225
|
+
class BeAsyncEvent {
|
|
226
|
+
_listeners = new Set();
|
|
227
|
+
_concurrent = false;
|
|
228
|
+
_promiseRejectionIsUnexpected = false;
|
|
229
|
+
constructor(options) {
|
|
230
|
+
if (options?.concurrent)
|
|
231
|
+
this._concurrent = true;
|
|
232
|
+
if (options?.promiseRejectionIsUnexpected)
|
|
233
|
+
this._promiseRejectionIsUnexpected = true;
|
|
234
|
+
}
|
|
235
|
+
/** The number of listeners currently subscribed to the event.
|
|
236
|
+
* @note During `raiseEvent()`, this may include listeners that have been removed or are one-shot
|
|
237
|
+
* but are awaiting deferred cleanup. The count is accurate outside of `raiseEvent()`.
|
|
238
|
+
*/
|
|
239
|
+
get numberOfListeners() { return this._listeners.size; }
|
|
240
|
+
/**
|
|
241
|
+
* Registers a Listener to be executed whenever this event is raised.
|
|
242
|
+
* @param listener The function to be executed when the event is raised.
|
|
243
|
+
* @param scope An optional object scope to serve as the 'this' pointer when listener is invoked.
|
|
244
|
+
* @returns A function that will remove this event listener in O(1).
|
|
245
|
+
*/
|
|
246
|
+
addListener(listener, scope) {
|
|
247
|
+
const ctx = { listener, scope, once: false };
|
|
248
|
+
this._listeners.add(ctx);
|
|
249
|
+
return () => this._removeCtx(ctx);
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Registers a callback function to be executed *only once* when the event is raised.
|
|
253
|
+
* @param listener The function to be executed once when the event is raised.
|
|
254
|
+
* @param scope An optional object scope to serve as the `this` pointer in which the listener function will execute.
|
|
255
|
+
* @returns A function that will remove this event listener in O(1).
|
|
256
|
+
*/
|
|
257
|
+
addOnce(listener, scope) {
|
|
258
|
+
const ctx = { listener, scope, once: true };
|
|
259
|
+
this._listeners.add(ctx);
|
|
260
|
+
return () => this._removeCtx(ctx);
|
|
261
|
+
}
|
|
262
|
+
/** Remove a specific context entry, deferring during emit. */
|
|
263
|
+
_removeCtx(ctx) {
|
|
264
|
+
this._listeners.delete(ctx);
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Raises the event by calling each registered listener with the supplied arguments.
|
|
268
|
+
*
|
|
269
|
+
* See [[BeAsyncEventOptions]] for options that control the behavior of this method.
|
|
270
|
+
*
|
|
271
|
+
* @param args This method takes any number of parameters and passes them through to the listeners.
|
|
272
|
+
* @returns A Promise that settles when the event invocation is complete.
|
|
273
|
+
*/
|
|
274
|
+
async raiseEvent(...args) {
|
|
275
|
+
const promises = [];
|
|
276
|
+
// Wrapper to ensure that an exception thrown immediately by a listener is captured as a rejected promise rather than
|
|
277
|
+
// allowed to propagate as an exception. A well-behaved Promise-returning function should never throw, but
|
|
278
|
+
// this defends against the poorly-behaved ones. In Node 23+ we could use `Promise.try` instead.
|
|
279
|
+
const invoke = async (ctx, args) => {
|
|
280
|
+
if (!ctx.listener)
|
|
281
|
+
return;
|
|
282
|
+
await ctx.listener.apply(ctx.scope, args);
|
|
283
|
+
};
|
|
284
|
+
for (const ctx of this._listeners) {
|
|
285
|
+
if (!ctx.listener)
|
|
286
|
+
continue;
|
|
287
|
+
if (ctx.once) {
|
|
288
|
+
// Set guarantees this is safe during iteration.
|
|
289
|
+
this._listeners.delete(ctx);
|
|
290
|
+
}
|
|
291
|
+
let promise = invoke(ctx, args);
|
|
292
|
+
if (this._promiseRejectionIsUnexpected)
|
|
293
|
+
promise = promise.catch(reason => UnexpectedErrors_1.UnexpectedErrors.handle(reason));
|
|
294
|
+
if (this._concurrent)
|
|
295
|
+
promises.push(promise);
|
|
296
|
+
else
|
|
297
|
+
await promise;
|
|
298
|
+
}
|
|
299
|
+
if (this._concurrent) {
|
|
300
|
+
const result = await Promise.allSettled(promises);
|
|
301
|
+
const firstRejection = result.find(r => r.status === "rejected");
|
|
302
|
+
if (firstRejection)
|
|
303
|
+
throw firstRejection.reason;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
/** Clear all listeners from this BeAsyncEvent.
|
|
307
|
+
* @note If called during `raiseEvent`, remaining listeners in the current iteration are skipped
|
|
308
|
+
* immediately rather than being tombstoned.
|
|
309
|
+
*/
|
|
310
|
+
clear() { this._listeners.clear(); }
|
|
311
|
+
}
|
|
312
|
+
exports.BeAsyncEvent = BeAsyncEvent;
|
|
228
313
|
/**
|
|
229
314
|
* A list of BeEvent objects, accessible by an event name.
|
|
230
315
|
* This class may be used instead of explicitly declaring each BeEvent as a member of a containing class.
|
package/lib/cjs/BeEvent.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BeEvent.js","sourceRoot":"","sources":["../../src/BeEvent.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,yDAAsD;AAatD;;;;;GAKG;AACH,MAAa,OAAO;IACV,UAAU,GAAmB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,GAAG,KAAK,CAAC;YAC5B,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;gBAClC,IAAI,GAAG,CAAC,QAAQ,KAAK,SAAS;oBAC5B,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAChC,CAAC;QACH,CAAC;IACH,CAAC;IAED;;;OAGG;IACI,KAAK,KAAW,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;CAClD;AApFD,4CAoFC;AAED;;GAEG;AACH,MAAa,kBAA+B,SAAQ,gBAA4C;IAC9F,wDAAwD;IACjD,IAAI,CAAC,IAAgB,IAAU,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;CAC/D;AAHD,gDAGC;AAED;;;;GAIG;AACH,MAAa,WAAW;IACd,OAAO,GAA+C,EAAE,CAAC;IAEjE;;;OAGG;IACI,GAAG,CAAC,IAAY;QACrB,IAAI,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC/B,IAAI,KAAK;YACP,OAAO,KAAK,CAAC;QAEf,KAAK,GAAG,IAAI,OAAO,EAAE,CAAC;QACtB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;QAC3B,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,IAAY;QACxB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC;IACjC,CAAC;CACF;AAxBD,kCAwBC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Events\r\n */\r\n\r\nimport { UnexpectedErrors } from \"./UnexpectedErrors\";\r\n\r\n/** A function invoked when a BeEvent is raised.\r\n * @public\r\n */\r\nexport type Listener = (...arg: any[]) => void;\r\n\r\ninterface EventContext {\r\n listener: Listener | undefined;\r\n scope: any;\r\n once: boolean;\r\n}\r\n\r\n/**\r\n * Manages a set of *listeners* for a particular event and notifies them when the event is raised.\r\n * This class is usually instantiated inside of a container class and\r\n * exposed as a property for others to *subscribe* via [[BeEvent.addListener]].\r\n * @public\r\n */\r\nexport class BeEvent<T extends Listener> {\r\n private _listeners: EventContext[] = [];\r\n private _emitDepth: number = 0;\r\n\r\n /** The number of listeners currently subscribed to the event. */\r\n public get numberOfListeners() { return this._listeners.length; }\r\n\r\n /**\r\n * Registers a Listener to be executed whenever this event is raised.\r\n * @param listener The function to be executed when the event is raised.\r\n * @param scope An optional object scope to serve as the 'this' pointer when listener is invoked.\r\n * @returns A function that will remove this event listener.\r\n * @see [[BeEvent.raiseEvent]], [[BeEvent.removeListener]]\r\n */\r\n public addListener(listener: T, scope?: any): () => void {\r\n this._listeners.push({ listener, scope, once: false });\r\n return () => this.removeListener(listener, scope);\r\n }\r\n\r\n /**\r\n * Registers a callback function to be executed *only once* when the event is raised.\r\n * @param listener The function to be executed once when the event is raised.\r\n * @param scope An optional object scope to serve as the `this` pointer in which the listener function will execute.\r\n * @returns A function that will remove this event listener.\r\n * @see [[BeEvent.raiseEvent]], [[BeEvent.removeListener]]\r\n */\r\n public addOnce(listener: T, scope?: any): () => void {\r\n this._listeners.push({ listener, scope, once: true });\r\n return () => this.removeListener(listener, scope);\r\n }\r\n\r\n /**\r\n * Un-register a previously registered listener.\r\n * @param listener The listener to be unregistered.\r\n * @param scope The scope that was originally passed to addListener.\r\n * @returns 'true' if the listener was removed; 'false' if the listener and scope are not registered with the event.\r\n * @see [[BeEvent.raiseEvent]], [[BeEvent.addListener]]\r\n */\r\n public removeListener(listener: T, scope?: any): boolean {\r\n const listeners = this._listeners;\r\n\r\n for (let i = 0; i < listeners.length; ++i) {\r\n const context = listeners[i];\r\n if (context.listener === listener && context.scope === scope) {\r\n if (this._emitDepth > 0) {\r\n context.listener = undefined;\r\n } else {\r\n listeners.splice(i, 1);\r\n }\r\n return true;\r\n }\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * Raises the event by calling each registered listener with the supplied arguments.\r\n * @param args This method takes any number of parameters and passes them through to the listeners.\r\n * @see [[BeEvent.removeListener]], [[BeEvent.addListener]]\r\n */\r\n public raiseEvent(...args: Parameters<T>) {\r\n this._emitDepth++;\r\n\r\n const listeners = this._listeners;\r\n const length = listeners.length;\r\n let dropped = false;\r\n\r\n for (let i = 0; i < length; ++i) {\r\n const context = listeners[i];\r\n if (!context.listener) {\r\n dropped = true;\r\n } else {\r\n try {\r\n context.listener.apply(context.scope, args);\r\n } catch (e) {\r\n UnexpectedErrors.handle(e);\r\n }\r\n if (!context.listener) {\r\n // listener was removed during its own callback\r\n dropped = true;\r\n } else if (context.once) {\r\n context.listener = undefined;\r\n dropped = true;\r\n }\r\n }\r\n }\r\n\r\n this._emitDepth--;\r\n\r\n // Only sweep tombstoned entries when the outermost emit completes,\r\n // so nested raiseEvent calls never mutate the array mid-iteration.\r\n if (dropped && this._emitDepth === 0)\r\n this._listeners = this._listeners.filter((ctx) => ctx.listener !== undefined);\r\n }\r\n\r\n /** Determine whether this BeEvent has a specified listener registered.\r\n * @param listener The listener to check.\r\n * @param scope optional scope argument to match call to addListener\r\n */\r\n public has(listener: T, scope?: any): boolean {\r\n for (const ctx of this._listeners) {\r\n if (ctx.listener === listener && ctx.scope === scope) {\r\n return true;\r\n }\r\n }\r\n return false;\r\n }\r\n\r\n /** Clear all Listeners from this BeEvent. */\r\n public clear(): void { this._listeners.length = 0; }\r\n}\r\n\r\n/** Specialization of BeEvent for events that take a single strongly typed argument, primarily used for UI events.\r\n * @public\r\n */\r\nexport class BeUiEvent<TEventArgs> extends BeEvent<(args: TEventArgs) => void> {\r\n /** Raises event with single strongly typed argument. */\r\n public emit(args: TEventArgs): void { this.raiseEvent(args); }\r\n}\r\n\r\ninterface UnorderedEventContext {\r\n listener: Listener | undefined;\r\n scope: any;\r\n once: boolean;\r\n}\r\n\r\n/**\r\n * Manages a set of *listeners* for a particular event and notifies them when the event is raised.\r\n * Unlike [[BeEvent]], this class uses a `Set` internally to support safe concurrent modification\r\n * during emit. When a listener is removed during emit, it is marked for deferred removal instead\r\n * of mutating the set immediately.\r\n *\r\n * Listeners are managed exclusively through the disposal closure returned by [[addListener]] and\r\n * [[addOnce]]. There is no `removeListener` or `has` method — callers must capture the returned\r\n * closure to unsubscribe.\r\n * @beta\r\n */\r\nexport class BeUnorderedEvent<T extends Listener> {\r\n private _listeners: Set<UnorderedEventContext> = new Set();\r\n private _emitDepth: number = 0;\r\n private _hasTombstones: boolean = false;\r\n\r\n /** The number of listeners currently subscribed to the event.\r\n * @note During `raiseEvent()`, this may include listeners that have been removed or are one-shot\r\n * but are awaiting deferred cleanup. The count is accurate outside of `raiseEvent()`.\r\n */\r\n public get numberOfListeners() { return this._listeners.size; }\r\n\r\n /**\r\n * Registers a Listener to be executed whenever this event is raised.\r\n * @param listener The function to be executed when the event is raised.\r\n * @param scope An optional object scope to serve as the 'this' pointer when listener is invoked.\r\n * @returns A function that will remove this event listener in O(1).\r\n */\r\n public addListener(listener: T, scope?: any): () => void {\r\n const ctx: UnorderedEventContext = { listener, scope, once: false };\r\n this._listeners.add(ctx);\r\n return () => this._removeCtx(ctx);\r\n }\r\n\r\n /**\r\n * Registers a callback function to be executed *only once* when the event is raised.\r\n * @param listener The function to be executed once when the event is raised.\r\n * @param scope An optional object scope to serve as the `this` pointer in which the listener function will execute.\r\n * @returns A function that will remove this event listener in O(1).\r\n */\r\n public addOnce(listener: T, scope?: any): () => void {\r\n const ctx: UnorderedEventContext = { listener, scope, once: true };\r\n this._listeners.add(ctx);\r\n return () => this._removeCtx(ctx);\r\n }\r\n\r\n /** Remove a specific context entry, deferring during emit. */\r\n private _removeCtx(ctx: UnorderedEventContext): void {\r\n if (this._emitDepth > 0) {\r\n ctx.listener = undefined; // tombstone for deferred cleanup\r\n this._hasTombstones = true;\r\n } else {\r\n this._listeners.delete(ctx);\r\n }\r\n }\r\n\r\n /**\r\n * Raises the event by calling each registered listener with the supplied arguments.\r\n * @param args This method takes any number of parameters and passes them through to the listeners.\r\n */\r\n public raiseEvent(...args: Parameters<T>) {\r\n this._emitDepth++;\r\n\r\n for (const ctx of this._listeners) {\r\n if (!ctx.listener) {\r\n continue;\r\n }\r\n try {\r\n ctx.listener.apply(ctx.scope, args);\r\n } catch (e) {\r\n UnexpectedErrors.handle(e);\r\n }\r\n if (ctx.listener && ctx.once) {\r\n ctx.listener = undefined;\r\n this._hasTombstones = true;\r\n }\r\n }\r\n\r\n this._emitDepth--;\r\n\r\n // Only clean up tombstoned entries when we're back at the outermost emit\r\n if (this._hasTombstones && this._emitDepth === 0) {\r\n this._hasTombstones = false;\r\n for (const ctx of this._listeners) {\r\n if (ctx.listener === undefined)\r\n this._listeners.delete(ctx);\r\n }\r\n }\r\n }\r\n\r\n /** Clear all listeners from this BeUnorderedEvent.\r\n * @note If called during `raiseEvent`, remaining listeners in the current iteration are skipped\r\n * immediately rather than being tombstoned.\r\n */\r\n public clear(): void { this._listeners.clear(); }\r\n}\r\n\r\n/** Specialization of BeUnorderedEvent for events that take a single strongly typed argument, primarily used for UI events.\r\n * @beta\r\n */\r\nexport class BeUnorderedUiEvent<TEventArgs> extends BeUnorderedEvent<(args: TEventArgs) => void> {\r\n /** Raises event with single strongly typed argument. */\r\n public emit(args: TEventArgs): void { this.raiseEvent(args); }\r\n}\r\n\r\n/**\r\n * A list of BeEvent objects, accessible by an event name.\r\n * This class may be used instead of explicitly declaring each BeEvent as a member of a containing class.\r\n * @public\r\n */\r\nexport class BeEventList<T extends Listener> {\r\n private _events: { [name: string]: BeEvent<T> | undefined } = {};\r\n\r\n /**\r\n * Gets the event associated with the specified name, creating the event if it does not already exist.\r\n * @param name The name of the event.\r\n */\r\n public get(name: string): BeEvent<T> {\r\n let event = this._events[name];\r\n if (event)\r\n return event;\r\n\r\n event = new BeEvent();\r\n this._events[name] = event;\r\n return event;\r\n }\r\n\r\n /**\r\n * Removes the event associated with a name.\r\n * @param name The name of the event.\r\n */\r\n public remove(name: string): void {\r\n this._events[name] = undefined;\r\n }\r\n}\r\n\r\n/**\r\n * Retrieves the type of the callback function for an event type like [[BeEvent]].\r\n * For example:\r\n * ```ts\r\n * const event = new BeEvent<(x: number, y: string) => void>();\r\n * const callback: ListenerType<typeof event> = (x, y) => {\r\n * console.log(`${x}, ${y}`);\r\n * };\r\n * ```\r\n *\r\n * @public\r\n */\r\nexport type ListenerType<TEvent extends {\r\n addListener(listener: Listener): () => void;\r\n}> =\r\n TEvent extends {\r\n addListener(listener: infer TListener): () => void;\r\n } ? TListener : never;\r\n"]}
|
|
1
|
+
{"version":3,"file":"BeEvent.js","sourceRoot":"","sources":["../../src/BeEvent.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,yDAAsD;AAmBtD;;;;;GAKG;AACH,MAAa,OAAO;IACV,UAAU,GAAmB,EAAE,CAAC;IAChC,UAAU,GAAW,CAAC,CAAC;IAE/B,iEAAiE;IACjE,IAAW,iBAAiB,KAAK,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;IAEjE;;;;;;OAMG;IACI,WAAW,CAAC,QAAW,EAAE,KAAW;QACzC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;QACvD,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IACpD,CAAC;IAED;;;;;;OAMG;IACI,OAAO,CAAC,QAAW,EAAE,KAAW;QACrC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;QACtD,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,cAAc,CAA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,CAAC;;gBAEvB,MAAM,OAAO,CAAC;QAClB,CAAC;QAED,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACrB,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;YAClD,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,UAAU,CAAC,CAAC;YACjE,IAAI,cAAc;gBAChB,MAAM,cAAc,CAAC,MAAM,CAAC;QAChC,CAAC;IACH,CAAC;IAED;;;OAGG;IACI,KAAK,KAAW,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;CAClD;AAlGD,oCAkGC;AAED;;;;GAIG;AACH,MAAa,WAAW;IACd,OAAO,GAA+C,EAAE,CAAC;IAEjE;;;OAGG;IACI,GAAG,CAAC,IAAY;QACrB,IAAI,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC/B,IAAI,KAAK;YACP,OAAO,KAAK,CAAC;QAEf,KAAK,GAAG,IAAI,OAAO,EAAE,CAAC;QACtB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;QAC3B,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,IAAY;QACxB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC;IACjC,CAAC;CACF;AAxBD,kCAwBC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Events\r\n */\r\n\r\nimport { UnexpectedErrors } from \"./UnexpectedErrors\";\r\n\r\n/** A function invoked when a BeEvent is raised.\r\n * @public\r\n */\r\nexport type Listener = (...arg: any[]) => void;\r\n\r\n/**\r\n * A function invoked when a BeAsyncEvent is raised.\r\n * @beta\r\n */\r\nexport type AsyncListener = (...arg: any[]) => Promise<void>;\r\n\r\ninterface EventContext {\r\n listener: Listener | undefined;\r\n scope: any;\r\n once: boolean;\r\n}\r\n\r\n/**\r\n * Manages a set of *listeners* for a particular event and notifies them when the event is raised.\r\n * This class is usually instantiated inside of a container class and\r\n * exposed as a property for others to *subscribe* via [[BeEvent.addListener]].\r\n * @public\r\n */\r\nexport class BeEvent<T extends Listener> {\r\n private _listeners: EventContext[] = [];\r\n private _emitDepth: number = 0;\r\n\r\n /** The number of listeners currently subscribed to the event. */\r\n public get numberOfListeners() { return this._listeners.length; }\r\n\r\n /**\r\n * Registers a Listener to be executed whenever this event is raised.\r\n * @param listener The function to be executed when the event is raised.\r\n * @param scope An optional object scope to serve as the 'this' pointer when listener is invoked.\r\n * @returns A function that will remove this event listener.\r\n * @see [[BeEvent.raiseEvent]], [[BeEvent.removeListener]]\r\n */\r\n public addListener(listener: T, scope?: any): () => void {\r\n this._listeners.push({ listener, scope, once: false });\r\n return () => this.removeListener(listener, scope);\r\n }\r\n\r\n /**\r\n * Registers a callback function to be executed *only once* when the event is raised.\r\n * @param listener The function to be executed once when the event is raised.\r\n * @param scope An optional object scope to serve as the `this` pointer in which the listener function will execute.\r\n * @returns A function that will remove this event listener.\r\n * @see [[BeEvent.raiseEvent]], [[BeEvent.removeListener]]\r\n */\r\n public addOnce(listener: T, scope?: any): () => void {\r\n this._listeners.push({ listener, scope, once: true });\r\n return () => this.removeListener(listener, scope);\r\n }\r\n\r\n /**\r\n * Un-register a previously registered listener.\r\n * @param listener The listener to be unregistered.\r\n * @param scope The scope that was originally passed to addListener.\r\n * @returns 'true' if the listener was removed; 'false' if the listener and scope are not registered with the event.\r\n * @see [[BeEvent.raiseEvent]], [[BeEvent.addListener]]\r\n */\r\n public removeListener(listener: T, scope?: any): boolean {\r\n const listeners = this._listeners;\r\n\r\n for (let i = 0; i < listeners.length; ++i) {\r\n const context = listeners[i];\r\n if (context.listener === listener && context.scope === scope) {\r\n if (this._emitDepth > 0) {\r\n context.listener = undefined;\r\n } else {\r\n listeners.splice(i, 1);\r\n }\r\n return true;\r\n }\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * Raises the event by calling each registered listener with the supplied arguments.\r\n * @param args This method takes any number of parameters and passes them through to the listeners.\r\n * @see [[BeEvent.removeListener]], [[BeEvent.addListener]]\r\n */\r\n public raiseEvent(...args: Parameters<T>) {\r\n this._emitDepth++;\r\n\r\n const listeners = this._listeners;\r\n const length = listeners.length;\r\n let dropped = false;\r\n\r\n for (let i = 0; i < length; ++i) {\r\n const context = listeners[i];\r\n if (!context.listener) {\r\n dropped = true;\r\n } else {\r\n const listener = context.listener;\r\n\r\n if (context.once) {\r\n context.listener = undefined;\r\n dropped = true;\r\n }\r\n\r\n try {\r\n listener.apply(context.scope, args);\r\n } catch (e) {\r\n UnexpectedErrors.handle(e);\r\n }\r\n\r\n if (!context.listener) {\r\n // listener was removed during its own callback\r\n dropped = true;\r\n }\r\n }\r\n }\r\n\r\n this._emitDepth--;\r\n\r\n // Only sweep tombstoned entries when the outermost emit completes,\r\n // so nested raiseEvent calls never mutate the array mid-iteration.\r\n if (dropped && this._emitDepth === 0)\r\n this._listeners = this._listeners.filter((ctx) => ctx.listener !== undefined);\r\n }\r\n\r\n /** Determine whether this BeEvent has a specified listener registered.\r\n * @param listener The listener to check.\r\n * @param scope optional scope argument to match call to addListener\r\n */\r\n public has(listener: T, scope?: any): boolean {\r\n for (const ctx of this._listeners) {\r\n if (ctx.listener === listener && ctx.scope === scope) {\r\n return true;\r\n }\r\n }\r\n return false;\r\n }\r\n\r\n /** Clear all Listeners from this BeEvent. */\r\n public clear(): void { this._listeners.length = 0; }\r\n}\r\n\r\n/** Specialization of BeEvent for events that take a single strongly typed argument, primarily used for UI events.\r\n * @public\r\n */\r\nexport class BeUiEvent<TEventArgs> extends BeEvent<(args: TEventArgs) => void> {\r\n /** Raises event with single strongly typed argument. */\r\n public emit(args: TEventArgs): void { this.raiseEvent(args); }\r\n}\r\n\r\ninterface UnorderedEventContext {\r\n listener: Listener | undefined;\r\n scope: any;\r\n once: boolean;\r\n}\r\n\r\n/**\r\n * Manages a set of *listeners* for a particular event and notifies them when the event is raised.\r\n * Unlike [[BeEvent]], this class uses a `Set` internally to support safe concurrent modification\r\n * during emit. When a listener is removed during emit, it is marked for deferred removal instead\r\n * of mutating the set immediately.\r\n *\r\n * Listeners are managed exclusively through the disposal closure returned by [[addListener]] and\r\n * [[addOnce]]. There is no `removeListener` or `has` method — callers must capture the returned\r\n * closure to unsubscribe.\r\n * @beta\r\n */\r\nexport class BeUnorderedEvent<T extends Listener> {\r\n private _listeners: Set<UnorderedEventContext> = new Set();\r\n\r\n /** The number of listeners currently subscribed to the event.\r\n * @note During `raiseEvent()`, this may include listeners that have been removed or are one-shot\r\n * but are awaiting deferred cleanup. The count is accurate outside of `raiseEvent()`.\r\n */\r\n public get numberOfListeners() { return this._listeners.size; }\r\n\r\n /**\r\n * Registers a Listener to be executed whenever this event is raised.\r\n * @param listener The function to be executed when the event is raised.\r\n * @param scope An optional object scope to serve as the 'this' pointer when listener is invoked.\r\n * @returns A function that will remove this event listener in O(1).\r\n */\r\n public addListener(listener: T, scope?: any): () => void {\r\n const ctx: UnorderedEventContext = { listener, scope, once: false };\r\n this._listeners.add(ctx);\r\n return () => this._removeCtx(ctx);\r\n }\r\n\r\n /**\r\n * Registers a callback function to be executed *only once* when the event is raised.\r\n * @param listener The function to be executed once when the event is raised.\r\n * @param scope An optional object scope to serve as the `this` pointer in which the listener function will execute.\r\n * @returns A function that will remove this event listener in O(1).\r\n */\r\n public addOnce(listener: T, scope?: any): () => void {\r\n const ctx: UnorderedEventContext = { listener, scope, once: true };\r\n this._listeners.add(ctx);\r\n return () => this._removeCtx(ctx);\r\n }\r\n\r\n /** Remove a specific context entry, deferring during emit. */\r\n private _removeCtx(ctx: UnorderedEventContext): void {\r\n this._listeners.delete(ctx);\r\n }\r\n\r\n /**\r\n * Raises the event by calling each registered listener with the supplied arguments.\r\n * @param args This method takes any number of parameters and passes them through to the listeners.\r\n */\r\n public raiseEvent(...args: Parameters<T>) {\r\n for (const ctx of this._listeners) {\r\n if (!ctx.listener) {\r\n continue;\r\n }\r\n\r\n if (ctx.once) {\r\n this._listeners.delete(ctx);\r\n }\r\n\r\n try {\r\n ctx.listener.apply(ctx.scope, args);\r\n } catch (e) {\r\n UnexpectedErrors.handle(e);\r\n }\r\n }\r\n }\r\n\r\n /** Clear all listeners from this BeUnorderedEvent.\r\n * @note If called during `raiseEvent`, remaining listeners in the current iteration are skipped\r\n * immediately rather than being tombstoned.\r\n */\r\n public clear(): void { this._listeners.clear(); }\r\n}\r\n\r\n/** Specialization of BeUnorderedEvent for events that take a single strongly typed argument, primarily used for UI events.\r\n * @beta\r\n */\r\nexport class BeUnorderedUiEvent<TEventArgs> extends BeUnorderedEvent<(args: TEventArgs) => void> {\r\n /** Raises event with single strongly typed argument. */\r\n public emit(args: TEventArgs): void { this.raiseEvent(args); }\r\n}\r\n\r\ninterface UnorderedAsyncEventContext {\r\n listener: AsyncListener | undefined;\r\n scope: any;\r\n once: boolean;\r\n}\r\n\r\n/**\r\n * Options for configuring the behavior of a BeAsyncEvent.\r\n * @beta\r\n */\r\ninterface BeAsyncEventOptions {\r\n /**\r\n * If true, listeners will be invoked concurrently rather than in series. The listeners will all be invoked\r\n * immediately, and the Promise returned by [[BeAsyncEvent.raiseEvent]] will be invoked after all listeners'\r\n * Promises have resolved.\r\n *\r\n * If false, [[BeAsyncEvent.raiseEvent]] will wait for each listener's Promise to resolve before invoking the\r\n * next listener.\r\n *\r\n * Note that \"concurrent\" does not necessarily imply the use of multiple threads.\r\n * It just means that the next listener is invoked before the Promise returned by\r\n * the previous listener has resolved.\r\n */\r\n concurrent?: boolean;\r\n\r\n /**\r\n * If true, and a listener rejects its returned Promise, [[UnexpectedError.handle]] is invoked\r\n * and the error is otherwise ignored; the Promise returned by [[BeAsyncEvent.raiseEvent]] will only\r\n * reject if [[UnexpectedError.handle]] itself throws an exception.\r\n *\r\n * If false or unspecified, promise rejection is considered normal, so [[UnexpectedError.handle]] is not\r\n * invoked. Instead, the Promise returned by [[BeAsyncEvent.raiseEvent]] will reject. If [[concurrent]] is true,\r\n * all listener Promises are awaited before the rejection is propagated, so all listeners run to completion.\r\n * If [[concurrent]] is false, the rejection is propagated immediately after the first listener's Promise rejects,\r\n * and subsequent listeners are not invoked.\r\n */\r\n promiseRejectionIsUnexpected?: boolean;\r\n}\r\n\r\n/**\r\n * Manages a set of *listeners* for a particular event and notifies them when the event is raised.\r\n * Each listener is async (return a Promise<void>). The listeners may be invoked in series\r\n * or concurrently depending on the configuration of the instance.\r\n *\r\n * Like [[BeUnorderedEvent]], this class uses a `Set` internally to support more performant removal\r\n * of old listeners. When a listener is removed during emit, it is marked for deferred removal instead\r\n * of mutating the set immediately. Despite the \"unordered\" implication, items in a `Set` are enumerated\r\n * in insertion order, which means that this class invokes the listeners in insertion order.\r\n *\r\n * Listeners are managed exclusively through the disposal closure returned by [[addListener]] and\r\n * [[addOnce]]. There is no `removeListener` or `has` method — callers must capture the returned\r\n * closure to unsubscribe.\r\n * @beta\r\n */\r\nexport class BeAsyncEvent<T extends AsyncListener> {\r\n private _listeners: Set<UnorderedAsyncEventContext> = new Set();\r\n private _concurrent: boolean = false;\r\n private _promiseRejectionIsUnexpected: boolean = false;\r\n\r\n public constructor(options?: BeAsyncEventOptions) {\r\n if (options?.concurrent)\r\n this._concurrent = true;\r\n if (options?.promiseRejectionIsUnexpected)\r\n this._promiseRejectionIsUnexpected = true;\r\n }\r\n\r\n /** The number of listeners currently subscribed to the event.\r\n * @note During `raiseEvent()`, this may include listeners that have been removed or are one-shot\r\n * but are awaiting deferred cleanup. The count is accurate outside of `raiseEvent()`.\r\n */\r\n public get numberOfListeners() { return this._listeners.size; }\r\n\r\n /**\r\n * Registers a Listener to be executed whenever this event is raised.\r\n * @param listener The function to be executed when the event is raised.\r\n * @param scope An optional object scope to serve as the 'this' pointer when listener is invoked.\r\n * @returns A function that will remove this event listener in O(1).\r\n */\r\n public addListener(listener: T, scope?: any): () => void {\r\n const ctx: UnorderedAsyncEventContext = { listener, scope, once: false };\r\n this._listeners.add(ctx);\r\n return () => this._removeCtx(ctx);\r\n }\r\n\r\n /**\r\n * Registers a callback function to be executed *only once* when the event is raised.\r\n * @param listener The function to be executed once when the event is raised.\r\n * @param scope An optional object scope to serve as the `this` pointer in which the listener function will execute.\r\n * @returns A function that will remove this event listener in O(1).\r\n */\r\n public addOnce(listener: T, scope?: any): () => void {\r\n const ctx: UnorderedAsyncEventContext = { listener, scope, once: true };\r\n this._listeners.add(ctx);\r\n return () => this._removeCtx(ctx);\r\n }\r\n\r\n /** Remove a specific context entry, deferring during emit. */\r\n private _removeCtx(ctx: UnorderedAsyncEventContext): void {\r\n this._listeners.delete(ctx);\r\n }\r\n\r\n /**\r\n * Raises the event by calling each registered listener with the supplied arguments.\r\n *\r\n * See [[BeAsyncEventOptions]] for options that control the behavior of this method.\r\n *\r\n * @param args This method takes any number of parameters and passes them through to the listeners.\r\n * @returns A Promise that settles when the event invocation is complete.\r\n */\r\n public async raiseEvent(...args: Parameters<T>): Promise<void> {\r\n const promises = [];\r\n\r\n // Wrapper to ensure that an exception thrown immediately by a listener is captured as a rejected promise rather than\r\n // allowed to propagate as an exception. A well-behaved Promise-returning function should never throw, but\r\n // this defends against the poorly-behaved ones. In Node 23+ we could use `Promise.try` instead.\r\n const invoke = async (ctx: UnorderedAsyncEventContext, args: Parameters<T>[]) => {\r\n if (!ctx.listener) return;\r\n await ctx.listener.apply(ctx.scope, args);\r\n };\r\n\r\n for (const ctx of this._listeners) {\r\n if (!ctx.listener)\r\n continue;\r\n\r\n if (ctx.once) {\r\n // Set guarantees this is safe during iteration.\r\n this._listeners.delete(ctx);\r\n }\r\n\r\n let promise = invoke(ctx, args);\r\n if (this._promiseRejectionIsUnexpected)\r\n promise = promise.catch(reason => UnexpectedErrors.handle(reason));\r\n\r\n if (this._concurrent)\r\n promises.push(promise);\r\n else\r\n await promise;\r\n }\r\n\r\n if (this._concurrent) {\r\n const result = await Promise.allSettled(promises);\r\n const firstRejection = result.find(r => r.status === \"rejected\");\r\n if (firstRejection)\r\n throw firstRejection.reason;\r\n }\r\n }\r\n\r\n /** Clear all listeners from this BeAsyncEvent.\r\n * @note If called during `raiseEvent`, remaining listeners in the current iteration are skipped\r\n * immediately rather than being tombstoned.\r\n */\r\n public clear(): void { this._listeners.clear(); }\r\n}\r\n\r\n/**\r\n * A list of BeEvent objects, accessible by an event name.\r\n * This class may be used instead of explicitly declaring each BeEvent as a member of a containing class.\r\n * @public\r\n */\r\nexport class BeEventList<T extends Listener> {\r\n private _events: { [name: string]: BeEvent<T> | undefined } = {};\r\n\r\n /**\r\n * Gets the event associated with the specified name, creating the event if it does not already exist.\r\n * @param name The name of the event.\r\n */\r\n public get(name: string): BeEvent<T> {\r\n let event = this._events[name];\r\n if (event)\r\n return event;\r\n\r\n event = new BeEvent();\r\n this._events[name] = event;\r\n return event;\r\n }\r\n\r\n /**\r\n * Removes the event associated with a name.\r\n * @param name The name of the event.\r\n */\r\n public remove(name: string): void {\r\n this._events[name] = undefined;\r\n }\r\n}\r\n\r\n/**\r\n * Retrieves the type of the callback function for an event type like [[BeEvent]].\r\n * For example:\r\n * ```ts\r\n * const event = new BeEvent<(x: number, y: string) => void>();\r\n * const callback: ListenerType<typeof event> = (x, y) => {\r\n * console.log(`${x}, ${y}`);\r\n * };\r\n * ```\r\n *\r\n * @public\r\n */\r\nexport type ListenerType<TEvent extends {\r\n addListener(listener: Listener): () => void;\r\n}> =\r\n TEvent extends {\r\n addListener(listener: infer TListener): () => void;\r\n } ? TListener : never;\r\n"]}
|
package/lib/cjs/Id.d.ts
CHANGED
|
@@ -113,7 +113,7 @@ export declare namespace Id64 {
|
|
|
113
113
|
/** Obtain iterator over the specified Ids.
|
|
114
114
|
* @see [[Id64.iterable]].
|
|
115
115
|
*/
|
|
116
|
-
function iterator(ids:
|
|
116
|
+
function iterator(ids: ReadonlyArray<Id64String> | ReadonlySet<Id64String> | Id64String): Iterator<Id64String>;
|
|
117
117
|
/** Obtain an iterable over the specified Ids. Example usage:
|
|
118
118
|
* ```ts
|
|
119
119
|
* const ids = ["0x123", "0xfed"];
|
|
@@ -121,13 +121,13 @@ export declare namespace Id64 {
|
|
|
121
121
|
* console.log(id);
|
|
122
122
|
* ```
|
|
123
123
|
*/
|
|
124
|
-
function iterable(ids:
|
|
124
|
+
function iterable(ids: ReadonlyArray<Id64String> | ReadonlySet<Id64String> | Id64String): Iterable<Id64String>;
|
|
125
125
|
/** Return the first [[Id64String]] of an [[Id64Arg]]. */
|
|
126
|
-
function getFirst(arg:
|
|
126
|
+
function getFirst(arg: ReadonlyArray<Id64String> | ReadonlySet<Id64String> | Id64String): Id64String;
|
|
127
127
|
/** Return the number of [[Id64String]]s represented by an [[Id64Arg]]. */
|
|
128
|
-
function sizeOf(arg:
|
|
128
|
+
function sizeOf(arg: ReadonlyArray<Id64String> | ReadonlySet<Id64String> | Id64String): number;
|
|
129
129
|
/** Returns true if the [[Id64Arg]] contains the specified Id. */
|
|
130
|
-
function has(arg:
|
|
130
|
+
function has(arg: ReadonlyArray<Id64String> | ReadonlySet<Id64String> | Id64String, id: Id64String): boolean;
|
|
131
131
|
/** The string representation of an invalid Id. */
|
|
132
132
|
const invalid = "0";
|
|
133
133
|
/** Determine if the supplied id string represents a transient Id.
|
package/lib/cjs/Id.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Id.d.ts","sourceRoot":"","sources":["../../src/Id.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC;AAEhC;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC;AAEhC;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG,GAAG,CAAC,UAAU,CAAC,CAA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OG;IACH,SAAgB,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,CAkBvD;CACF"}
|
package/lib/cjs/Id.js
CHANGED
|
@@ -311,16 +311,18 @@ var Id64;
|
|
|
311
311
|
Id64.getFirst = getFirst;
|
|
312
312
|
/** Return the number of [[Id64String]]s represented by an [[Id64Arg]]. */
|
|
313
313
|
function sizeOf(arg) {
|
|
314
|
-
return typeof arg === "string" ? 1 :
|
|
314
|
+
return typeof arg === "string" ? 1 : "size" in arg ? arg.size : arg.length;
|
|
315
315
|
}
|
|
316
316
|
Id64.sizeOf = sizeOf;
|
|
317
317
|
/** Returns true if the [[Id64Arg]] contains the specified Id. */
|
|
318
318
|
function has(arg, id) {
|
|
319
|
-
if (typeof arg === "string")
|
|
319
|
+
if (typeof arg === "string") {
|
|
320
320
|
return arg === id;
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
321
|
+
}
|
|
322
|
+
if ("has" in arg) {
|
|
323
|
+
return arg.has(id);
|
|
324
|
+
}
|
|
325
|
+
return -1 !== arg.indexOf(id);
|
|
324
326
|
}
|
|
325
327
|
Id64.has = has;
|
|
326
328
|
/** The string representation of an invalid Id. */
|