@itwin/core-bentley 5.9.0-dev.1 → 5.9.0-dev.10
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 +55 -1
- package/lib/cjs/BeEvent.d.ts.map +1 -1
- package/lib/cjs/BeEvent.js +111 -8
- package/lib/cjs/BeEvent.js.map +1 -1
- package/lib/cjs/UtilityFunctions.d.ts +17 -0
- package/lib/cjs/UtilityFunctions.d.ts.map +1 -0
- package/lib/cjs/UtilityFunctions.js +52 -0
- package/lib/cjs/UtilityFunctions.js.map +1 -0
- package/lib/cjs/core-bentley.d.ts +1 -0
- package/lib/cjs/core-bentley.d.ts.map +1 -1
- package/lib/cjs/core-bentley.js +1 -0
- package/lib/cjs/core-bentley.js.map +1 -1
- package/lib/esm/BeEvent.d.ts +55 -1
- package/lib/esm/BeEvent.d.ts.map +1 -1
- package/lib/esm/BeEvent.js +108 -7
- package/lib/esm/BeEvent.js.map +1 -1
- package/lib/esm/UtilityFunctions.d.ts +17 -0
- package/lib/esm/UtilityFunctions.d.ts.map +1 -0
- package/lib/esm/UtilityFunctions.js +49 -0
- package/lib/esm/UtilityFunctions.js.map +1 -0
- package/lib/esm/core-bentley.d.ts +1 -0
- package/lib/esm/core-bentley.d.ts.map +1 -1
- package/lib/esm/core-bentley.js +1 -0
- package/lib/esm/core-bentley.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
|
|
3
|
+
This log was last generated on Thu, 16 Apr 2026 11:06:21 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 5.8.2
|
|
6
|
+
Thu, 16 Apr 2026 11:05:01 GMT
|
|
7
|
+
|
|
8
|
+
_Version update only_
|
|
9
|
+
|
|
10
|
+
## 5.8.1
|
|
11
|
+
Fri, 10 Apr 2026 13:02:00 GMT
|
|
12
|
+
|
|
13
|
+
_Version update only_
|
|
14
|
+
|
|
15
|
+
## 5.8.0
|
|
16
|
+
Thu, 02 Apr 2026 18:19:33 GMT
|
|
17
|
+
|
|
18
|
+
_Version update only_
|
|
4
19
|
|
|
5
20
|
## 5.7.3
|
|
6
21
|
Tue, 24 Mar 2026 14:29:17 GMT
|
package/lib/cjs/BeEvent.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export type Listener = (...arg: any[]) => void;
|
|
|
13
13
|
*/
|
|
14
14
|
export declare class BeEvent<T extends Listener> {
|
|
15
15
|
private _listeners;
|
|
16
|
-
private
|
|
16
|
+
private _emitDepth;
|
|
17
17
|
/** The number of listeners currently subscribed to the event. */
|
|
18
18
|
get numberOfListeners(): number;
|
|
19
19
|
/**
|
|
@@ -61,6 +61,60 @@ export declare class BeUiEvent<TEventArgs> extends BeEvent<(args: TEventArgs) =>
|
|
|
61
61
|
/** Raises event with single strongly typed argument. */
|
|
62
62
|
emit(args: TEventArgs): void;
|
|
63
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Manages a set of *listeners* for a particular event and notifies them when the event is raised.
|
|
66
|
+
* Unlike [[BeEvent]], this class uses a `Set` internally to support safe concurrent modification
|
|
67
|
+
* during emit. When a listener is removed during emit, it is marked for deferred removal instead
|
|
68
|
+
* of mutating the set immediately.
|
|
69
|
+
*
|
|
70
|
+
* Listeners are managed exclusively through the disposal closure returned by [[addListener]] and
|
|
71
|
+
* [[addOnce]]. There is no `removeListener` or `has` method — callers must capture the returned
|
|
72
|
+
* closure to unsubscribe.
|
|
73
|
+
* @beta
|
|
74
|
+
*/
|
|
75
|
+
export declare class BeUnorderedEvent<T extends Listener> {
|
|
76
|
+
private _listeners;
|
|
77
|
+
private _emitDepth;
|
|
78
|
+
private _hasTombstones;
|
|
79
|
+
/** The number of listeners currently subscribed to the event.
|
|
80
|
+
* @note During `raiseEvent()`, this may include listeners that have been removed or are one-shot
|
|
81
|
+
* but are awaiting deferred cleanup. The count is accurate outside of `raiseEvent()`.
|
|
82
|
+
*/
|
|
83
|
+
get numberOfListeners(): number;
|
|
84
|
+
/**
|
|
85
|
+
* Registers a Listener to be executed whenever this event is raised.
|
|
86
|
+
* @param listener The function to be executed when the event is raised.
|
|
87
|
+
* @param scope An optional object scope to serve as the 'this' pointer when listener is invoked.
|
|
88
|
+
* @returns A function that will remove this event listener in O(1).
|
|
89
|
+
*/
|
|
90
|
+
addListener(listener: T, scope?: any): () => void;
|
|
91
|
+
/**
|
|
92
|
+
* Registers a callback function to be executed *only once* when the event is raised.
|
|
93
|
+
* @param listener The function to be executed once when the event is raised.
|
|
94
|
+
* @param scope An optional object scope to serve as the `this` pointer in which the listener function will execute.
|
|
95
|
+
* @returns A function that will remove this event listener in O(1).
|
|
96
|
+
*/
|
|
97
|
+
addOnce(listener: T, scope?: any): () => void;
|
|
98
|
+
/** Remove a specific context entry, deferring during emit. */
|
|
99
|
+
private _removeCtx;
|
|
100
|
+
/**
|
|
101
|
+
* Raises the event by calling each registered listener with the supplied arguments.
|
|
102
|
+
* @param args This method takes any number of parameters and passes them through to the listeners.
|
|
103
|
+
*/
|
|
104
|
+
raiseEvent(...args: Parameters<T>): void;
|
|
105
|
+
/** Clear all listeners from this BeUnorderedEvent.
|
|
106
|
+
* @note If called during `raiseEvent`, remaining listeners in the current iteration are skipped
|
|
107
|
+
* immediately rather than being tombstoned.
|
|
108
|
+
*/
|
|
109
|
+
clear(): void;
|
|
110
|
+
}
|
|
111
|
+
/** Specialization of BeUnorderedEvent for events that take a single strongly typed argument, primarily used for UI events.
|
|
112
|
+
* @beta
|
|
113
|
+
*/
|
|
114
|
+
export declare class BeUnorderedUiEvent<TEventArgs> extends BeUnorderedEvent<(args: TEventArgs) => void> {
|
|
115
|
+
/** Raises event with single strongly typed argument. */
|
|
116
|
+
emit(args: TEventArgs): void;
|
|
117
|
+
}
|
|
64
118
|
/**
|
|
65
119
|
* A list of BeEvent objects, accessible by an event name.
|
|
66
120
|
* This class may be used instead of explicitly declaring each BeEvent as a member of a containing class.
|
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;AAQ/C;;;;;GAKG;AACH,qBAAa,OAAO,CAAC,CAAC,SAAS,QAAQ;IACrC,OAAO,CAAC,UAAU,CAAsB;IACxC,OAAO,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;AAQ/C;;;;;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,GAAG,GAAG,MAAM,IAAI;IAKpD;;;;;;OAMG;IACI,cAAc,CAAC,QAAQ,EAAE,CAAC,EAAE,KAAK,CAAC,EAAE,GAAG,GAAG,OAAO;IAiBxD;;;;OAIG;IACI,UAAU,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC;IAmCxC;;;OAGG;IACI,GAAG,CAAC,QAAQ,EAAE,CAAC,EAAE,KAAK,C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G,IAAI;CAGlC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,YAAY,CAAC,MAAM,SAAS;IACtC,WAAW,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,IAAI,CAAC;CAC7C,IACC,MAAM,SAAS;IACb,WAAW,CAAC,QAAQ,EAAE,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC;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.BeUiEvent = exports.BeEvent = void 0;
|
|
10
|
+
exports.BeEventList = 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.
|
|
@@ -17,7 +17,7 @@ const UnexpectedErrors_1 = require("./UnexpectedErrors");
|
|
|
17
17
|
*/
|
|
18
18
|
class BeEvent {
|
|
19
19
|
_listeners = [];
|
|
20
|
-
|
|
20
|
+
_emitDepth = 0;
|
|
21
21
|
/** The number of listeners currently subscribed to the event. */
|
|
22
22
|
get numberOfListeners() { return this._listeners.length; }
|
|
23
23
|
/**
|
|
@@ -54,7 +54,7 @@ class BeEvent {
|
|
|
54
54
|
for (let i = 0; i < listeners.length; ++i) {
|
|
55
55
|
const context = listeners[i];
|
|
56
56
|
if (context.listener === listener && context.scope === scope) {
|
|
57
|
-
if (this.
|
|
57
|
+
if (this._emitDepth > 0) {
|
|
58
58
|
context.listener = undefined;
|
|
59
59
|
}
|
|
60
60
|
else {
|
|
@@ -71,7 +71,7 @@ class BeEvent {
|
|
|
71
71
|
* @see [[BeEvent.removeListener]], [[BeEvent.addListener]]
|
|
72
72
|
*/
|
|
73
73
|
raiseEvent(...args) {
|
|
74
|
-
this.
|
|
74
|
+
this._emitDepth++;
|
|
75
75
|
const listeners = this._listeners;
|
|
76
76
|
const length = listeners.length;
|
|
77
77
|
let dropped = false;
|
|
@@ -87,16 +87,21 @@ class BeEvent {
|
|
|
87
87
|
catch (e) {
|
|
88
88
|
UnexpectedErrors_1.UnexpectedErrors.handle(e);
|
|
89
89
|
}
|
|
90
|
-
if (context.
|
|
90
|
+
if (!context.listener) {
|
|
91
|
+
// listener was removed during its own callback
|
|
92
|
+
dropped = true;
|
|
93
|
+
}
|
|
94
|
+
else if (context.once) {
|
|
91
95
|
context.listener = undefined;
|
|
92
96
|
dropped = true;
|
|
93
97
|
}
|
|
94
98
|
}
|
|
95
99
|
}
|
|
96
|
-
|
|
97
|
-
|
|
100
|
+
this._emitDepth--;
|
|
101
|
+
// Only sweep tombstoned entries when the outermost emit completes,
|
|
102
|
+
// so nested raiseEvent calls never mutate the array mid-iteration.
|
|
103
|
+
if (dropped && this._emitDepth === 0)
|
|
98
104
|
this._listeners = this._listeners.filter((ctx) => ctx.listener !== undefined);
|
|
99
|
-
this._insideRaiseEvent = false;
|
|
100
105
|
}
|
|
101
106
|
/** Determine whether this BeEvent has a specified listener registered.
|
|
102
107
|
* @param listener The listener to check.
|
|
@@ -122,6 +127,104 @@ class BeUiEvent extends BeEvent {
|
|
|
122
127
|
emit(args) { this.raiseEvent(args); }
|
|
123
128
|
}
|
|
124
129
|
exports.BeUiEvent = BeUiEvent;
|
|
130
|
+
/**
|
|
131
|
+
* Manages a set of *listeners* for a particular event and notifies them when the event is raised.
|
|
132
|
+
* Unlike [[BeEvent]], this class uses a `Set` internally to support safe concurrent modification
|
|
133
|
+
* during emit. When a listener is removed during emit, it is marked for deferred removal instead
|
|
134
|
+
* of mutating the set immediately.
|
|
135
|
+
*
|
|
136
|
+
* Listeners are managed exclusively through the disposal closure returned by [[addListener]] and
|
|
137
|
+
* [[addOnce]]. There is no `removeListener` or `has` method — callers must capture the returned
|
|
138
|
+
* closure to unsubscribe.
|
|
139
|
+
* @beta
|
|
140
|
+
*/
|
|
141
|
+
class BeUnorderedEvent {
|
|
142
|
+
_listeners = new Set();
|
|
143
|
+
_emitDepth = 0;
|
|
144
|
+
_hasTombstones = false;
|
|
145
|
+
/** The number of listeners currently subscribed to the event.
|
|
146
|
+
* @note During `raiseEvent()`, this may include listeners that have been removed or are one-shot
|
|
147
|
+
* but are awaiting deferred cleanup. The count is accurate outside of `raiseEvent()`.
|
|
148
|
+
*/
|
|
149
|
+
get numberOfListeners() { return this._listeners.size; }
|
|
150
|
+
/**
|
|
151
|
+
* Registers a Listener to be executed whenever this event is raised.
|
|
152
|
+
* @param listener The function to be executed when the event is raised.
|
|
153
|
+
* @param scope An optional object scope to serve as the 'this' pointer when listener is invoked.
|
|
154
|
+
* @returns A function that will remove this event listener in O(1).
|
|
155
|
+
*/
|
|
156
|
+
addListener(listener, scope) {
|
|
157
|
+
const ctx = { listener, scope, once: false };
|
|
158
|
+
this._listeners.add(ctx);
|
|
159
|
+
return () => this._removeCtx(ctx);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Registers a callback function to be executed *only once* when the event is raised.
|
|
163
|
+
* @param listener The function to be executed once when the event is raised.
|
|
164
|
+
* @param scope An optional object scope to serve as the `this` pointer in which the listener function will execute.
|
|
165
|
+
* @returns A function that will remove this event listener in O(1).
|
|
166
|
+
*/
|
|
167
|
+
addOnce(listener, scope) {
|
|
168
|
+
const ctx = { listener, scope, once: true };
|
|
169
|
+
this._listeners.add(ctx);
|
|
170
|
+
return () => this._removeCtx(ctx);
|
|
171
|
+
}
|
|
172
|
+
/** Remove a specific context entry, deferring during emit. */
|
|
173
|
+
_removeCtx(ctx) {
|
|
174
|
+
if (this._emitDepth > 0) {
|
|
175
|
+
ctx.listener = undefined; // tombstone for deferred cleanup
|
|
176
|
+
this._hasTombstones = true;
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
this._listeners.delete(ctx);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Raises the event by calling each registered listener with the supplied arguments.
|
|
184
|
+
* @param args This method takes any number of parameters and passes them through to the listeners.
|
|
185
|
+
*/
|
|
186
|
+
raiseEvent(...args) {
|
|
187
|
+
this._emitDepth++;
|
|
188
|
+
for (const ctx of this._listeners) {
|
|
189
|
+
if (!ctx.listener) {
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
try {
|
|
193
|
+
ctx.listener.apply(ctx.scope, args);
|
|
194
|
+
}
|
|
195
|
+
catch (e) {
|
|
196
|
+
UnexpectedErrors_1.UnexpectedErrors.handle(e);
|
|
197
|
+
}
|
|
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
|
+
}
|
|
212
|
+
}
|
|
213
|
+
/** Clear all listeners from this BeUnorderedEvent.
|
|
214
|
+
* @note If called during `raiseEvent`, remaining listeners in the current iteration are skipped
|
|
215
|
+
* immediately rather than being tombstoned.
|
|
216
|
+
*/
|
|
217
|
+
clear() { this._listeners.clear(); }
|
|
218
|
+
}
|
|
219
|
+
exports.BeUnorderedEvent = BeUnorderedEvent;
|
|
220
|
+
/** Specialization of BeUnorderedEvent for events that take a single strongly typed argument, primarily used for UI events.
|
|
221
|
+
* @beta
|
|
222
|
+
*/
|
|
223
|
+
class BeUnorderedUiEvent extends BeUnorderedEvent {
|
|
224
|
+
/** Raises event with single strongly typed argument. */
|
|
225
|
+
emit(args) { this.raiseEvent(args); }
|
|
226
|
+
}
|
|
227
|
+
exports.BeUnorderedUiEvent = BeUnorderedUiEvent;
|
|
125
228
|
/**
|
|
126
229
|
* A list of BeEvent objects, accessible by an event name.
|
|
127
230
|
* 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,EAAE,CAAC;IAChC,iBAAiB,GAAY,KAAK,CAAC;IAE3C,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,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IACpD,CAAC;IAED;;;;;;OAMG;IACI,cAAc,CAAC,QAAW,EAAE,KAAW;QAC5C,MAAM,SAAS,GAAG,IAAI,CAAC,UAAU,CAAC;QAElC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,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ACI,MAAM,CAAC,IAAY;QACxB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC;IACjC,CAAC;CACF;AAxBD,kCAwBC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Events\n */\n\nimport { UnexpectedErrors } from \"./UnexpectedErrors\";\n\n/** A function invoked when a BeEvent is raised.\n * @public\n */\nexport type Listener = (...arg: any[]) => void;\n\ninterface EventContext {\n listener: Listener | undefined;\n scope: any;\n once: boolean;\n}\n\n/**\n * Manages a set of *listeners* for a particular event and notifies them when the event is raised.\n * This class is usually instantiated inside of a container class and\n * exposed as a property for others to *subscribe* via [[BeEvent.addListener]].\n * @public\n */\nexport class BeEvent<T extends Listener> {\n private _listeners: EventContext[] = [];\n private _insideRaiseEvent: boolean = false;\n\n /** The number of listeners currently subscribed to the event. */\n public get numberOfListeners() { return this._listeners.length; }\n\n /**\n * Registers a Listener to be executed whenever this event is raised.\n * @param listener The function to be executed when the event is raised.\n * @param scope An optional object scope to serve as the 'this' pointer when listener is invoked.\n * @returns A function that will remove this event listener.\n * @see [[BeEvent.raiseEvent]], [[BeEvent.removeListener]]\n */\n public addListener(listener: T, scope?: any): () => void {\n this._listeners.push({ listener, scope, once: false });\n return () => this.removeListener(listener, scope);\n }\n\n /**\n * Registers a callback function to be executed *only once* when the event is raised.\n * @param listener The function to be executed once when the event is raised.\n * @param scope An optional object scope to serve as the `this` pointer in which the listener function will execute.\n * @returns A function that will remove this event listener.\n * @see [[BeEvent.raiseEvent]], [[BeEvent.removeListener]]\n */\n public addOnce(listener: T, scope?: any): () => void {\n this._listeners.push({ listener, scope, once: true });\n return () => this.removeListener(listener, scope);\n }\n\n /**\n * Un-register a previously registered listener.\n * @param listener The listener to be unregistered.\n * @param scope The scope that was originally passed to addListener.\n * @returns 'true' if the listener was removed; 'false' if the listener and scope are not registered with the event.\n * @see [[BeEvent.raiseEvent]], [[BeEvent.addListener]]\n */\n public removeListener(listener: T, scope?: any): boolean {\n const listeners = this._listeners;\n\n for (let i = 0; i < listeners.length; ++i) {\n const context = listeners[i];\n if (context.listener === listener && context.scope === scope) {\n if (this._insideRaiseEvent) {\n context.listener = undefined;\n } else {\n listeners.splice(i, 1);\n }\n return true;\n }\n }\n return false;\n }\n\n /**\n * Raises the event by calling each registered listener with the supplied arguments.\n * @param args This method takes any number of parameters and passes them through to the listeners.\n * @see [[BeEvent.removeListener]], [[BeEvent.addListener]]\n */\n public raiseEvent(...args: Parameters<T>) {\n this._insideRaiseEvent = true;\n\n const listeners = this._listeners;\n const length = listeners.length;\n let dropped = false;\n\n for (let i = 0; i < length; ++i) {\n const context = listeners[i];\n if (!context.listener) {\n dropped = true;\n } else {\n try {\n context.listener.apply(context.scope, args);\n } catch (e) {\n UnexpectedErrors.handle(e);\n }\n if (context.once) {\n context.listener = undefined;\n dropped = true;\n }\n }\n }\n\n // if we had dropped listeners, remove them now\n if (dropped)\n this._listeners = this._listeners.filter((ctx) => ctx.listener !== undefined);\n\n this._insideRaiseEvent = false;\n }\n\n /** Determine whether this BeEvent has a specified listener registered.\n * @param listener The listener to check.\n * @param scope optional scope argument to match call to addListener\n */\n public has(listener: T, scope?: any): boolean {\n for (const ctx of this._listeners) {\n if (ctx.listener === listener && ctx.scope === scope) {\n return true;\n }\n }\n return false;\n }\n\n /** Clear all Listeners from this BeEvent. */\n public clear(): void { this._listeners.length = 0; }\n}\n\n/** Specialization of BeEvent for events that take a single strongly typed argument, primarily used for UI events.\n * @public\n */\nexport class BeUiEvent<TEventArgs> extends BeEvent<(args: TEventArgs) => void> {\n /** Raises event with single strongly typed argument. */\n public emit(args: TEventArgs): void { this.raiseEvent(args); }\n}\n\n/**\n * A list of BeEvent objects, accessible by an event name.\n * This class may be used instead of explicitly declaring each BeEvent as a member of a containing class.\n * @public\n */\nexport class BeEventList<T extends Listener> {\n private _events: { [name: string]: BeEvent<T> | undefined } = {};\n\n /**\n * Gets the event associated with the specified name, creating the event if it does not already exist.\n * @param name The name of the event.\n */\n public get(name: string): BeEvent<T> {\n let event = this._events[name];\n if (event)\n return event;\n\n event = new BeEvent();\n this._events[name] = event;\n return event;\n }\n\n /**\n * Removes the event associated with a name.\n * @param name The name of the event.\n */\n public remove(name: string): void {\n this._events[name] = undefined;\n }\n}\n\n/**\n * Retrieves the type of the callback function for an event type like [[BeEvent]].\n * For example:\n * ```ts\n * const event = new BeEvent<(x: number, y: string) => void>();\n * const callback: ListenerType<typeof event> = (x, y) => {\n * console.log(`${x}, ${y}`);\n * };\n * ```\n *\n * @public\n */\nexport type ListenerType<TEvent extends {\n addListener(listener: Listener): () => void;\n}> =\n TEvent extends {\n addListener(listener: infer TListener): () => void;\n } ? TListener : never;\n"]}
|
|
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,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,KA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Aa,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":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Events\n */\n\nimport { UnexpectedErrors } from \"./UnexpectedErrors\";\n\n/** A function invoked when a BeEvent is raised.\n * @public\n */\nexport type Listener = (...arg: any[]) => void;\n\ninterface EventContext {\n listener: Listener | undefined;\n scope: any;\n once: boolean;\n}\n\n/**\n * Manages a set of *listeners* for a particular event and notifies them when the event is raised.\n * This class is usually instantiated inside of a container class and\n * exposed as a property for others to *subscribe* via [[BeEvent.addListener]].\n * @public\n */\nexport class BeEvent<T extends Listener> {\n private _listeners: EventContext[] = [];\n private _emitDepth: number = 0;\n\n /** The number of listeners currently subscribed to the event. */\n public get numberOfListeners() { return this._listeners.length; }\n\n /**\n * Registers a Listener to be executed whenever this event is raised.\n * @param listener The function to be executed when the event is raised.\n * @param scope An optional object scope to serve as the 'this' pointer when listener is invoked.\n * @returns A function that will remove this event listener.\n * @see [[BeEvent.raiseEvent]], [[BeEvent.removeListener]]\n */\n public addListener(listener: T, scope?: any): () => void {\n this._listeners.push({ listener, scope, once: false });\n return () => this.removeListener(listener, scope);\n }\n\n /**\n * Registers a callback function to be executed *only once* when the event is raised.\n * @param listener The function to be executed once when the event is raised.\n * @param scope An optional object scope to serve as the `this` pointer in which the listener function will execute.\n * @returns A function that will remove this event listener.\n * @see [[BeEvent.raiseEvent]], [[BeEvent.removeListener]]\n */\n public addOnce(listener: T, scope?: any): () => void {\n this._listeners.push({ listener, scope, once: true });\n return () => this.removeListener(listener, scope);\n }\n\n /**\n * Un-register a previously registered listener.\n * @param listener The listener to be unregistered.\n * @param scope The scope that was originally passed to addListener.\n * @returns 'true' if the listener was removed; 'false' if the listener and scope are not registered with the event.\n * @see [[BeEvent.raiseEvent]], [[BeEvent.addListener]]\n */\n public removeListener(listener: T, scope?: any): boolean {\n const listeners = this._listeners;\n\n for (let i = 0; i < listeners.length; ++i) {\n const context = listeners[i];\n if (context.listener === listener && context.scope === scope) {\n if (this._emitDepth > 0) {\n context.listener = undefined;\n } else {\n listeners.splice(i, 1);\n }\n return true;\n }\n }\n return false;\n }\n\n /**\n * Raises the event by calling each registered listener with the supplied arguments.\n * @param args This method takes any number of parameters and passes them through to the listeners.\n * @see [[BeEvent.removeListener]], [[BeEvent.addListener]]\n */\n public raiseEvent(...args: Parameters<T>) {\n this._emitDepth++;\n\n const listeners = this._listeners;\n const length = listeners.length;\n let dropped = false;\n\n for (let i = 0; i < length; ++i) {\n const context = listeners[i];\n if (!context.listener) {\n dropped = true;\n } else {\n try {\n context.listener.apply(context.scope, args);\n } catch (e) {\n UnexpectedErrors.handle(e);\n }\n if (!context.listener) {\n // listener was removed during its own callback\n dropped = true;\n } else if (context.once) {\n context.listener = undefined;\n dropped = true;\n }\n }\n }\n\n this._emitDepth--;\n\n // Only sweep tombstoned entries when the outermost emit completes,\n // so nested raiseEvent calls never mutate the array mid-iteration.\n if (dropped && this._emitDepth === 0)\n this._listeners = this._listeners.filter((ctx) => ctx.listener !== undefined);\n }\n\n /** Determine whether this BeEvent has a specified listener registered.\n * @param listener The listener to check.\n * @param scope optional scope argument to match call to addListener\n */\n public has(listener: T, scope?: any): boolean {\n for (const ctx of this._listeners) {\n if (ctx.listener === listener && ctx.scope === scope) {\n return true;\n }\n }\n return false;\n }\n\n /** Clear all Listeners from this BeEvent. */\n public clear(): void { this._listeners.length = 0; }\n}\n\n/** Specialization of BeEvent for events that take a single strongly typed argument, primarily used for UI events.\n * @public\n */\nexport class BeUiEvent<TEventArgs> extends BeEvent<(args: TEventArgs) => void> {\n /** Raises event with single strongly typed argument. */\n public emit(args: TEventArgs): void { this.raiseEvent(args); }\n}\n\ninterface UnorderedEventContext {\n listener: Listener | undefined;\n scope: any;\n once: boolean;\n}\n\n/**\n * Manages a set of *listeners* for a particular event and notifies them when the event is raised.\n * Unlike [[BeEvent]], this class uses a `Set` internally to support safe concurrent modification\n * during emit. When a listener is removed during emit, it is marked for deferred removal instead\n * of mutating the set immediately.\n *\n * Listeners are managed exclusively through the disposal closure returned by [[addListener]] and\n * [[addOnce]]. There is no `removeListener` or `has` method — callers must capture the returned\n * closure to unsubscribe.\n * @beta\n */\nexport class BeUnorderedEvent<T extends Listener> {\n private _listeners: Set<UnorderedEventContext> = new Set();\n private _emitDepth: number = 0;\n private _hasTombstones: boolean = false;\n\n /** The number of listeners currently subscribed to the event.\n * @note During `raiseEvent()`, this may include listeners that have been removed or are one-shot\n * but are awaiting deferred cleanup. The count is accurate outside of `raiseEvent()`.\n */\n public get numberOfListeners() { return this._listeners.size; }\n\n /**\n * Registers a Listener to be executed whenever this event is raised.\n * @param listener The function to be executed when the event is raised.\n * @param scope An optional object scope to serve as the 'this' pointer when listener is invoked.\n * @returns A function that will remove this event listener in O(1).\n */\n public addListener(listener: T, scope?: any): () => void {\n const ctx: UnorderedEventContext = { listener, scope, once: false };\n this._listeners.add(ctx);\n return () => this._removeCtx(ctx);\n }\n\n /**\n * Registers a callback function to be executed *only once* when the event is raised.\n * @param listener The function to be executed once when the event is raised.\n * @param scope An optional object scope to serve as the `this` pointer in which the listener function will execute.\n * @returns A function that will remove this event listener in O(1).\n */\n public addOnce(listener: T, scope?: any): () => void {\n const ctx: UnorderedEventContext = { listener, scope, once: true };\n this._listeners.add(ctx);\n return () => this._removeCtx(ctx);\n }\n\n /** Remove a specific context entry, deferring during emit. */\n private _removeCtx(ctx: UnorderedEventContext): void {\n if (this._emitDepth > 0) {\n ctx.listener = undefined; // tombstone for deferred cleanup\n this._hasTombstones = true;\n } else {\n this._listeners.delete(ctx);\n }\n }\n\n /**\n * Raises the event by calling each registered listener with the supplied arguments.\n * @param args This method takes any number of parameters and passes them through to the listeners.\n */\n public raiseEvent(...args: Parameters<T>) {\n this._emitDepth++;\n\n for (const ctx of this._listeners) {\n if (!ctx.listener) {\n continue;\n }\n try {\n ctx.listener.apply(ctx.scope, args);\n } catch (e) {\n UnexpectedErrors.handle(e);\n }\n if (ctx.listener && ctx.once) {\n ctx.listener = undefined;\n this._hasTombstones = true;\n }\n }\n\n this._emitDepth--;\n\n // Only clean up tombstoned entries when we're back at the outermost emit\n if (this._hasTombstones && this._emitDepth === 0) {\n this._hasTombstones = false;\n for (const ctx of this._listeners) {\n if (ctx.listener === undefined)\n this._listeners.delete(ctx);\n }\n }\n }\n\n /** Clear all listeners from this BeUnorderedEvent.\n * @note If called during `raiseEvent`, remaining listeners in the current iteration are skipped\n * immediately rather than being tombstoned.\n */\n public clear(): void { this._listeners.clear(); }\n}\n\n/** Specialization of BeUnorderedEvent for events that take a single strongly typed argument, primarily used for UI events.\n * @beta\n */\nexport class BeUnorderedUiEvent<TEventArgs> extends BeUnorderedEvent<(args: TEventArgs) => void> {\n /** Raises event with single strongly typed argument. */\n public emit(args: TEventArgs): void { this.raiseEvent(args); }\n}\n\n/**\n * A list of BeEvent objects, accessible by an event name.\n * This class may be used instead of explicitly declaring each BeEvent as a member of a containing class.\n * @public\n */\nexport class BeEventList<T extends Listener> {\n private _events: { [name: string]: BeEvent<T> | undefined } = {};\n\n /**\n * Gets the event associated with the specified name, creating the event if it does not already exist.\n * @param name The name of the event.\n */\n public get(name: string): BeEvent<T> {\n let event = this._events[name];\n if (event)\n return event;\n\n event = new BeEvent();\n this._events[name] = event;\n return event;\n }\n\n /**\n * Removes the event associated with a name.\n * @param name The name of the event.\n */\n public remove(name: string): void {\n this._events[name] = undefined;\n }\n}\n\n/**\n * Retrieves the type of the callback function for an event type like [[BeEvent]].\n * For example:\n * ```ts\n * const event = new BeEvent<(x: number, y: string) => void>();\n * const callback: ListenerType<typeof event> = (x, y) => {\n * console.log(`${x}, ${y}`);\n * };\n * ```\n *\n * @public\n */\nexport type ListenerType<TEvent extends {\n addListener(listener: Listener): () => void;\n}> =\n TEvent extends {\n addListener(listener: infer TListener): () => void;\n } ? TListener : never;\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module Utils
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Wrapper function designed to be used for callbacks called by setInterval or setTimeout in order to propagate any
|
|
6
|
+
* exceptions thrown in the callback to the main promise chain. It does this by creating a new promise for the callback
|
|
7
|
+
* invocation and adding it to the timerPromises set. The main promise chain can then await
|
|
8
|
+
* Promise.all(timerPromises) to catch any exceptions thrown in any of the callbacks. Note that if the callback
|
|
9
|
+
* completes successfully, the promise is resolved and removed from the set. If it throws an exception, the promise is
|
|
10
|
+
* rejected but not removed from the set, so that the main promise chain can detect that an error occurred and handle
|
|
11
|
+
* it appropriately.
|
|
12
|
+
* @param timerPromises A set of promises representing the currently active timer callbacks.
|
|
13
|
+
* @param callback The async callback to be executed within the timer.
|
|
14
|
+
* @beta
|
|
15
|
+
*/
|
|
16
|
+
export declare function wrapTimerCallback(timerPromises: Set<Promise<void>>, callback: () => Promise<void>): Promise<void>;
|
|
17
|
+
//# sourceMappingURL=UtilityFunctions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UtilityFunctions.d.ts","sourceRoot":"","sources":["../../src/UtilityFunctions.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH;;;;;;;;;;;GAWG;AACH,wBAAsB,iBAAiB,CAAC,aAAa,EAAE,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,iBAgCvG"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
/** @packageDocumentation
|
|
7
|
+
* @module Utils
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.wrapTimerCallback = wrapTimerCallback;
|
|
11
|
+
/**
|
|
12
|
+
* Wrapper function designed to be used for callbacks called by setInterval or setTimeout in order to propagate any
|
|
13
|
+
* exceptions thrown in the callback to the main promise chain. It does this by creating a new promise for the callback
|
|
14
|
+
* invocation and adding it to the timerPromises set. The main promise chain can then await
|
|
15
|
+
* Promise.all(timerPromises) to catch any exceptions thrown in any of the callbacks. Note that if the callback
|
|
16
|
+
* completes successfully, the promise is resolved and removed from the set. If it throws an exception, the promise is
|
|
17
|
+
* rejected but not removed from the set, so that the main promise chain can detect that an error occurred and handle
|
|
18
|
+
* it appropriately.
|
|
19
|
+
* @param timerPromises A set of promises representing the currently active timer callbacks.
|
|
20
|
+
* @param callback The async callback to be executed within the timer.
|
|
21
|
+
* @beta
|
|
22
|
+
*/
|
|
23
|
+
async function wrapTimerCallback(timerPromises, callback) {
|
|
24
|
+
let resolvePromise;
|
|
25
|
+
let rejectPromise;
|
|
26
|
+
// The callback of the Promise constructor does not have access to the promise itself, so all we do there is
|
|
27
|
+
// capture the resolve and reject functions for use in the async callback that would have otherwise been
|
|
28
|
+
// placed in the setInterval or setTimeout callback.
|
|
29
|
+
const timerPromise = new Promise((resolve, reject) => {
|
|
30
|
+
resolvePromise = resolve;
|
|
31
|
+
rejectPromise = reject;
|
|
32
|
+
});
|
|
33
|
+
// Note: when we get here, resolvePromise and rejectPromise will always be defined, but there is no way to
|
|
34
|
+
// convince TS of that fact without extra unnecessary checks, so we use ?. when accessing them.
|
|
35
|
+
// Prevent unhandled rejection warnings. The rejection is still observable
|
|
36
|
+
// when the consumer awaits Promise.all(promises).
|
|
37
|
+
timerPromise.catch(() => { });
|
|
38
|
+
timerPromises.add(timerPromise);
|
|
39
|
+
const cleanupAndResolve = () => {
|
|
40
|
+
resolvePromise?.();
|
|
41
|
+
// No need to keep track of this promise anymore since it's resolved.
|
|
42
|
+
timerPromises.delete(timerPromise);
|
|
43
|
+
};
|
|
44
|
+
try {
|
|
45
|
+
await callback();
|
|
46
|
+
cleanupAndResolve();
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
rejectPromise?.(err);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=UtilityFunctions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UtilityFunctions.js","sourceRoot":"","sources":["../../src/UtilityFunctions.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;AAcH,8CAgCC;AA5CD;;;;;;;;;;;GAWG;AACI,KAAK,UAAU,iBAAiB,CAAC,aAAiC,EAAE,QAA6B;IACtG,IAAI,cAAwC,CAAC;IAC7C,IAAI,aAAmD,CAAC;IAExD,4GAA4G;IAC5G,wGAAwG;IACxG,oDAAoD;IACpD,MAAM,YAAY,GAAG,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACzD,cAAc,GAAG,OAAO,CAAC;QACzB,aAAa,GAAG,MAAM,CAAC;IACzB,CAAC,CAAC,CAAC;IACH,0GAA0G;IAC1G,+FAA+F;IAE/F,0EAA0E;IAC1E,kDAAkD;IAClD,YAAY,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IAE7B,aAAa,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IAEhC,MAAM,iBAAiB,GAAG,GAAG,EAAE;QAC7B,cAAc,EAAE,EAAE,CAAC;QACnB,qEAAqE;QACrE,aAAa,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;IACrC,CAAC,CAAC;IAEF,IAAI,CAAC;QACH,MAAM,QAAQ,EAAE,CAAC;QACjB,iBAAiB,EAAE,CAAC;IACtB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,aAAa,EAAE,CAAC,GAAG,CAAC,CAAC;IACvB,CAAC;AACH,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Utils\n */\n\n/**\n * Wrapper function designed to be used for callbacks called by setInterval or setTimeout in order to propagate any\n * exceptions thrown in the callback to the main promise chain. It does this by creating a new promise for the callback\n * invocation and adding it to the timerPromises set. The main promise chain can then await\n * Promise.all(timerPromises) to catch any exceptions thrown in any of the callbacks. Note that if the callback\n * completes successfully, the promise is resolved and removed from the set. If it throws an exception, the promise is\n * rejected but not removed from the set, so that the main promise chain can detect that an error occurred and handle\n * it appropriately.\n * @param timerPromises A set of promises representing the currently active timer callbacks.\n * @param callback The async callback to be executed within the timer.\n * @beta\n */\nexport async function wrapTimerCallback(timerPromises: Set<Promise<void>>, callback: () => Promise<void>) {\n let resolvePromise: (() => void) | undefined;\n let rejectPromise: ((reason?: any) => void) | undefined;\n\n // The callback of the Promise constructor does not have access to the promise itself, so all we do there is\n // capture the resolve and reject functions for use in the async callback that would have otherwise been\n // placed in the setInterval or setTimeout callback.\n const timerPromise = new Promise<void>((resolve, reject) => {\n resolvePromise = resolve;\n rejectPromise = reject;\n });\n // Note: when we get here, resolvePromise and rejectPromise will always be defined, but there is no way to\n // convince TS of that fact without extra unnecessary checks, so we use ?. when accessing them.\n\n // Prevent unhandled rejection warnings. The rejection is still observable\n // when the consumer awaits Promise.all(promises).\n timerPromise.catch(() => {});\n\n timerPromises.add(timerPromise);\n\n const cleanupAndResolve = () => {\n resolvePromise?.();\n // No need to keep track of this promise anymore since it's resolved.\n timerPromises.delete(timerPromise);\n };\n\n try {\n await callback();\n cleanupAndResolve();\n } catch (err) {\n rejectPromise?.(err);\n }\n}\n"]}
|
|
@@ -32,6 +32,7 @@ export * from "./Tracing";
|
|
|
32
32
|
export * from "./TupleKeyedMap";
|
|
33
33
|
export * from "./TypedArrayBuilder";
|
|
34
34
|
export * from "./UnexpectedErrors";
|
|
35
|
+
export * from "./UtilityFunctions";
|
|
35
36
|
export * from "./UtilityTypes";
|
|
36
37
|
export * from "./YieldManager";
|
|
37
38
|
export * from "./internal/cross-package";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-bentley.d.ts","sourceRoot":"","sources":["../../src/core-bentley.ts"],"names":[],"mappings":"AAIA,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,MAAM,CAAC;AACrB,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,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AAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAG/B,cAAc,0BAA0B,CAAC;AAEzC;;GAEG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG"}
|
package/lib/cjs/core-bentley.js
CHANGED
|
@@ -52,6 +52,7 @@ __exportStar(require("./Tracing"), exports);
|
|
|
52
52
|
__exportStar(require("./TupleKeyedMap"), exports);
|
|
53
53
|
__exportStar(require("./TypedArrayBuilder"), exports);
|
|
54
54
|
__exportStar(require("./UnexpectedErrors"), exports);
|
|
55
|
+
__exportStar(require("./UtilityFunctions"), exports);
|
|
55
56
|
__exportStar(require("./UtilityTypes"), exports);
|
|
56
57
|
__exportStar(require("./YieldManager"), exports);
|
|
57
58
|
// Temporarily (until 5.0) export top-level internal APIs to avoid breaking callers.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-bentley.js","sourceRoot":"","sources":["../../src/core-bentley.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;;+FAG+F;AAC/F,gDAA8B;AAC9B,2CAAyB;AACzB,4CAA0B;AAC1B,iDAA+B;AAC/B,0DAAwC;AACxC,mDAAiC;AACjC,6CAA2B;AAC3B,+CAA6B;AAC7B,+CAA6B;AAC7B,4CAA0B;AAC1B,sDAAoC;AACpC,+CAA6B;AAC7B,+CAA6B;AAC7B,2CAAyB;AACzB,uCAAqB;AACrB,6CAA2B;AAC3B,+CAA6B;AAC7B,8CAA4B;AAC5B,2CAAyB;AACzB,2CAAyB;AACzB,kDAAgC;AAChC,qDAAmC;AACnC,wDAAsC;AACtC,+CAA6B;AAC7B,mDAAiC;AACjC,kDAAgC;AAChC,oDAAkC;AAClC,gDAA8B;AAC9B,gDAA8B;AAC9B,yCAAuB;AACvB,4CAA0B;AAC1B,kDAAgC;AAChC,sDAAoC;AACpC,qDAAmC;AACnC,iDAA+B;AAC/B,iDAA+B;AAE/B,oFAAoF;AACpF,2DAAyC;AAEzC;;GAEG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nexport * from \"./AccessToken\";\nexport * from \"./Assert\";\nexport * from \"./BeEvent\";\nexport * from \"./BentleyError\";\nexport * from \"./BentleyLoggerCategory\";\nexport * from \"./StatusCategory\";\nexport * from \"./BeSQLite\";\nexport * from \"./ByteStream\";\nexport * from \"./ClassUtils\";\nexport * from \"./Compare\";\nexport * from \"./CompressedId64Set\";\nexport * from \"./Dictionary\";\nexport * from \"./Disposable\";\nexport * from \"./Expect\";\nexport * from \"./Id\";\nexport * from \"./IndexMap\";\nexport * from \"./JsonSchema\";\nexport * from \"./JsonUtils\";\nexport * from \"./Logger\";\nexport * from \"./LRUMap\";\nexport * from \"./ObservableSet\";\nexport * from \"./OneAtATimeAction\";\nexport * from \"./OrderedId64Iterable\";\nexport * from \"./OrderedSet\";\nexport * from \"./partitionArray\";\nexport * from \"./PriorityQueue\";\nexport * from \"./ProcessDetector\";\nexport * from \"./SortedArray\";\nexport * from \"./StringUtils\";\nexport * from \"./Time\";\nexport * from \"./Tracing\";\nexport * from \"./TupleKeyedMap\";\nexport * from \"./TypedArrayBuilder\";\nexport * from \"./UnexpectedErrors\";\nexport * from \"./UtilityTypes\";\nexport * from \"./YieldManager\";\n\n// Temporarily (until 5.0) export top-level internal APIs to avoid breaking callers.\nexport * from \"./internal/cross-package\";\n\n/** @docs-package-description\n * The core-bentley package contains classes to solve problems that are common for both client and server use cases.\n */\n/**\n * @docs-group-description BeSQLite\n * Classes for working with SQLite databases. SQLite underlies IModelDb and ECDb - see [Executing ECSQL]($docs/learning/ECSQL.md)\n */\n/**\n * @docs-group-description Errors\n * Classes for working with errors.\n */\n/**\n * @docs-group-description Events\n * Classes for raising and handling events.\n */\n/**\n * @docs-group-description Ids\n * Classes for working with unique identifiers.\n */\n/**\n * @docs-group-description Logging\n * Classes for configuring and logging diagnostic messages - see [Learning about Logging]($docs/learning/common/Logging.md)\n */\n/**\n * @docs-group-description Collections\n * Specialized, customizable collection classes like priority queues.\n */\n/**\n * @docs-group-description Json\n * utilities for dealing with Json strings and files.\n */\n/**\n * @docs-group-description Utils\n * Miscellaneous utility classes.\n */\n/**\n * @docs-group-description ProcessDetector\n * Functions for determining the type of the current JavaScript process.\n */\n"]}
|
|
1
|
+
{"version":3,"file":"core-bentley.js","sourceRoot":"","sources":["../../src/core-bentley.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;;+FAG+F;AAC/F,gDAA8B;AAC9B,2CAAyB;AACzB,4CAA0B;AAC1B,iDAA+B;AAC/B,0DAAwC;AACxC,mDAAiC;AACjC,6CAA2B;AAC3B,+CAA6B;AAC7B,+CAA6B;AAC7B,4CAA0B;AAC1B,sDAAoC;AACpC,+CAA6B;AAC7B,+CAA6B;AAC7B,2CAAyB;AACzB,uCAAqB;AACrB,6CAA2B;AAC3B,+CAA6B;AAC7B,8CAA4B;AAC5B,2CAAyB;AACzB,2CAAyB;AACzB,kDAAgC;AAChC,qDAAmC;AACnC,wDAAsC;AACtC,+CAA6B;AAC7B,mDAAiC;AACjC,kDAAgC;AAChC,oDAAkC;AAClC,gDAA8B;AAC9B,gDAA8B;AAC9B,yCAAuB;AACvB,4CAA0B;AAC1B,kDAAgC;AAChC,sDAAoC;AACpC,qDAAmC;AACnC,qDAAmC;AACnC,iDAA+B;AAC/B,iDAA+B;AAE/B,oFAAoF;AACpF,2DAAyC;AAEzC;;GAEG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nexport * from \"./AccessToken\";\nexport * from \"./Assert\";\nexport * from \"./BeEvent\";\nexport * from \"./BentleyError\";\nexport * from \"./BentleyLoggerCategory\";\nexport * from \"./StatusCategory\";\nexport * from \"./BeSQLite\";\nexport * from \"./ByteStream\";\nexport * from \"./ClassUtils\";\nexport * from \"./Compare\";\nexport * from \"./CompressedId64Set\";\nexport * from \"./Dictionary\";\nexport * from \"./Disposable\";\nexport * from \"./Expect\";\nexport * from \"./Id\";\nexport * from \"./IndexMap\";\nexport * from \"./JsonSchema\";\nexport * from \"./JsonUtils\";\nexport * from \"./Logger\";\nexport * from \"./LRUMap\";\nexport * from \"./ObservableSet\";\nexport * from \"./OneAtATimeAction\";\nexport * from \"./OrderedId64Iterable\";\nexport * from \"./OrderedSet\";\nexport * from \"./partitionArray\";\nexport * from \"./PriorityQueue\";\nexport * from \"./ProcessDetector\";\nexport * from \"./SortedArray\";\nexport * from \"./StringUtils\";\nexport * from \"./Time\";\nexport * from \"./Tracing\";\nexport * from \"./TupleKeyedMap\";\nexport * from \"./TypedArrayBuilder\";\nexport * from \"./UnexpectedErrors\";\nexport * from \"./UtilityFunctions\";\nexport * from \"./UtilityTypes\";\nexport * from \"./YieldManager\";\n\n// Temporarily (until 5.0) export top-level internal APIs to avoid breaking callers.\nexport * from \"./internal/cross-package\";\n\n/** @docs-package-description\n * The core-bentley package contains classes to solve problems that are common for both client and server use cases.\n */\n/**\n * @docs-group-description BeSQLite\n * Classes for working with SQLite databases. SQLite underlies IModelDb and ECDb - see [Executing ECSQL]($docs/learning/ECSQL.md)\n */\n/**\n * @docs-group-description Errors\n * Classes for working with errors.\n */\n/**\n * @docs-group-description Events\n * Classes for raising and handling events.\n */\n/**\n * @docs-group-description Ids\n * Classes for working with unique identifiers.\n */\n/**\n * @docs-group-description Logging\n * Classes for configuring and logging diagnostic messages - see [Learning about Logging]($docs/learning/common/Logging.md)\n */\n/**\n * @docs-group-description Collections\n * Specialized, customizable collection classes like priority queues.\n */\n/**\n * @docs-group-description Json\n * utilities for dealing with Json strings and files.\n */\n/**\n * @docs-group-description Utils\n * Miscellaneous utility classes.\n */\n/**\n * @docs-group-description ProcessDetector\n * Functions for determining the type of the current JavaScript process.\n */\n"]}
|
package/lib/esm/BeEvent.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export type Listener = (...arg: any[]) => void;
|
|
|
13
13
|
*/
|
|
14
14
|
export declare class BeEvent<T extends Listener> {
|
|
15
15
|
private _listeners;
|
|
16
|
-
private
|
|
16
|
+
private _emitDepth;
|
|
17
17
|
/** The number of listeners currently subscribed to the event. */
|
|
18
18
|
get numberOfListeners(): number;
|
|
19
19
|
/**
|
|
@@ -61,6 +61,60 @@ export declare class BeUiEvent<TEventArgs> extends BeEvent<(args: TEventArgs) =>
|
|
|
61
61
|
/** Raises event with single strongly typed argument. */
|
|
62
62
|
emit(args: TEventArgs): void;
|
|
63
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Manages a set of *listeners* for a particular event and notifies them when the event is raised.
|
|
66
|
+
* Unlike [[BeEvent]], this class uses a `Set` internally to support safe concurrent modification
|
|
67
|
+
* during emit. When a listener is removed during emit, it is marked for deferred removal instead
|
|
68
|
+
* of mutating the set immediately.
|
|
69
|
+
*
|
|
70
|
+
* Listeners are managed exclusively through the disposal closure returned by [[addListener]] and
|
|
71
|
+
* [[addOnce]]. There is no `removeListener` or `has` method — callers must capture the returned
|
|
72
|
+
* closure to unsubscribe.
|
|
73
|
+
* @beta
|
|
74
|
+
*/
|
|
75
|
+
export declare class BeUnorderedEvent<T extends Listener> {
|
|
76
|
+
private _listeners;
|
|
77
|
+
private _emitDepth;
|
|
78
|
+
private _hasTombstones;
|
|
79
|
+
/** The number of listeners currently subscribed to the event.
|
|
80
|
+
* @note During `raiseEvent()`, this may include listeners that have been removed or are one-shot
|
|
81
|
+
* but are awaiting deferred cleanup. The count is accurate outside of `raiseEvent()`.
|
|
82
|
+
*/
|
|
83
|
+
get numberOfListeners(): number;
|
|
84
|
+
/**
|
|
85
|
+
* Registers a Listener to be executed whenever this event is raised.
|
|
86
|
+
* @param listener The function to be executed when the event is raised.
|
|
87
|
+
* @param scope An optional object scope to serve as the 'this' pointer when listener is invoked.
|
|
88
|
+
* @returns A function that will remove this event listener in O(1).
|
|
89
|
+
*/
|
|
90
|
+
addListener(listener: T, scope?: any): () => void;
|
|
91
|
+
/**
|
|
92
|
+
* Registers a callback function to be executed *only once* when the event is raised.
|
|
93
|
+
* @param listener The function to be executed once when the event is raised.
|
|
94
|
+
* @param scope An optional object scope to serve as the `this` pointer in which the listener function will execute.
|
|
95
|
+
* @returns A function that will remove this event listener in O(1).
|
|
96
|
+
*/
|
|
97
|
+
addOnce(listener: T, scope?: any): () => void;
|
|
98
|
+
/** Remove a specific context entry, deferring during emit. */
|
|
99
|
+
private _removeCtx;
|
|
100
|
+
/**
|
|
101
|
+
* Raises the event by calling each registered listener with the supplied arguments.
|
|
102
|
+
* @param args This method takes any number of parameters and passes them through to the listeners.
|
|
103
|
+
*/
|
|
104
|
+
raiseEvent(...args: Parameters<T>): void;
|
|
105
|
+
/** Clear all listeners from this BeUnorderedEvent.
|
|
106
|
+
* @note If called during `raiseEvent`, remaining listeners in the current iteration are skipped
|
|
107
|
+
* immediately rather than being tombstoned.
|
|
108
|
+
*/
|
|
109
|
+
clear(): void;
|
|
110
|
+
}
|
|
111
|
+
/** Specialization of BeUnorderedEvent for events that take a single strongly typed argument, primarily used for UI events.
|
|
112
|
+
* @beta
|
|
113
|
+
*/
|
|
114
|
+
export declare class BeUnorderedUiEvent<TEventArgs> extends BeUnorderedEvent<(args: TEventArgs) => void> {
|
|
115
|
+
/** Raises event with single strongly typed argument. */
|
|
116
|
+
emit(args: TEventArgs): void;
|
|
117
|
+
}
|
|
64
118
|
/**
|
|
65
119
|
* A list of BeEvent objects, accessible by an event name.
|
|
66
120
|
* This class may be used instead of explicitly declaring each BeEvent as a member of a containing class.
|
package/lib/esm/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;AAQ/C;;;;;GAKG;AACH,qBAAa,OAAO,CAAC,CAAC,SAAS,QAAQ;IACrC,OAAO,CAAC,UAAU,CAAsB;IACxC,OAAO,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;AAQ/C;;;;;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,E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,wDAAwD;IACjD,IAAI,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI;CACpC;AAED;;;;GAIG;AACH,qBAAa,WAAW,CAAC,CAAC,SAAS,QAAQ;IACzC,OAAO,CAAC,OAAO,CAAkD;IAEjE;;;OAGG;IACI,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IAUpC;;;OAGG;IACI,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;CAGlC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,YAAY,CAAC,MAAM,SAAS;IACtC,WAAW,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,IAAI,CAAC;CAC7C,IACC,MAAM,SAAS;IACb,WAAW,CAAC,QAAQ,EAAE,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC;CACpD,GAAG,SAAS,GAAG,KAAK,CAAC"}
|
package/lib/esm/BeEvent.js
CHANGED
|
@@ -14,7 +14,7 @@ import { UnexpectedErrors } from "./UnexpectedErrors";
|
|
|
14
14
|
*/
|
|
15
15
|
export class BeEvent {
|
|
16
16
|
_listeners = [];
|
|
17
|
-
|
|
17
|
+
_emitDepth = 0;
|
|
18
18
|
/** The number of listeners currently subscribed to the event. */
|
|
19
19
|
get numberOfListeners() { return this._listeners.length; }
|
|
20
20
|
/**
|
|
@@ -51,7 +51,7 @@ export class BeEvent {
|
|
|
51
51
|
for (let i = 0; i < listeners.length; ++i) {
|
|
52
52
|
const context = listeners[i];
|
|
53
53
|
if (context.listener === listener && context.scope === scope) {
|
|
54
|
-
if (this.
|
|
54
|
+
if (this._emitDepth > 0) {
|
|
55
55
|
context.listener = undefined;
|
|
56
56
|
}
|
|
57
57
|
else {
|
|
@@ -68,7 +68,7 @@ export class BeEvent {
|
|
|
68
68
|
* @see [[BeEvent.removeListener]], [[BeEvent.addListener]]
|
|
69
69
|
*/
|
|
70
70
|
raiseEvent(...args) {
|
|
71
|
-
this.
|
|
71
|
+
this._emitDepth++;
|
|
72
72
|
const listeners = this._listeners;
|
|
73
73
|
const length = listeners.length;
|
|
74
74
|
let dropped = false;
|
|
@@ -84,16 +84,21 @@ export class BeEvent {
|
|
|
84
84
|
catch (e) {
|
|
85
85
|
UnexpectedErrors.handle(e);
|
|
86
86
|
}
|
|
87
|
-
if (context.
|
|
87
|
+
if (!context.listener) {
|
|
88
|
+
// listener was removed during its own callback
|
|
89
|
+
dropped = true;
|
|
90
|
+
}
|
|
91
|
+
else if (context.once) {
|
|
88
92
|
context.listener = undefined;
|
|
89
93
|
dropped = true;
|
|
90
94
|
}
|
|
91
95
|
}
|
|
92
96
|
}
|
|
93
|
-
|
|
94
|
-
|
|
97
|
+
this._emitDepth--;
|
|
98
|
+
// Only sweep tombstoned entries when the outermost emit completes,
|
|
99
|
+
// so nested raiseEvent calls never mutate the array mid-iteration.
|
|
100
|
+
if (dropped && this._emitDepth === 0)
|
|
95
101
|
this._listeners = this._listeners.filter((ctx) => ctx.listener !== undefined);
|
|
96
|
-
this._insideRaiseEvent = false;
|
|
97
102
|
}
|
|
98
103
|
/** Determine whether this BeEvent has a specified listener registered.
|
|
99
104
|
* @param listener The listener to check.
|
|
@@ -117,6 +122,102 @@ export class BeUiEvent extends BeEvent {
|
|
|
117
122
|
/** Raises event with single strongly typed argument. */
|
|
118
123
|
emit(args) { this.raiseEvent(args); }
|
|
119
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* Manages a set of *listeners* for a particular event and notifies them when the event is raised.
|
|
127
|
+
* Unlike [[BeEvent]], this class uses a `Set` internally to support safe concurrent modification
|
|
128
|
+
* during emit. When a listener is removed during emit, it is marked for deferred removal instead
|
|
129
|
+
* of mutating the set immediately.
|
|
130
|
+
*
|
|
131
|
+
* Listeners are managed exclusively through the disposal closure returned by [[addListener]] and
|
|
132
|
+
* [[addOnce]]. There is no `removeListener` or `has` method — callers must capture the returned
|
|
133
|
+
* closure to unsubscribe.
|
|
134
|
+
* @beta
|
|
135
|
+
*/
|
|
136
|
+
export class BeUnorderedEvent {
|
|
137
|
+
_listeners = new Set();
|
|
138
|
+
_emitDepth = 0;
|
|
139
|
+
_hasTombstones = false;
|
|
140
|
+
/** The number of listeners currently subscribed to the event.
|
|
141
|
+
* @note During `raiseEvent()`, this may include listeners that have been removed or are one-shot
|
|
142
|
+
* but are awaiting deferred cleanup. The count is accurate outside of `raiseEvent()`.
|
|
143
|
+
*/
|
|
144
|
+
get numberOfListeners() { return this._listeners.size; }
|
|
145
|
+
/**
|
|
146
|
+
* Registers a Listener to be executed whenever this event is raised.
|
|
147
|
+
* @param listener The function to be executed when the event is raised.
|
|
148
|
+
* @param scope An optional object scope to serve as the 'this' pointer when listener is invoked.
|
|
149
|
+
* @returns A function that will remove this event listener in O(1).
|
|
150
|
+
*/
|
|
151
|
+
addListener(listener, scope) {
|
|
152
|
+
const ctx = { listener, scope, once: false };
|
|
153
|
+
this._listeners.add(ctx);
|
|
154
|
+
return () => this._removeCtx(ctx);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Registers a callback function to be executed *only once* when the event is raised.
|
|
158
|
+
* @param listener The function to be executed once when the event is raised.
|
|
159
|
+
* @param scope An optional object scope to serve as the `this` pointer in which the listener function will execute.
|
|
160
|
+
* @returns A function that will remove this event listener in O(1).
|
|
161
|
+
*/
|
|
162
|
+
addOnce(listener, scope) {
|
|
163
|
+
const ctx = { listener, scope, once: true };
|
|
164
|
+
this._listeners.add(ctx);
|
|
165
|
+
return () => this._removeCtx(ctx);
|
|
166
|
+
}
|
|
167
|
+
/** Remove a specific context entry, deferring during emit. */
|
|
168
|
+
_removeCtx(ctx) {
|
|
169
|
+
if (this._emitDepth > 0) {
|
|
170
|
+
ctx.listener = undefined; // tombstone for deferred cleanup
|
|
171
|
+
this._hasTombstones = true;
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
this._listeners.delete(ctx);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Raises the event by calling each registered listener with the supplied arguments.
|
|
179
|
+
* @param args This method takes any number of parameters and passes them through to the listeners.
|
|
180
|
+
*/
|
|
181
|
+
raiseEvent(...args) {
|
|
182
|
+
this._emitDepth++;
|
|
183
|
+
for (const ctx of this._listeners) {
|
|
184
|
+
if (!ctx.listener) {
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
try {
|
|
188
|
+
ctx.listener.apply(ctx.scope, args);
|
|
189
|
+
}
|
|
190
|
+
catch (e) {
|
|
191
|
+
UnexpectedErrors.handle(e);
|
|
192
|
+
}
|
|
193
|
+
if (ctx.listener && ctx.once) {
|
|
194
|
+
ctx.listener = undefined;
|
|
195
|
+
this._hasTombstones = true;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
this._emitDepth--;
|
|
199
|
+
// Only clean up tombstoned entries when we're back at the outermost emit
|
|
200
|
+
if (this._hasTombstones && this._emitDepth === 0) {
|
|
201
|
+
this._hasTombstones = false;
|
|
202
|
+
for (const ctx of this._listeners) {
|
|
203
|
+
if (ctx.listener === undefined)
|
|
204
|
+
this._listeners.delete(ctx);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
/** Clear all listeners from this BeUnorderedEvent.
|
|
209
|
+
* @note If called during `raiseEvent`, remaining listeners in the current iteration are skipped
|
|
210
|
+
* immediately rather than being tombstoned.
|
|
211
|
+
*/
|
|
212
|
+
clear() { this._listeners.clear(); }
|
|
213
|
+
}
|
|
214
|
+
/** Specialization of BeUnorderedEvent for events that take a single strongly typed argument, primarily used for UI events.
|
|
215
|
+
* @beta
|
|
216
|
+
*/
|
|
217
|
+
export class BeUnorderedUiEvent extends BeUnorderedEvent {
|
|
218
|
+
/** Raises event with single strongly typed argument. */
|
|
219
|
+
emit(args) { this.raiseEvent(args); }
|
|
220
|
+
}
|
|
120
221
|
/**
|
|
121
222
|
* A list of BeEvent objects, accessible by an event name.
|
|
122
223
|
* This class may be used instead of explicitly declaring each BeEvent as a member of a containing class.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IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC;QAEhF,IAAI,CAAC,iBAAiB,GAAG,KAAK,CAAC;IACjC,CAAC;IAED;;;OAGG;IACI,GAAG,CAAC,QAAW,EAAE,KAAW;QACjC,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YAClC,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ,IAAI,GAAG,CAAC,KAAK,KAAK,KAAK,EAAE,CAAC;gBACrD,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,6CAA6C;IACtC,KAAK,KAAW,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;CACrD;AAED;;GAEG;AACH,MAAM,OAAO,SAAsB,SAAQ,OAAmC;IAC5E,wDAAwD;IACjD,IAAI,CAAC,IAAgB,IAAU,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;CAC/D;AAED;;;;GAIG;AACH,MAAM,OAAO,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","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Events\n */\n\nimport { UnexpectedErrors } from \"./UnexpectedErrors\";\n\n/** A function invoked when a BeEvent is raised.\n * @public\n */\nexport type Listener = (...arg: any[]) => void;\n\ninterface EventContext {\n listener: Listener | undefined;\n scope: any;\n once: boolean;\n}\n\n/**\n * Manages a set of *listeners* for a particular event and notifies them when the event is raised.\n * This class is usually instantiated inside of a container class and\n * exposed as a property for others to *subscribe* via [[BeEvent.addListener]].\n * @public\n */\nexport class BeEvent<T extends Listener> {\n private _listeners: EventContext[] = [];\n private _insideRaiseEvent: boolean = false;\n\n /** The number of listeners currently subscribed to the event. */\n public get numberOfListeners() { return this._listeners.length; }\n\n /**\n * Registers a Listener to be executed whenever this event is raised.\n * @param listener The function to be executed when the event is raised.\n * @param scope An optional object scope to serve as the 'this' pointer when listener is invoked.\n * @returns A function that will remove this event listener.\n * @see [[BeEvent.raiseEvent]], [[BeEvent.removeListener]]\n */\n public addListener(listener: T, scope?: any): () => void {\n this._listeners.push({ listener, scope, once: false });\n return () => this.removeListener(listener, scope);\n }\n\n /**\n * Registers a callback function to be executed *only once* when the event is raised.\n * @param listener The function to be executed once when the event is raised.\n * @param scope An optional object scope to serve as the `this` pointer in which the listener function will execute.\n * @returns A function that will remove this event listener.\n * @see [[BeEvent.raiseEvent]], [[BeEvent.removeListener]]\n */\n public addOnce(listener: T, scope?: any): () => void {\n this._listeners.push({ listener, scope, once: true });\n return () => this.removeListener(listener, scope);\n }\n\n /**\n * Un-register a previously registered listener.\n * @param listener The listener to be unregistered.\n * @param scope The scope that was originally passed to addListener.\n * @returns 'true' if the listener was removed; 'false' if the listener and scope are not registered with the event.\n * @see [[BeEvent.raiseEvent]], [[BeEvent.addListener]]\n */\n public removeListener(listener: T, scope?: any): boolean {\n const listeners = this._listeners;\n\n for (let i = 0; i < listeners.length; ++i) {\n const context = listeners[i];\n if (context.listener === listener && context.scope === scope) {\n if (this._insideRaiseEvent) {\n context.listener = undefined;\n } else {\n listeners.splice(i, 1);\n }\n return true;\n }\n }\n return false;\n }\n\n /**\n * Raises the event by calling each registered listener with the supplied arguments.\n * @param args This method takes any number of parameters and passes them through to the listeners.\n * @see [[BeEvent.removeListener]], [[BeEvent.addListener]]\n */\n public raiseEvent(...args: Parameters<T>) {\n this._insideRaiseEvent = true;\n\n const listeners = this._listeners;\n const length = listeners.length;\n let dropped = false;\n\n for (let i = 0; i < length; ++i) {\n const context = listeners[i];\n if (!context.listener) {\n dropped = true;\n } else {\n try {\n context.listener.apply(context.scope, args);\n } catch (e) {\n UnexpectedErrors.handle(e);\n }\n if (context.once) {\n context.listener = undefined;\n dropped = true;\n }\n }\n }\n\n // if we had dropped listeners, remove them now\n if (dropped)\n this._listeners = this._listeners.filter((ctx) => ctx.listener !== undefined);\n\n this._insideRaiseEvent = false;\n }\n\n /** Determine whether this BeEvent has a specified listener registered.\n * @param listener The listener to check.\n * @param scope optional scope argument to match call to addListener\n */\n public has(listener: T, scope?: any): boolean {\n for (const ctx of this._listeners) {\n if (ctx.listener === listener && ctx.scope === scope) {\n return true;\n }\n }\n return false;\n }\n\n /** Clear all Listeners from this BeEvent. */\n public clear(): void { this._listeners.length = 0; }\n}\n\n/** Specialization of BeEvent for events that take a single strongly typed argument, primarily used for UI events.\n * @public\n */\nexport class BeUiEvent<TEventArgs> extends BeEvent<(args: TEventArgs) => void> {\n /** Raises event with single strongly typed argument. */\n public emit(args: TEventArgs): void { this.raiseEvent(args); }\n}\n\n/**\n * A list of BeEvent objects, accessible by an event name.\n * This class may be used instead of explicitly declaring each BeEvent as a member of a containing class.\n * @public\n */\nexport class BeEventList<T extends Listener> {\n private _events: { [name: string]: BeEvent<T> | undefined } = {};\n\n /**\n * Gets the event associated with the specified name, creating the event if it does not already exist.\n * @param name The name of the event.\n */\n public get(name: string): BeEvent<T> {\n let event = this._events[name];\n if (event)\n return event;\n\n event = new BeEvent();\n this._events[name] = event;\n return event;\n }\n\n /**\n * Removes the event associated with a name.\n * @param name The name of the event.\n */\n public remove(name: string): void {\n this._events[name] = undefined;\n }\n}\n\n/**\n * Retrieves the type of the callback function for an event type like [[BeEvent]].\n * For example:\n * ```ts\n * const event = new BeEvent<(x: number, y: string) => void>();\n * const callback: ListenerType<typeof event> = (x, y) => {\n * console.log(`${x}, ${y}`);\n * };\n * ```\n *\n * @public\n */\nexport type ListenerType<TEvent extends {\n addListener(listener: Listener): () => void;\n}> =\n TEvent extends {\n addListener(listener: infer TListener): () => void;\n } ? TListener : never;\n"]}
|
|
1
|
+
{"version":3,"file":"BeEvent.js","sourceRoot":"","sources":["../../src/BeEvent.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAatD;;;;;GAKG;AACH,MAAM,OAAO,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,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IAC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P,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","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Events\n */\n\nimport { UnexpectedErrors } from \"./UnexpectedErrors\";\n\n/** A function invoked when a BeEvent is raised.\n * @public\n */\nexport type Listener = (...arg: any[]) => void;\n\ninterface EventContext {\n listener: Listener | undefined;\n scope: any;\n once: boolean;\n}\n\n/**\n * Manages a set of *listeners* for a particular event and notifies them when the event is raised.\n * This class is usually instantiated inside of a container class and\n * exposed as a property for others to *subscribe* via [[BeEvent.addListener]].\n * @public\n */\nexport class BeEvent<T extends Listener> {\n private _listeners: EventContext[] = [];\n private _emitDepth: number = 0;\n\n /** The number of listeners currently subscribed to the event. */\n public get numberOfListeners() { return this._listeners.length; }\n\n /**\n * Registers a Listener to be executed whenever this event is raised.\n * @param listener The function to be executed when the event is raised.\n * @param scope An optional object scope to serve as the 'this' pointer when listener is invoked.\n * @returns A function that will remove this event listener.\n * @see [[BeEvent.raiseEvent]], [[BeEvent.removeListener]]\n */\n public addListener(listener: T, scope?: any): () => void {\n this._listeners.push({ listener, scope, once: false });\n return () => this.removeListener(listener, scope);\n }\n\n /**\n * Registers a callback function to be executed *only once* when the event is raised.\n * @param listener The function to be executed once when the event is raised.\n * @param scope An optional object scope to serve as the `this` pointer in which the listener function will execute.\n * @returns A function that will remove this event listener.\n * @see [[BeEvent.raiseEvent]], [[BeEvent.removeListener]]\n */\n public addOnce(listener: T, scope?: any): () => void {\n this._listeners.push({ listener, scope, once: true });\n return () => this.removeListener(listener, scope);\n }\n\n /**\n * Un-register a previously registered listener.\n * @param listener The listener to be unregistered.\n * @param scope The scope that was originally passed to addListener.\n * @returns 'true' if the listener was removed; 'false' if the listener and scope are not registered with the event.\n * @see [[BeEvent.raiseEvent]], [[BeEvent.addListener]]\n */\n public removeListener(listener: T, scope?: any): boolean {\n const listeners = this._listeners;\n\n for (let i = 0; i < listeners.length; ++i) {\n const context = listeners[i];\n if (context.listener === listener && context.scope === scope) {\n if (this._emitDepth > 0) {\n context.listener = undefined;\n } else {\n listeners.splice(i, 1);\n }\n return true;\n }\n }\n return false;\n }\n\n /**\n * Raises the event by calling each registered listener with the supplied arguments.\n * @param args This method takes any number of parameters and passes them through to the listeners.\n * @see [[BeEvent.removeListener]], [[BeEvent.addListener]]\n */\n public raiseEvent(...args: Parameters<T>) {\n this._emitDepth++;\n\n const listeners = this._listeners;\n const length = listeners.length;\n let dropped = false;\n\n for (let i = 0; i < length; ++i) {\n const context = listeners[i];\n if (!context.listener) {\n dropped = true;\n } else {\n try {\n context.listener.apply(context.scope, args);\n } catch (e) {\n UnexpectedErrors.handle(e);\n }\n if (!context.listener) {\n // listener was removed during its own callback\n dropped = true;\n } else if (context.once) {\n context.listener = undefined;\n dropped = true;\n }\n }\n }\n\n this._emitDepth--;\n\n // Only sweep tombstoned entries when the outermost emit completes,\n // so nested raiseEvent calls never mutate the array mid-iteration.\n if (dropped && this._emitDepth === 0)\n this._listeners = this._listeners.filter((ctx) => ctx.listener !== undefined);\n }\n\n /** Determine whether this BeEvent has a specified listener registered.\n * @param listener The listener to check.\n * @param scope optional scope argument to match call to addListener\n */\n public has(listener: T, scope?: any): boolean {\n for (const ctx of this._listeners) {\n if (ctx.listener === listener && ctx.scope === scope) {\n return true;\n }\n }\n return false;\n }\n\n /** Clear all Listeners from this BeEvent. */\n public clear(): void { this._listeners.length = 0; }\n}\n\n/** Specialization of BeEvent for events that take a single strongly typed argument, primarily used for UI events.\n * @public\n */\nexport class BeUiEvent<TEventArgs> extends BeEvent<(args: TEventArgs) => void> {\n /** Raises event with single strongly typed argument. */\n public emit(args: TEventArgs): void { this.raiseEvent(args); }\n}\n\ninterface UnorderedEventContext {\n listener: Listener | undefined;\n scope: any;\n once: boolean;\n}\n\n/**\n * Manages a set of *listeners* for a particular event and notifies them when the event is raised.\n * Unlike [[BeEvent]], this class uses a `Set` internally to support safe concurrent modification\n * during emit. When a listener is removed during emit, it is marked for deferred removal instead\n * of mutating the set immediately.\n *\n * Listeners are managed exclusively through the disposal closure returned by [[addListener]] and\n * [[addOnce]]. There is no `removeListener` or `has` method — callers must capture the returned\n * closure to unsubscribe.\n * @beta\n */\nexport class BeUnorderedEvent<T extends Listener> {\n private _listeners: Set<UnorderedEventContext> = new Set();\n private _emitDepth: number = 0;\n private _hasTombstones: boolean = false;\n\n /** The number of listeners currently subscribed to the event.\n * @note During `raiseEvent()`, this may include listeners that have been removed or are one-shot\n * but are awaiting deferred cleanup. The count is accurate outside of `raiseEvent()`.\n */\n public get numberOfListeners() { return this._listeners.size; }\n\n /**\n * Registers a Listener to be executed whenever this event is raised.\n * @param listener The function to be executed when the event is raised.\n * @param scope An optional object scope to serve as the 'this' pointer when listener is invoked.\n * @returns A function that will remove this event listener in O(1).\n */\n public addListener(listener: T, scope?: any): () => void {\n const ctx: UnorderedEventContext = { listener, scope, once: false };\n this._listeners.add(ctx);\n return () => this._removeCtx(ctx);\n }\n\n /**\n * Registers a callback function to be executed *only once* when the event is raised.\n * @param listener The function to be executed once when the event is raised.\n * @param scope An optional object scope to serve as the `this` pointer in which the listener function will execute.\n * @returns A function that will remove this event listener in O(1).\n */\n public addOnce(listener: T, scope?: any): () => void {\n const ctx: UnorderedEventContext = { listener, scope, once: true };\n this._listeners.add(ctx);\n return () => this._removeCtx(ctx);\n }\n\n /** Remove a specific context entry, deferring during emit. */\n private _removeCtx(ctx: UnorderedEventContext): void {\n if (this._emitDepth > 0) {\n ctx.listener = undefined; // tombstone for deferred cleanup\n this._hasTombstones = true;\n } else {\n this._listeners.delete(ctx);\n }\n }\n\n /**\n * Raises the event by calling each registered listener with the supplied arguments.\n * @param args This method takes any number of parameters and passes them through to the listeners.\n */\n public raiseEvent(...args: Parameters<T>) {\n this._emitDepth++;\n\n for (const ctx of this._listeners) {\n if (!ctx.listener) {\n continue;\n }\n try {\n ctx.listener.apply(ctx.scope, args);\n } catch (e) {\n UnexpectedErrors.handle(e);\n }\n if (ctx.listener && ctx.once) {\n ctx.listener = undefined;\n this._hasTombstones = true;\n }\n }\n\n this._emitDepth--;\n\n // Only clean up tombstoned entries when we're back at the outermost emit\n if (this._hasTombstones && this._emitDepth === 0) {\n this._hasTombstones = false;\n for (const ctx of this._listeners) {\n if (ctx.listener === undefined)\n this._listeners.delete(ctx);\n }\n }\n }\n\n /** Clear all listeners from this BeUnorderedEvent.\n * @note If called during `raiseEvent`, remaining listeners in the current iteration are skipped\n * immediately rather than being tombstoned.\n */\n public clear(): void { this._listeners.clear(); }\n}\n\n/** Specialization of BeUnorderedEvent for events that take a single strongly typed argument, primarily used for UI events.\n * @beta\n */\nexport class BeUnorderedUiEvent<TEventArgs> extends BeUnorderedEvent<(args: TEventArgs) => void> {\n /** Raises event with single strongly typed argument. */\n public emit(args: TEventArgs): void { this.raiseEvent(args); }\n}\n\n/**\n * A list of BeEvent objects, accessible by an event name.\n * This class may be used instead of explicitly declaring each BeEvent as a member of a containing class.\n * @public\n */\nexport class BeEventList<T extends Listener> {\n private _events: { [name: string]: BeEvent<T> | undefined } = {};\n\n /**\n * Gets the event associated with the specified name, creating the event if it does not already exist.\n * @param name The name of the event.\n */\n public get(name: string): BeEvent<T> {\n let event = this._events[name];\n if (event)\n return event;\n\n event = new BeEvent();\n this._events[name] = event;\n return event;\n }\n\n /**\n * Removes the event associated with a name.\n * @param name The name of the event.\n */\n public remove(name: string): void {\n this._events[name] = undefined;\n }\n}\n\n/**\n * Retrieves the type of the callback function for an event type like [[BeEvent]].\n * For example:\n * ```ts\n * const event = new BeEvent<(x: number, y: string) => void>();\n * const callback: ListenerType<typeof event> = (x, y) => {\n * console.log(`${x}, ${y}`);\n * };\n * ```\n *\n * @public\n */\nexport type ListenerType<TEvent extends {\n addListener(listener: Listener): () => void;\n}> =\n TEvent extends {\n addListener(listener: infer TListener): () => void;\n } ? TListener : never;\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module Utils
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Wrapper function designed to be used for callbacks called by setInterval or setTimeout in order to propagate any
|
|
6
|
+
* exceptions thrown in the callback to the main promise chain. It does this by creating a new promise for the callback
|
|
7
|
+
* invocation and adding it to the timerPromises set. The main promise chain can then await
|
|
8
|
+
* Promise.all(timerPromises) to catch any exceptions thrown in any of the callbacks. Note that if the callback
|
|
9
|
+
* completes successfully, the promise is resolved and removed from the set. If it throws an exception, the promise is
|
|
10
|
+
* rejected but not removed from the set, so that the main promise chain can detect that an error occurred and handle
|
|
11
|
+
* it appropriately.
|
|
12
|
+
* @param timerPromises A set of promises representing the currently active timer callbacks.
|
|
13
|
+
* @param callback The async callback to be executed within the timer.
|
|
14
|
+
* @beta
|
|
15
|
+
*/
|
|
16
|
+
export declare function wrapTimerCallback(timerPromises: Set<Promise<void>>, callback: () => Promise<void>): Promise<void>;
|
|
17
|
+
//# sourceMappingURL=UtilityFunctions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UtilityFunctions.d.ts","sourceRoot":"","sources":["../../src/UtilityFunctions.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH;;;;;;;;;;;GAWG;AACH,wBAAsB,iBAAiB,CAAC,aAAa,EAAE,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,iBAgCvG"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
/** @packageDocumentation
|
|
6
|
+
* @module Utils
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Wrapper function designed to be used for callbacks called by setInterval or setTimeout in order to propagate any
|
|
10
|
+
* exceptions thrown in the callback to the main promise chain. It does this by creating a new promise for the callback
|
|
11
|
+
* invocation and adding it to the timerPromises set. The main promise chain can then await
|
|
12
|
+
* Promise.all(timerPromises) to catch any exceptions thrown in any of the callbacks. Note that if the callback
|
|
13
|
+
* completes successfully, the promise is resolved and removed from the set. If it throws an exception, the promise is
|
|
14
|
+
* rejected but not removed from the set, so that the main promise chain can detect that an error occurred and handle
|
|
15
|
+
* it appropriately.
|
|
16
|
+
* @param timerPromises A set of promises representing the currently active timer callbacks.
|
|
17
|
+
* @param callback The async callback to be executed within the timer.
|
|
18
|
+
* @beta
|
|
19
|
+
*/
|
|
20
|
+
export async function wrapTimerCallback(timerPromises, callback) {
|
|
21
|
+
let resolvePromise;
|
|
22
|
+
let rejectPromise;
|
|
23
|
+
// The callback of the Promise constructor does not have access to the promise itself, so all we do there is
|
|
24
|
+
// capture the resolve and reject functions for use in the async callback that would have otherwise been
|
|
25
|
+
// placed in the setInterval or setTimeout callback.
|
|
26
|
+
const timerPromise = new Promise((resolve, reject) => {
|
|
27
|
+
resolvePromise = resolve;
|
|
28
|
+
rejectPromise = reject;
|
|
29
|
+
});
|
|
30
|
+
// Note: when we get here, resolvePromise and rejectPromise will always be defined, but there is no way to
|
|
31
|
+
// convince TS of that fact without extra unnecessary checks, so we use ?. when accessing them.
|
|
32
|
+
// Prevent unhandled rejection warnings. The rejection is still observable
|
|
33
|
+
// when the consumer awaits Promise.all(promises).
|
|
34
|
+
timerPromise.catch(() => { });
|
|
35
|
+
timerPromises.add(timerPromise);
|
|
36
|
+
const cleanupAndResolve = () => {
|
|
37
|
+
resolvePromise?.();
|
|
38
|
+
// No need to keep track of this promise anymore since it's resolved.
|
|
39
|
+
timerPromises.delete(timerPromise);
|
|
40
|
+
};
|
|
41
|
+
try {
|
|
42
|
+
await callback();
|
|
43
|
+
cleanupAndResolve();
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
rejectPromise?.(err);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=UtilityFunctions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UtilityFunctions.js","sourceRoot":"","sources":["../../src/UtilityFunctions.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,aAAiC,EAAE,QAA6B;IACtG,IAAI,cAAwC,CAAC;IAC7C,IAAI,aAAmD,CAAC;IAExD,4GAA4G;IAC5G,wGAAwG;IACxG,oDAAoD;IACpD,MAAM,YAAY,GAAG,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACzD,cAAc,GAAG,OAAO,CAAC;QACzB,aAAa,GAAG,MAAM,CAAC;IACzB,CAAC,CAAC,CAAC;IACH,0GAA0G;IAC1G,+FAA+F;IAE/F,0EAA0E;IAC1E,kDAAkD;IAClD,YAAY,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IAE7B,aAAa,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IAEhC,MAAM,iBAAiB,GAAG,GAAG,EAAE;QAC7B,cAAc,EAAE,EAAE,CAAC;QACnB,qEAAqE;QACrE,aAAa,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;IACrC,CAAC,CAAC;IAEF,IAAI,CAAC;QACH,MAAM,QAAQ,EAAE,CAAC;QACjB,iBAAiB,EAAE,CAAC;IACtB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,aAAa,EAAE,CAAC,GAAG,CAAC,CAAC;IACvB,CAAC;AACH,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Utils\n */\n\n/**\n * Wrapper function designed to be used for callbacks called by setInterval or setTimeout in order to propagate any\n * exceptions thrown in the callback to the main promise chain. It does this by creating a new promise for the callback\n * invocation and adding it to the timerPromises set. The main promise chain can then await\n * Promise.all(timerPromises) to catch any exceptions thrown in any of the callbacks. Note that if the callback\n * completes successfully, the promise is resolved and removed from the set. If it throws an exception, the promise is\n * rejected but not removed from the set, so that the main promise chain can detect that an error occurred and handle\n * it appropriately.\n * @param timerPromises A set of promises representing the currently active timer callbacks.\n * @param callback The async callback to be executed within the timer.\n * @beta\n */\nexport async function wrapTimerCallback(timerPromises: Set<Promise<void>>, callback: () => Promise<void>) {\n let resolvePromise: (() => void) | undefined;\n let rejectPromise: ((reason?: any) => void) | undefined;\n\n // The callback of the Promise constructor does not have access to the promise itself, so all we do there is\n // capture the resolve and reject functions for use in the async callback that would have otherwise been\n // placed in the setInterval or setTimeout callback.\n const timerPromise = new Promise<void>((resolve, reject) => {\n resolvePromise = resolve;\n rejectPromise = reject;\n });\n // Note: when we get here, resolvePromise and rejectPromise will always be defined, but there is no way to\n // convince TS of that fact without extra unnecessary checks, so we use ?. when accessing them.\n\n // Prevent unhandled rejection warnings. The rejection is still observable\n // when the consumer awaits Promise.all(promises).\n timerPromise.catch(() => {});\n\n timerPromises.add(timerPromise);\n\n const cleanupAndResolve = () => {\n resolvePromise?.();\n // No need to keep track of this promise anymore since it's resolved.\n timerPromises.delete(timerPromise);\n };\n\n try {\n await callback();\n cleanupAndResolve();\n } catch (err) {\n rejectPromise?.(err);\n }\n}\n"]}
|
|
@@ -32,6 +32,7 @@ export * from "./Tracing";
|
|
|
32
32
|
export * from "./TupleKeyedMap";
|
|
33
33
|
export * from "./TypedArrayBuilder";
|
|
34
34
|
export * from "./UnexpectedErrors";
|
|
35
|
+
export * from "./UtilityFunctions";
|
|
35
36
|
export * from "./UtilityTypes";
|
|
36
37
|
export * from "./YieldManager";
|
|
37
38
|
export * from "./internal/cross-package";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-bentley.d.ts","sourceRoot":"","sources":["../../src/core-bentley.ts"],"names":[],"mappings":"AAIA,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,MAAM,CAAC;AACrB,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,g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CAAC;AAG/B,cAAc,0BAA0B,CAAC;AAEzC;;GAEG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG"}
|
package/lib/esm/core-bentley.js
CHANGED
|
@@ -36,6 +36,7 @@ export * from "./Tracing";
|
|
|
36
36
|
export * from "./TupleKeyedMap";
|
|
37
37
|
export * from "./TypedArrayBuilder";
|
|
38
38
|
export * from "./UnexpectedErrors";
|
|
39
|
+
export * from "./UtilityFunctions";
|
|
39
40
|
export * from "./UtilityTypes";
|
|
40
41
|
export * from "./YieldManager";
|
|
41
42
|
// Temporarily (until 5.0) export top-level internal APIs to avoid breaking callers.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-bentley.js","sourceRoot":"","sources":["../../src/core-bentley.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,MAAM,CAAC;AACrB,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAE/B,oFAAoF;AACpF,cAAc,0BAA0B,CAAC;AAEzC;;GAEG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nexport * from \"./AccessToken\";\nexport * from \"./Assert\";\nexport * from \"./BeEvent\";\nexport * from \"./BentleyError\";\nexport * from \"./BentleyLoggerCategory\";\nexport * from \"./StatusCategory\";\nexport * from \"./BeSQLite\";\nexport * from \"./ByteStream\";\nexport * from \"./ClassUtils\";\nexport * from \"./Compare\";\nexport * from \"./CompressedId64Set\";\nexport * from \"./Dictionary\";\nexport * from \"./Disposable\";\nexport * from \"./Expect\";\nexport * from \"./Id\";\nexport * from \"./IndexMap\";\nexport * from \"./JsonSchema\";\nexport * from \"./JsonUtils\";\nexport * from \"./Logger\";\nexport * from \"./LRUMap\";\nexport * from \"./ObservableSet\";\nexport * from \"./OneAtATimeAction\";\nexport * from \"./OrderedId64Iterable\";\nexport * from \"./OrderedSet\";\nexport * from \"./partitionArray\";\nexport * from \"./PriorityQueue\";\nexport * from \"./ProcessDetector\";\nexport * from \"./SortedArray\";\nexport * from \"./StringUtils\";\nexport * from \"./Time\";\nexport * from \"./Tracing\";\nexport * from \"./TupleKeyedMap\";\nexport * from \"./TypedArrayBuilder\";\nexport * from \"./UnexpectedErrors\";\nexport * from \"./UtilityTypes\";\nexport * from \"./YieldManager\";\n\n// Temporarily (until 5.0) export top-level internal APIs to avoid breaking callers.\nexport * from \"./internal/cross-package\";\n\n/** @docs-package-description\n * The core-bentley package contains classes to solve problems that are common for both client and server use cases.\n */\n/**\n * @docs-group-description BeSQLite\n * Classes for working with SQLite databases. SQLite underlies IModelDb and ECDb - see [Executing ECSQL]($docs/learning/ECSQL.md)\n */\n/**\n * @docs-group-description Errors\n * Classes for working with errors.\n */\n/**\n * @docs-group-description Events\n * Classes for raising and handling events.\n */\n/**\n * @docs-group-description Ids\n * Classes for working with unique identifiers.\n */\n/**\n * @docs-group-description Logging\n * Classes for configuring and logging diagnostic messages - see [Learning about Logging]($docs/learning/common/Logging.md)\n */\n/**\n * @docs-group-description Collections\n * Specialized, customizable collection classes like priority queues.\n */\n/**\n * @docs-group-description Json\n * utilities for dealing with Json strings and files.\n */\n/**\n * @docs-group-description Utils\n * Miscellaneous utility classes.\n */\n/**\n * @docs-group-description ProcessDetector\n * Functions for determining the type of the current JavaScript process.\n */\n"]}
|
|
1
|
+
{"version":3,"file":"core-bentley.js","sourceRoot":"","sources":["../../src/core-bentley.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,MAAM,CAAC;AACrB,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAE/B,oFAAoF;AACpF,cAAc,0BAA0B,CAAC;AAEzC;;GAEG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nexport * from \"./AccessToken\";\nexport * from \"./Assert\";\nexport * from \"./BeEvent\";\nexport * from \"./BentleyError\";\nexport * from \"./BentleyLoggerCategory\";\nexport * from \"./StatusCategory\";\nexport * from \"./BeSQLite\";\nexport * from \"./ByteStream\";\nexport * from \"./ClassUtils\";\nexport * from \"./Compare\";\nexport * from \"./CompressedId64Set\";\nexport * from \"./Dictionary\";\nexport * from \"./Disposable\";\nexport * from \"./Expect\";\nexport * from \"./Id\";\nexport * from \"./IndexMap\";\nexport * from \"./JsonSchema\";\nexport * from \"./JsonUtils\";\nexport * from \"./Logger\";\nexport * from \"./LRUMap\";\nexport * from \"./ObservableSet\";\nexport * from \"./OneAtATimeAction\";\nexport * from \"./OrderedId64Iterable\";\nexport * from \"./OrderedSet\";\nexport * from \"./partitionArray\";\nexport * from \"./PriorityQueue\";\nexport * from \"./ProcessDetector\";\nexport * from \"./SortedArray\";\nexport * from \"./StringUtils\";\nexport * from \"./Time\";\nexport * from \"./Tracing\";\nexport * from \"./TupleKeyedMap\";\nexport * from \"./TypedArrayBuilder\";\nexport * from \"./UnexpectedErrors\";\nexport * from \"./UtilityFunctions\";\nexport * from \"./UtilityTypes\";\nexport * from \"./YieldManager\";\n\n// Temporarily (until 5.0) export top-level internal APIs to avoid breaking callers.\nexport * from \"./internal/cross-package\";\n\n/** @docs-package-description\n * The core-bentley package contains classes to solve problems that are common for both client and server use cases.\n */\n/**\n * @docs-group-description BeSQLite\n * Classes for working with SQLite databases. SQLite underlies IModelDb and ECDb - see [Executing ECSQL]($docs/learning/ECSQL.md)\n */\n/**\n * @docs-group-description Errors\n * Classes for working with errors.\n */\n/**\n * @docs-group-description Events\n * Classes for raising and handling events.\n */\n/**\n * @docs-group-description Ids\n * Classes for working with unique identifiers.\n */\n/**\n * @docs-group-description Logging\n * Classes for configuring and logging diagnostic messages - see [Learning about Logging]($docs/learning/common/Logging.md)\n */\n/**\n * @docs-group-description Collections\n * Specialized, customizable collection classes like priority queues.\n */\n/**\n * @docs-group-description Json\n * utilities for dealing with Json strings and files.\n */\n/**\n * @docs-group-description Utils\n * Miscellaneous utility classes.\n */\n/**\n * @docs-group-description ProcessDetector\n * Functions for determining the type of the current JavaScript process.\n */\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/core-bentley",
|
|
3
|
-
"version": "5.9.0-dev.
|
|
3
|
+
"version": "5.9.0-dev.10",
|
|
4
4
|
"description": "Bentley JavaScript core components",
|
|
5
5
|
"main": "lib/cjs/core-bentley.js",
|
|
6
6
|
"module": "lib/esm/core-bentley.js",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"rimraf": "^6.0.1",
|
|
31
31
|
"typescript": "~5.6.2",
|
|
32
32
|
"vitest": "^3.0.6",
|
|
33
|
-
"@itwin/build-tools": "5.9.0-dev.
|
|
33
|
+
"@itwin/build-tools": "5.9.0-dev.10"
|
|
34
34
|
},
|
|
35
35
|
"nyc": {
|
|
36
36
|
"extends": "./node_modules/@itwin/build-tools/.nycrc"
|