@blac/core 2.0.0-rc-11 → 2.0.0-rc-13
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/dist/index.cjs.js +2 -2
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +254 -0
- package/dist/index.es.js +700 -296
- package/dist/index.es.js.map +1 -1
- package/package.json +1 -1
- package/src/Blac.ts +48 -2
- package/src/BlacObserver.ts +3 -0
- package/src/Bloc.ts +44 -1
- package/src/BlocBase.ts +107 -4
- package/src/__tests__/plugins.test.ts +454 -0
- package/src/index.ts +3 -0
- package/src/plugins/BlocPluginRegistry.ts +220 -0
- package/src/plugins/SystemPluginRegistry.ts +192 -0
- package/src/plugins/index.ts +8 -0
- package/src/plugins/types.ts +100 -0
package/dist/index.es.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
var
|
|
2
|
-
var O = (c, e, t) => e in c ?
|
|
1
|
+
var R = Object.defineProperty;
|
|
2
|
+
var O = (c, e, t) => e in c ? R(c, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : c[e] = t;
|
|
3
3
|
var i = (c, e, t) => O(c, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
-
class
|
|
4
|
+
class H {
|
|
5
5
|
/**
|
|
6
6
|
* Creates a new BlacObservable instance
|
|
7
7
|
* @param bloc - The Bloc instance to observe
|
|
@@ -33,23 +33,23 @@ class V {
|
|
|
33
33
|
*/
|
|
34
34
|
subscribe(e) {
|
|
35
35
|
const t = this.bloc._disposalState;
|
|
36
|
-
return t ===
|
|
36
|
+
return t === y.DISPOSED || t === y.DISPOSING ? (u.log(
|
|
37
37
|
"BlacObservable.subscribe: Cannot subscribe to disposed/disposing bloc.",
|
|
38
38
|
this.bloc,
|
|
39
39
|
e
|
|
40
40
|
), () => {
|
|
41
|
-
}) : (
|
|
41
|
+
}) : (u.log(
|
|
42
42
|
"BlacObservable.subscribe: Subscribing observer.",
|
|
43
43
|
this.bloc,
|
|
44
44
|
e
|
|
45
|
-
), this._observers.add(e), t ===
|
|
45
|
+
), this._observers.add(e), t === y.DISPOSAL_REQUESTED && (u.log(
|
|
46
46
|
"BlacObservable.subscribe: Cancelling disposal due to new subscription.",
|
|
47
47
|
this.bloc
|
|
48
48
|
), this.bloc._atomicStateTransition(
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
y.DISPOSAL_REQUESTED,
|
|
50
|
+
y.ACTIVE
|
|
51
51
|
)), () => {
|
|
52
|
-
|
|
52
|
+
u.log(
|
|
53
53
|
"BlacObservable.subscribe: Unsubscribing observer.",
|
|
54
54
|
this.bloc,
|
|
55
55
|
e
|
|
@@ -61,7 +61,7 @@ class V {
|
|
|
61
61
|
* @param observer - The observer to unsubscribe
|
|
62
62
|
*/
|
|
63
63
|
unsubscribe(e) {
|
|
64
|
-
this._observers.delete(e), this.size === 0 && (
|
|
64
|
+
this._observers.delete(e), this.size === 0 && (u.log("BlacObservable.unsubscribe: No observers left.", this.bloc), this.bloc._consumers.size === 0 && !this.bloc._keepAlive && this.bloc._disposalState === y.ACTIVE && (u.log(
|
|
65
65
|
`[${this.bloc._name}:${this.bloc._id}] No observers or consumers left. Scheduling disposal.`
|
|
66
66
|
), this.bloc._scheduleDisposal()));
|
|
67
67
|
}
|
|
@@ -72,29 +72,29 @@ class V {
|
|
|
72
72
|
* @param action - Optional action that triggered the state change
|
|
73
73
|
*/
|
|
74
74
|
notify(e, t, s) {
|
|
75
|
-
this._observers.forEach((
|
|
76
|
-
let
|
|
77
|
-
if (
|
|
78
|
-
const o =
|
|
75
|
+
this._observers.forEach((r) => {
|
|
76
|
+
let n = !1;
|
|
77
|
+
if (r.dependencyArray) {
|
|
78
|
+
const o = r.lastState, a = r.dependencyArray(
|
|
79
79
|
e,
|
|
80
80
|
t,
|
|
81
81
|
this.bloc
|
|
82
82
|
);
|
|
83
83
|
if (!o)
|
|
84
|
-
|
|
84
|
+
n = !0;
|
|
85
85
|
else if (o.length !== a.length)
|
|
86
|
-
|
|
86
|
+
n = !0;
|
|
87
87
|
else
|
|
88
|
-
for (let
|
|
89
|
-
if (!Object.is(o[
|
|
90
|
-
|
|
88
|
+
for (let l = 0; l < a.length; l++)
|
|
89
|
+
if (!Object.is(o[l], a[l])) {
|
|
90
|
+
n = !0;
|
|
91
91
|
break;
|
|
92
92
|
}
|
|
93
|
-
|
|
93
|
+
r.lastState = a;
|
|
94
94
|
} else
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
});
|
|
95
|
+
n = !0;
|
|
96
|
+
n && r.fn(e, t, s);
|
|
97
|
+
}), u.instance.plugins.notifyStateChanged(this.bloc, t, e);
|
|
98
98
|
}
|
|
99
99
|
/**
|
|
100
100
|
* Clears the observer set
|
|
@@ -109,8 +109,161 @@ function $() {
|
|
|
109
109
|
return (c === "x" ? e : e & 3 | 8).toString(16);
|
|
110
110
|
});
|
|
111
111
|
}
|
|
112
|
-
|
|
113
|
-
|
|
112
|
+
class V {
|
|
113
|
+
constructor() {
|
|
114
|
+
i(this, "plugins", /* @__PURE__ */ new Map());
|
|
115
|
+
i(this, "executionOrder", []);
|
|
116
|
+
i(this, "attached", !1);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Add a bloc plugin
|
|
120
|
+
*/
|
|
121
|
+
add(e) {
|
|
122
|
+
if (this.plugins.has(e.name))
|
|
123
|
+
throw new Error(`Plugin '${e.name}' is already registered`);
|
|
124
|
+
e.capabilities && this.validateCapabilities(e), this.plugins.set(e.name, e), this.executionOrder.push(e.name);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Remove a bloc plugin
|
|
128
|
+
*/
|
|
129
|
+
remove(e) {
|
|
130
|
+
const t = this.plugins.get(e);
|
|
131
|
+
if (!t) return !1;
|
|
132
|
+
if (this.attached && t.onDetach)
|
|
133
|
+
try {
|
|
134
|
+
t.onDetach();
|
|
135
|
+
} catch (s) {
|
|
136
|
+
console.error(`Plugin '${e}' error in onDetach:`, s);
|
|
137
|
+
}
|
|
138
|
+
return this.plugins.delete(e), this.executionOrder = this.executionOrder.filter((s) => s !== e), !0;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Get a plugin by name
|
|
142
|
+
*/
|
|
143
|
+
get(e) {
|
|
144
|
+
return this.plugins.get(e);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Get all plugins in execution order
|
|
148
|
+
*/
|
|
149
|
+
getAll() {
|
|
150
|
+
return this.executionOrder.map((e) => this.plugins.get(e));
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Clear all plugins
|
|
154
|
+
*/
|
|
155
|
+
clear() {
|
|
156
|
+
if (this.attached) {
|
|
157
|
+
for (const e of this.getAll())
|
|
158
|
+
if (e.onDetach)
|
|
159
|
+
try {
|
|
160
|
+
e.onDetach();
|
|
161
|
+
} catch (t) {
|
|
162
|
+
console.error(`Plugin '${e.name}' error in onDetach:`, t);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
this.plugins.clear(), this.executionOrder = [], this.attached = !1;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Attach all plugins to a bloc
|
|
169
|
+
*/
|
|
170
|
+
attach(e) {
|
|
171
|
+
if (this.attached)
|
|
172
|
+
throw new Error("Plugins are already attached");
|
|
173
|
+
for (const t of this.getAll())
|
|
174
|
+
if (t.onAttach)
|
|
175
|
+
try {
|
|
176
|
+
t.onAttach(e);
|
|
177
|
+
} catch (s) {
|
|
178
|
+
console.error(`Plugin '${t.name}' error in onAttach:`, s), this.remove(t.name);
|
|
179
|
+
}
|
|
180
|
+
this.attached = !0;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Transform state through all plugins
|
|
184
|
+
*/
|
|
185
|
+
transformState(e, t) {
|
|
186
|
+
let s = t;
|
|
187
|
+
for (const r of this.getAll())
|
|
188
|
+
if (r.transformState && this.canTransformState(r))
|
|
189
|
+
try {
|
|
190
|
+
s = r.transformState(e, s);
|
|
191
|
+
} catch (n) {
|
|
192
|
+
console.error(`Plugin '${r.name}' error in transformState:`, n);
|
|
193
|
+
}
|
|
194
|
+
return s;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Transform event through all plugins
|
|
198
|
+
*/
|
|
199
|
+
transformEvent(e) {
|
|
200
|
+
let t = e;
|
|
201
|
+
for (const s of this.getAll()) {
|
|
202
|
+
if (t === null) break;
|
|
203
|
+
if (s.transformEvent && this.canInterceptEvents(s))
|
|
204
|
+
try {
|
|
205
|
+
t = s.transformEvent(t);
|
|
206
|
+
} catch (r) {
|
|
207
|
+
console.error(`Plugin '${s.name}' error in transformEvent:`, r);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return t;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Notify plugins of state change
|
|
214
|
+
*/
|
|
215
|
+
notifyStateChange(e, t) {
|
|
216
|
+
for (const s of this.getAll())
|
|
217
|
+
if (s.onStateChange && this.canReadState(s))
|
|
218
|
+
try {
|
|
219
|
+
s.onStateChange(e, t);
|
|
220
|
+
} catch (r) {
|
|
221
|
+
console.error(`Plugin '${s.name}' error in onStateChange:`, r);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Notify plugins of event
|
|
226
|
+
*/
|
|
227
|
+
notifyEvent(e) {
|
|
228
|
+
for (const t of this.getAll())
|
|
229
|
+
if (t.onEvent && this.canReadState(t))
|
|
230
|
+
try {
|
|
231
|
+
t.onEvent(e);
|
|
232
|
+
} catch (s) {
|
|
233
|
+
console.error(`Plugin '${t.name}' error in onEvent:`, s);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Notify plugins of error
|
|
238
|
+
*/
|
|
239
|
+
notifyError(e, t) {
|
|
240
|
+
for (const s of this.getAll())
|
|
241
|
+
if (s.onError)
|
|
242
|
+
try {
|
|
243
|
+
s.onError(e, t);
|
|
244
|
+
} catch (r) {
|
|
245
|
+
console.error(`Plugin '${s.name}' error in onError:`, r);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
validateCapabilities(e) {
|
|
249
|
+
const t = e.capabilities;
|
|
250
|
+
if (t.transformState && !t.readState)
|
|
251
|
+
throw new Error(`Plugin '${e.name}': transformState requires readState capability`);
|
|
252
|
+
if (t.interceptEvents && !t.readState)
|
|
253
|
+
throw new Error(`Plugin '${e.name}': interceptEvents requires readState capability`);
|
|
254
|
+
}
|
|
255
|
+
canReadState(e) {
|
|
256
|
+
return !e.capabilities || e.capabilities.readState !== !1;
|
|
257
|
+
}
|
|
258
|
+
canTransformState(e) {
|
|
259
|
+
return !e.capabilities || e.capabilities.transformState === !0;
|
|
260
|
+
}
|
|
261
|
+
canInterceptEvents(e) {
|
|
262
|
+
return !e.capabilities || e.capabilities.interceptEvents === !0;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
var y = /* @__PURE__ */ ((c) => (c.ACTIVE = "active", c.DISPOSAL_REQUESTED = "disposal_requested", c.DISPOSING = "disposing", c.DISPOSED = "disposed", c))(y || {});
|
|
266
|
+
class k {
|
|
114
267
|
/**
|
|
115
268
|
* Creates a new BlocBase instance with the given initial state.
|
|
116
269
|
* Sets up the observer, registers with the Blac manager, and initializes addons.
|
|
@@ -194,6 +347,10 @@ class x {
|
|
|
194
347
|
* Map of consumer IDs to their WeakRef objects for proper cleanup
|
|
195
348
|
*/
|
|
196
349
|
i(this, "_consumerRefs", /* @__PURE__ */ new Map());
|
|
350
|
+
/**
|
|
351
|
+
* Plugin registry for this bloc instance
|
|
352
|
+
*/
|
|
353
|
+
i(this, "_plugins");
|
|
197
354
|
/**
|
|
198
355
|
* @internal
|
|
199
356
|
* Validates that all consumer references are still alive
|
|
@@ -277,13 +434,28 @@ class x {
|
|
|
277
434
|
* @param action Optional metadata about what caused the state change
|
|
278
435
|
*/
|
|
279
436
|
i(this, "_pushState", (e, t, s) => {
|
|
280
|
-
if (e
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
437
|
+
if (e === void 0 || s !== void 0 && typeof s != "object" && typeof s != "function")
|
|
438
|
+
return;
|
|
439
|
+
let r = e;
|
|
440
|
+
try {
|
|
441
|
+
r = this._plugins.transformState(t, e);
|
|
442
|
+
} catch (n) {
|
|
443
|
+
this._plugins.notifyError(n, {
|
|
444
|
+
phase: "state-change",
|
|
445
|
+
operation: "transformState"
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
if (this._batchingEnabled) {
|
|
449
|
+
this._pendingUpdates.push({ newState: r, oldState: t, action: s }), this._oldState = t, this._state = r;
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
this._oldState = t, this._state = r;
|
|
453
|
+
try {
|
|
454
|
+
this._plugins.notifyStateChange(t, r);
|
|
455
|
+
} catch (n) {
|
|
456
|
+
console.error("Error notifying bloc plugins of state change:", n);
|
|
286
457
|
}
|
|
458
|
+
this._observer.notify(r, t, s), this.lastUpdate = Date.now();
|
|
287
459
|
});
|
|
288
460
|
/**
|
|
289
461
|
* Enables batching for multiple state updates
|
|
@@ -308,9 +480,11 @@ class x {
|
|
|
308
480
|
this._batchingEnabled = !1, this._batchingLock = !1, this._pendingUpdates = [];
|
|
309
481
|
}
|
|
310
482
|
});
|
|
311
|
-
this._state = e, this._observer = new
|
|
483
|
+
this._state = e, this._observer = new H(this), this._id = this.constructor.name;
|
|
312
484
|
const t = this.constructor;
|
|
313
|
-
this._keepAlive = typeof t.keepAlive == "boolean" ? t.keepAlive : !1, this._isolated = typeof t.isolated == "boolean" ? t.isolated : !1
|
|
485
|
+
if (this._keepAlive = typeof t.keepAlive == "boolean" ? t.keepAlive : !1, this._isolated = typeof t.isolated == "boolean" ? t.isolated : !1, this._plugins = new V(), t.plugins && Array.isArray(t.plugins))
|
|
486
|
+
for (const s of t.plugins)
|
|
487
|
+
this.addPlugin(s);
|
|
314
488
|
}
|
|
315
489
|
get isIsolated() {
|
|
316
490
|
return this._isolated;
|
|
@@ -348,10 +522,10 @@ class x {
|
|
|
348
522
|
* @returns Result indicating success/failure and state information
|
|
349
523
|
*/
|
|
350
524
|
_atomicStateTransition(e, t) {
|
|
351
|
-
var s,
|
|
525
|
+
var s, r, n, o;
|
|
352
526
|
if (this._disposalState === e) {
|
|
353
527
|
const a = this._disposalState;
|
|
354
|
-
return this._disposalState = t, (s = globalThis.Blac) != null && s.enableLog && ((
|
|
528
|
+
return this._disposalState = t, (s = globalThis.Blac) != null && s.enableLog && ((r = globalThis.Blac) == null || r.log(
|
|
355
529
|
`[${this._name}:${this._id}] State transition: ${a} -> ${t} (SUCCESS)`
|
|
356
530
|
)), {
|
|
357
531
|
success: !0,
|
|
@@ -359,7 +533,7 @@ class x {
|
|
|
359
533
|
previousState: a
|
|
360
534
|
};
|
|
361
535
|
}
|
|
362
|
-
return (
|
|
536
|
+
return (n = globalThis.Blac) != null && n.enableLog && ((o = globalThis.Blac) == null || o.log(
|
|
363
537
|
`[${this._name}:${this._id}] State transition failed: expected ${e}, current ${this._disposalState}`
|
|
364
538
|
)), {
|
|
365
539
|
success: !1,
|
|
@@ -430,42 +604,224 @@ class x {
|
|
|
430
604
|
);
|
|
431
605
|
});
|
|
432
606
|
}
|
|
607
|
+
/**
|
|
608
|
+
* Notify observers of a state change
|
|
609
|
+
* @internal Used by plugins for state hydration
|
|
610
|
+
* @param newState The new state
|
|
611
|
+
* @param oldState The old state
|
|
612
|
+
*/
|
|
613
|
+
_notifyObservers(e, t) {
|
|
614
|
+
this._observer.notify(e, t);
|
|
615
|
+
}
|
|
616
|
+
/**
|
|
617
|
+
* Add a plugin to this bloc instance
|
|
618
|
+
*/
|
|
619
|
+
addPlugin(e) {
|
|
620
|
+
if (this._plugins.add(e), this._disposalState === "active")
|
|
621
|
+
try {
|
|
622
|
+
e.onAttach && e.onAttach(this);
|
|
623
|
+
} catch (t) {
|
|
624
|
+
throw console.error(`Failed to attach plugin '${e.name}':`, t), this._plugins.remove(e.name), t;
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
/**
|
|
628
|
+
* Remove a plugin from this bloc instance
|
|
629
|
+
*/
|
|
630
|
+
removePlugin(e) {
|
|
631
|
+
return this._plugins.remove(e);
|
|
632
|
+
}
|
|
633
|
+
/**
|
|
634
|
+
* Get a plugin by name
|
|
635
|
+
*/
|
|
636
|
+
getPlugin(e) {
|
|
637
|
+
return this._plugins.get(e);
|
|
638
|
+
}
|
|
639
|
+
/**
|
|
640
|
+
* Get all plugins
|
|
641
|
+
*/
|
|
642
|
+
getPlugins() {
|
|
643
|
+
return this._plugins.getAll();
|
|
644
|
+
}
|
|
645
|
+
/**
|
|
646
|
+
* @internal
|
|
647
|
+
* Activate plugins when bloc becomes active
|
|
648
|
+
*/
|
|
649
|
+
_activatePlugins() {
|
|
650
|
+
if (this._disposalState === "active")
|
|
651
|
+
try {
|
|
652
|
+
this._plugins.attach(this);
|
|
653
|
+
} catch (e) {
|
|
654
|
+
console.error(`Failed to activate plugins for ${this._name}:`, e);
|
|
655
|
+
}
|
|
656
|
+
}
|
|
433
657
|
}
|
|
434
658
|
/**
|
|
435
659
|
* When true, every consumer will receive its own unique instance of this Bloc.
|
|
436
660
|
* Use this when state should not be shared between components.
|
|
437
661
|
* @default false
|
|
438
662
|
*/
|
|
439
|
-
i(
|
|
663
|
+
i(k, "isolated", !1), /**
|
|
440
664
|
* When true, the Bloc instance persists even when there are no active consumers.
|
|
441
665
|
* Useful for maintaining state between component unmount/remount cycles.
|
|
442
666
|
* @default false
|
|
443
667
|
*/
|
|
444
|
-
i(
|
|
445
|
-
|
|
668
|
+
i(k, "keepAlive", !1);
|
|
669
|
+
class U {
|
|
670
|
+
constructor() {
|
|
671
|
+
i(this, "plugins", /* @__PURE__ */ new Map());
|
|
672
|
+
i(this, "metrics", /* @__PURE__ */ new Map());
|
|
673
|
+
i(this, "executionOrder", []);
|
|
674
|
+
}
|
|
675
|
+
/**
|
|
676
|
+
* Add a system plugin
|
|
677
|
+
*/
|
|
678
|
+
add(e) {
|
|
679
|
+
if (this.plugins.has(e.name))
|
|
680
|
+
throw new Error(`Plugin '${e.name}' is already registered`);
|
|
681
|
+
this.plugins.set(e.name, e), this.executionOrder.push(e.name), this.initializeMetrics(e.name);
|
|
682
|
+
}
|
|
683
|
+
/**
|
|
684
|
+
* Remove a system plugin
|
|
685
|
+
*/
|
|
686
|
+
remove(e) {
|
|
687
|
+
return this.plugins.get(e) ? (this.plugins.delete(e), this.metrics.delete(e), this.executionOrder = this.executionOrder.filter((s) => s !== e), !0) : !1;
|
|
688
|
+
}
|
|
689
|
+
/**
|
|
690
|
+
* Get a plugin by name
|
|
691
|
+
*/
|
|
692
|
+
get(e) {
|
|
693
|
+
return this.plugins.get(e);
|
|
694
|
+
}
|
|
695
|
+
/**
|
|
696
|
+
* Get all plugins in execution order
|
|
697
|
+
*/
|
|
698
|
+
getAll() {
|
|
699
|
+
return this.executionOrder.map((e) => this.plugins.get(e));
|
|
700
|
+
}
|
|
701
|
+
/**
|
|
702
|
+
* Clear all plugins
|
|
703
|
+
*/
|
|
704
|
+
clear() {
|
|
705
|
+
this.plugins.clear(), this.metrics.clear(), this.executionOrder = [];
|
|
706
|
+
}
|
|
707
|
+
/**
|
|
708
|
+
* Execute a hook on all plugins
|
|
709
|
+
*/
|
|
710
|
+
executeHook(e, t, s) {
|
|
711
|
+
for (const r of this.executionOrder) {
|
|
712
|
+
const n = this.plugins.get(r), o = n[e];
|
|
713
|
+
if (typeof o != "function") continue;
|
|
714
|
+
const a = performance.now();
|
|
715
|
+
try {
|
|
716
|
+
o.apply(n, t), this.recordSuccess(r, e, a);
|
|
717
|
+
} catch (l) {
|
|
718
|
+
this.recordError(r, e, l), s ? s(l, n) : console.error(`Plugin '${r}' error in hook '${e}':`, l);
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
/**
|
|
723
|
+
* Bootstrap all plugins
|
|
724
|
+
*/
|
|
725
|
+
bootstrap() {
|
|
726
|
+
this.executeHook("beforeBootstrap", []), this.executeHook("afterBootstrap", []);
|
|
727
|
+
}
|
|
728
|
+
/**
|
|
729
|
+
* Shutdown all plugins
|
|
730
|
+
*/
|
|
731
|
+
shutdown() {
|
|
732
|
+
this.executeHook("beforeShutdown", []), this.executeHook("afterShutdown", []);
|
|
733
|
+
}
|
|
734
|
+
/**
|
|
735
|
+
* Notify plugins of bloc creation
|
|
736
|
+
*/
|
|
737
|
+
notifyBlocCreated(e) {
|
|
738
|
+
this.executeHook("onBlocCreated", [e]);
|
|
739
|
+
}
|
|
740
|
+
/**
|
|
741
|
+
* Notify plugins of bloc disposal
|
|
742
|
+
*/
|
|
743
|
+
notifyBlocDisposed(e) {
|
|
744
|
+
this.executeHook("onBlocDisposed", [e]);
|
|
745
|
+
}
|
|
746
|
+
/**
|
|
747
|
+
* Notify plugins of state change
|
|
748
|
+
*/
|
|
749
|
+
notifyStateChanged(e, t, s) {
|
|
750
|
+
this.executeHook("onStateChanged", [e, t, s]);
|
|
751
|
+
}
|
|
752
|
+
/**
|
|
753
|
+
* Notify plugins of event addition
|
|
754
|
+
*/
|
|
755
|
+
notifyEventAdded(e, t) {
|
|
756
|
+
this.executeHook("onEventAdded", [e, t]);
|
|
757
|
+
}
|
|
758
|
+
/**
|
|
759
|
+
* Notify plugins of errors
|
|
760
|
+
*/
|
|
761
|
+
notifyError(e, t, s) {
|
|
762
|
+
this.executeHook("onError", [e, t, s], (r, n) => {
|
|
763
|
+
console.error(`Plugin '${n.name}' error handler failed:`, r);
|
|
764
|
+
});
|
|
765
|
+
}
|
|
766
|
+
/**
|
|
767
|
+
* Get metrics for a plugin
|
|
768
|
+
*/
|
|
769
|
+
getMetrics(e) {
|
|
770
|
+
return this.metrics.get(e);
|
|
771
|
+
}
|
|
772
|
+
initializeMetrics(e) {
|
|
773
|
+
this.metrics.set(e, /* @__PURE__ */ new Map());
|
|
774
|
+
}
|
|
775
|
+
recordSuccess(e, t, s) {
|
|
776
|
+
const r = this.metrics.get(e), n = r.get(t) || {
|
|
777
|
+
executionTime: 0,
|
|
778
|
+
executionCount: 0,
|
|
779
|
+
errorCount: 0
|
|
780
|
+
}, o = performance.now() - s;
|
|
781
|
+
r.set(t, {
|
|
782
|
+
...n,
|
|
783
|
+
executionTime: n.executionTime + o,
|
|
784
|
+
executionCount: n.executionCount + 1,
|
|
785
|
+
lastExecutionTime: o
|
|
786
|
+
});
|
|
787
|
+
}
|
|
788
|
+
recordError(e, t, s) {
|
|
789
|
+
const r = this.metrics.get(e), n = r.get(t) || {
|
|
790
|
+
executionTime: 0,
|
|
791
|
+
executionCount: 0,
|
|
792
|
+
errorCount: 0
|
|
793
|
+
};
|
|
794
|
+
r.set(t, {
|
|
795
|
+
...n,
|
|
796
|
+
errorCount: n.errorCount + 1,
|
|
797
|
+
lastError: s
|
|
798
|
+
});
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
const _ = class _ {
|
|
446
802
|
getInstance() {
|
|
447
|
-
return
|
|
803
|
+
return _._instance || (_._instance = new u({
|
|
448
804
|
__unsafe_ignore_singleton: !0
|
|
449
|
-
})),
|
|
805
|
+
})), _._instance;
|
|
450
806
|
}
|
|
451
807
|
setInstance(e) {
|
|
452
|
-
|
|
808
|
+
_._instance = e;
|
|
453
809
|
}
|
|
454
810
|
resetInstance() {
|
|
455
|
-
const e =
|
|
456
|
-
if (
|
|
811
|
+
const e = _._instance;
|
|
812
|
+
if (_._instance = new u({
|
|
457
813
|
__unsafe_ignore_singleton: !0
|
|
458
814
|
}), e)
|
|
459
815
|
for (const t of e.keepAliveBlocs)
|
|
460
|
-
|
|
816
|
+
_._instance.keepAliveBlocs.add(t), _._instance.uidRegistry.set(t.uid, t);
|
|
461
817
|
}
|
|
462
818
|
};
|
|
463
|
-
i(
|
|
464
|
-
let
|
|
465
|
-
function
|
|
819
|
+
i(_, "_instance");
|
|
820
|
+
let E = _, S = new E();
|
|
821
|
+
function W(c) {
|
|
466
822
|
S = c;
|
|
467
823
|
}
|
|
468
|
-
const
|
|
824
|
+
const h = class h {
|
|
469
825
|
/**
|
|
470
826
|
* Creates a new Blac instance.
|
|
471
827
|
* @param options - Configuration options including singleton control
|
|
@@ -488,12 +844,14 @@ const l = class l {
|
|
|
488
844
|
i(this, "keepAliveBlocs", /* @__PURE__ */ new Set());
|
|
489
845
|
/** Flag to control whether changes should be posted to document */
|
|
490
846
|
i(this, "postChangesToDocument", !1);
|
|
847
|
+
/** System plugin registry */
|
|
848
|
+
i(this, "plugins", new U());
|
|
491
849
|
/**
|
|
492
850
|
* Logs messages to console when logging is enabled
|
|
493
851
|
* @param args - Arguments to log
|
|
494
852
|
*/
|
|
495
853
|
i(this, "log", (...e) => {
|
|
496
|
-
|
|
854
|
+
h.logSpy && h.logSpy(e), h.enableLog && h.logLevel, h.enableLog && h.logLevel;
|
|
497
855
|
});
|
|
498
856
|
/**
|
|
499
857
|
* Logs a warning message
|
|
@@ -501,7 +859,7 @@ const l = class l {
|
|
|
501
859
|
* @param args - Additional arguments
|
|
502
860
|
*/
|
|
503
861
|
i(this, "warn", (e, ...t) => {
|
|
504
|
-
|
|
862
|
+
h.enableLog;
|
|
505
863
|
});
|
|
506
864
|
/**
|
|
507
865
|
* Logs an error message
|
|
@@ -509,7 +867,7 @@ const l = class l {
|
|
|
509
867
|
* @param args - Additional arguments
|
|
510
868
|
*/
|
|
511
869
|
i(this, "error", (e, ...t) => {
|
|
512
|
-
|
|
870
|
+
h.enableLog;
|
|
513
871
|
});
|
|
514
872
|
/**
|
|
515
873
|
* Resets the Blac instance to a new one, disposing non-keepAlive blocs
|
|
@@ -519,10 +877,10 @@ const l = class l {
|
|
|
519
877
|
this.log("Reset Blac instance");
|
|
520
878
|
const e = new Map(this.blocInstanceMap), t = new Map(this.isolatedBlocMap);
|
|
521
879
|
e.forEach((s) => {
|
|
522
|
-
!s._keepAlive && s._disposalState ===
|
|
880
|
+
!s._keepAlive && s._disposalState === y.ACTIVE && this.disposeBloc(s);
|
|
523
881
|
}), t.forEach((s) => {
|
|
524
|
-
s.forEach((
|
|
525
|
-
!
|
|
882
|
+
s.forEach((r) => {
|
|
883
|
+
!r._keepAlive && r._disposalState === y.ACTIVE && this.disposeBloc(r);
|
|
526
884
|
});
|
|
527
885
|
}), this.blocInstanceMap.clear(), this.isolatedBlocMap.clear(), this.isolatedBlocIndex.clear(), S.resetInstance();
|
|
528
886
|
});
|
|
@@ -533,21 +891,21 @@ const l = class l {
|
|
|
533
891
|
i(this, "disposeBloc", (e) => {
|
|
534
892
|
const t = e._disposalState;
|
|
535
893
|
if (![
|
|
536
|
-
|
|
537
|
-
|
|
894
|
+
y.ACTIVE,
|
|
895
|
+
y.DISPOSAL_REQUESTED
|
|
538
896
|
].includes(t)) {
|
|
539
897
|
this.log(
|
|
540
898
|
`[${e._name}:${String(e._id)}] disposeBloc called on bloc in invalid state: ${t}`
|
|
541
899
|
);
|
|
542
900
|
return;
|
|
543
901
|
}
|
|
544
|
-
const
|
|
902
|
+
const r = e.constructor, n = this.createBlocInstanceMapKey(e._name, e._id);
|
|
545
903
|
this.log(
|
|
546
|
-
`[${e._name}:${String(e._id)}] disposeBloc called. Isolated: ${String(
|
|
547
|
-
), e._dispose(),
|
|
904
|
+
`[${e._name}:${String(e._id)}] disposeBloc called. Isolated: ${String(r.isolated)}`
|
|
905
|
+
), e._dispose(), this.plugins.notifyBlocDisposed(e), r.isolated ? (this.unregisterIsolatedBlocInstance(e), this.blocInstanceMap.delete(n)) : this.unregisterBlocInstance(e), this.log("dispatched bloc", e);
|
|
548
906
|
});
|
|
549
907
|
i(this, "activateBloc", (e) => {
|
|
550
|
-
if (e._disposalState !==
|
|
908
|
+
if (e._disposalState !== y.ACTIVE) {
|
|
551
909
|
this.log(
|
|
552
910
|
`[${e._name}:${String(e._id)}] activateBloc called on disposed bloc. Ignoring.`
|
|
553
911
|
);
|
|
@@ -570,27 +928,27 @@ const l = class l {
|
|
|
570
928
|
* @returns The bloc instance
|
|
571
929
|
*/
|
|
572
930
|
i(this, "getBloc", (e, t = {}) => {
|
|
573
|
-
const { id: s, forceNewInstance:
|
|
931
|
+
const { id: s, forceNewInstance: r } = t, n = e, o = s ?? e.name;
|
|
574
932
|
if (this.log(`[${e.name}:${String(o)}] (getBloc) Called:`, {
|
|
575
933
|
options: t,
|
|
576
|
-
base:
|
|
577
|
-
}), !
|
|
578
|
-
if (
|
|
579
|
-
const
|
|
934
|
+
base: n
|
|
935
|
+
}), !r)
|
|
936
|
+
if (n.isolated) {
|
|
937
|
+
const l = this.findIsolatedBlocInstance(
|
|
580
938
|
e,
|
|
581
939
|
t.instanceRef ?? o
|
|
582
940
|
);
|
|
583
|
-
if (
|
|
584
|
-
return
|
|
941
|
+
if (l)
|
|
942
|
+
return l;
|
|
585
943
|
if (t.throwIfNotFound)
|
|
586
944
|
throw new Error(`Isolated bloc ${e.name} not found`);
|
|
587
945
|
} else {
|
|
588
|
-
const
|
|
946
|
+
const l = this.findRegisteredBlocInstance(
|
|
589
947
|
e,
|
|
590
948
|
o
|
|
591
949
|
);
|
|
592
|
-
if (
|
|
593
|
-
return
|
|
950
|
+
if (l)
|
|
951
|
+
return l;
|
|
594
952
|
if (t.throwIfNotFound)
|
|
595
953
|
throw new Error(`Registered bloc ${e.name} not found`);
|
|
596
954
|
}
|
|
@@ -614,9 +972,9 @@ const l = class l {
|
|
|
614
972
|
* - instanceRef: Optional reference string for the instance
|
|
615
973
|
*/
|
|
616
974
|
i(this, "getBlocOrThrow", (e, t = {}) => {
|
|
617
|
-
const s = e.isolated,
|
|
618
|
-
if (
|
|
619
|
-
return
|
|
975
|
+
const s = e.isolated, r = t.id || e.name, n = s ? this.findIsolatedBlocInstance(e, r) : this.findRegisteredBlocInstance(e, r);
|
|
976
|
+
if (n)
|
|
977
|
+
return n;
|
|
620
978
|
throw new Error(`Bloc ${e.name} not found`);
|
|
621
979
|
});
|
|
622
980
|
/**
|
|
@@ -628,11 +986,11 @@ const l = class l {
|
|
|
628
986
|
*/
|
|
629
987
|
i(this, "getAllBlocs", (e, t = {}) => {
|
|
630
988
|
const s = [];
|
|
631
|
-
if (this.blocInstanceMap.forEach((
|
|
632
|
-
|
|
989
|
+
if (this.blocInstanceMap.forEach((r) => {
|
|
990
|
+
r.constructor === e && s.push(r);
|
|
633
991
|
}), t.searchIsolated !== !1) {
|
|
634
|
-
const
|
|
635
|
-
|
|
992
|
+
const r = this.isolatedBlocMap.get(e);
|
|
993
|
+
r && s.push(...r.map((n) => n));
|
|
636
994
|
}
|
|
637
995
|
return s;
|
|
638
996
|
});
|
|
@@ -655,8 +1013,8 @@ const l = class l {
|
|
|
655
1013
|
for (const s of this.blocInstanceMap.values())
|
|
656
1014
|
e(s) && t.push(s);
|
|
657
1015
|
for (const s of this.isolatedBlocMap.values())
|
|
658
|
-
for (const
|
|
659
|
-
e(
|
|
1016
|
+
for (const r of s)
|
|
1017
|
+
e(r) && t.push(r);
|
|
660
1018
|
t.forEach((s) => s._dispose());
|
|
661
1019
|
});
|
|
662
1020
|
/**
|
|
@@ -677,20 +1035,20 @@ const l = class l {
|
|
|
677
1035
|
*/
|
|
678
1036
|
i(this, "validateConsumers", () => {
|
|
679
1037
|
for (const e of this.uidRegistry.values())
|
|
680
|
-
e._validateConsumers(), e._consumers.size === 0 && !e._keepAlive && e._disposalState ===
|
|
681
|
-
e._consumers.size === 0 && !e._keepAlive && e._disposalState ===
|
|
1038
|
+
e._validateConsumers(), e._consumers.size === 0 && !e._keepAlive && e._disposalState === y.ACTIVE && setTimeout(() => {
|
|
1039
|
+
e._consumers.size === 0 && !e._keepAlive && e._disposalState === y.ACTIVE && this.disposeBloc(e);
|
|
682
1040
|
}, 1e3);
|
|
683
1041
|
});
|
|
684
1042
|
const { __unsafe_ignore_singleton: t = !1 } = e;
|
|
685
1043
|
if (!t)
|
|
686
|
-
return
|
|
687
|
-
S.setInstance(this);
|
|
1044
|
+
return h.instance;
|
|
1045
|
+
S.setInstance(this), this.plugins.bootstrap();
|
|
688
1046
|
}
|
|
689
1047
|
static get instance() {
|
|
690
1048
|
return S.getInstance();
|
|
691
1049
|
}
|
|
692
1050
|
static get getAllBlocs() {
|
|
693
|
-
return
|
|
1051
|
+
return h.instance.getAllBlocs;
|
|
694
1052
|
}
|
|
695
1053
|
/** Get current configuration */
|
|
696
1054
|
static get config() {
|
|
@@ -712,7 +1070,7 @@ const l = class l {
|
|
|
712
1070
|
}, this.enableLog && this.instance.log("Blac config updated:", this._config);
|
|
713
1071
|
}
|
|
714
1072
|
static get log() {
|
|
715
|
-
return
|
|
1073
|
+
return h.instance.log;
|
|
716
1074
|
}
|
|
717
1075
|
/**
|
|
718
1076
|
* Gets the current Blac instance
|
|
@@ -722,13 +1080,13 @@ const l = class l {
|
|
|
722
1080
|
return S.getInstance();
|
|
723
1081
|
}
|
|
724
1082
|
static get warn() {
|
|
725
|
-
return
|
|
1083
|
+
return h.instance.warn;
|
|
726
1084
|
}
|
|
727
1085
|
static get error() {
|
|
728
|
-
return
|
|
1086
|
+
return h.instance.error;
|
|
729
1087
|
}
|
|
730
1088
|
static get disposeBloc() {
|
|
731
|
-
return
|
|
1089
|
+
return h.instance.disposeBloc;
|
|
732
1090
|
}
|
|
733
1091
|
/**
|
|
734
1092
|
* Creates a unique key for a bloc instance in the map based on the bloc class name and instance ID
|
|
@@ -763,8 +1121,8 @@ const l = class l {
|
|
|
763
1121
|
*/
|
|
764
1122
|
findRegisteredBlocInstance(e, t) {
|
|
765
1123
|
if (e.isolated) return;
|
|
766
|
-
const
|
|
767
|
-
return this.blocInstanceMap.get(
|
|
1124
|
+
const r = this.createBlocInstanceMapKey(e.name, t);
|
|
1125
|
+
return this.blocInstanceMap.get(r);
|
|
768
1126
|
}
|
|
769
1127
|
/**
|
|
770
1128
|
* Registers an isolated bloc instance in the isolated registry
|
|
@@ -780,14 +1138,14 @@ const l = class l {
|
|
|
780
1138
|
*/
|
|
781
1139
|
unregisterIsolatedBlocInstance(e) {
|
|
782
1140
|
const t = e.constructor, s = this.isolatedBlocMap.get(t);
|
|
783
|
-
let
|
|
1141
|
+
let r = !1;
|
|
784
1142
|
if (s) {
|
|
785
1143
|
const o = s.findIndex((a) => a.uid === e.uid);
|
|
786
|
-
o !== -1 && (s.splice(o, 1),
|
|
1144
|
+
o !== -1 && (s.splice(o, 1), r = !0), s.length === 0 && this.isolatedBlocMap.delete(t);
|
|
787
1145
|
}
|
|
788
|
-
const
|
|
789
|
-
this.uidRegistry.delete(e.uid), this.keepAliveBlocs.delete(e),
|
|
790
|
-
`[Blac] Inconsistent state detected during isolated bloc cleanup for ${e._name}:${e.uid}. Map removal: ${
|
|
1146
|
+
const n = this.isolatedBlocIndex.delete(e.uid);
|
|
1147
|
+
this.uidRegistry.delete(e.uid), this.keepAliveBlocs.delete(e), r !== n && this.warn(
|
|
1148
|
+
`[Blac] Inconsistent state detected during isolated bloc cleanup for ${e._name}:${e.uid}. Map removal: ${r}, Index removal: ${n}`
|
|
791
1149
|
);
|
|
792
1150
|
}
|
|
793
1151
|
/**
|
|
@@ -795,8 +1153,8 @@ const l = class l {
|
|
|
795
1153
|
*/
|
|
796
1154
|
findIsolatedBlocInstance(e, t) {
|
|
797
1155
|
if (!e.isolated) return;
|
|
798
|
-
const
|
|
799
|
-
return
|
|
1156
|
+
const r = this.isolatedBlocMap.get(e);
|
|
1157
|
+
return r ? r.find((o) => o._id === t) : void 0;
|
|
800
1158
|
}
|
|
801
1159
|
/**
|
|
802
1160
|
* Finds an isolated bloc instance by UID (O(1) lookup)
|
|
@@ -813,41 +1171,58 @@ const l = class l {
|
|
|
813
1171
|
* @returns The newly created bloc instance
|
|
814
1172
|
*/
|
|
815
1173
|
createNewBlocInstance(e, t, s = {}) {
|
|
816
|
-
const { props:
|
|
817
|
-
return o._instanceRef =
|
|
1174
|
+
const { props: r, instanceRef: n } = s, o = new e(r);
|
|
1175
|
+
return o._instanceRef = n, o.props = r || null, o._updateId(t), o._setDisposalHandler((a) => this.disposeBloc(a)), o.isIsolated ? this.registerIsolatedBlocInstance(o) : this.registerBlocInstance(o), o._activatePlugins(), this.plugins.notifyBlocCreated(o), o;
|
|
818
1176
|
}
|
|
819
1177
|
static get activateBloc() {
|
|
820
|
-
return
|
|
1178
|
+
return h.instance.activateBloc;
|
|
821
1179
|
}
|
|
822
1180
|
static get getBloc() {
|
|
823
|
-
return
|
|
1181
|
+
return h.instance.getBloc;
|
|
824
1182
|
}
|
|
825
1183
|
static get getBlocOrThrow() {
|
|
826
|
-
return
|
|
1184
|
+
return h.instance.getBlocOrThrow;
|
|
827
1185
|
}
|
|
828
1186
|
static get disposeKeepAliveBlocs() {
|
|
829
|
-
return
|
|
1187
|
+
return h.instance.disposeKeepAliveBlocs;
|
|
830
1188
|
}
|
|
831
1189
|
static get disposeBlocs() {
|
|
832
|
-
return
|
|
1190
|
+
return h.instance.disposeBlocs;
|
|
833
1191
|
}
|
|
834
1192
|
static get getMemoryStats() {
|
|
835
|
-
return
|
|
1193
|
+
return h.instance.getMemoryStats;
|
|
836
1194
|
}
|
|
837
1195
|
static get validateConsumers() {
|
|
838
|
-
return
|
|
1196
|
+
return h.instance.validateConsumers;
|
|
1197
|
+
}
|
|
1198
|
+
/**
|
|
1199
|
+
* Bootstrap the Blac instance and all plugins
|
|
1200
|
+
*/
|
|
1201
|
+
bootstrap() {
|
|
1202
|
+
this.plugins.bootstrap();
|
|
1203
|
+
}
|
|
1204
|
+
/**
|
|
1205
|
+
* Shutdown the Blac instance and all plugins
|
|
1206
|
+
*/
|
|
1207
|
+
shutdown() {
|
|
1208
|
+
this.plugins.shutdown();
|
|
1209
|
+
for (const e of this.blocInstanceMap.values())
|
|
1210
|
+
e._keepAlive || this.disposeBloc(e);
|
|
1211
|
+
for (const e of this.isolatedBlocMap.values())
|
|
1212
|
+
for (const t of e)
|
|
1213
|
+
t._keepAlive || this.disposeBloc(t);
|
|
839
1214
|
}
|
|
840
1215
|
};
|
|
841
1216
|
/** Private static configuration */
|
|
842
|
-
i(
|
|
1217
|
+
i(h, "_config", {
|
|
843
1218
|
exposeBlacInstance: !1,
|
|
844
1219
|
proxyDependencyTracking: !0
|
|
845
1220
|
}), /** Flag to enable/disable logging */
|
|
846
|
-
i(
|
|
1221
|
+
i(h, "enableLog", !1), i(h, "logLevel", "warn"), i(h, "logSpy", null), i(h, "resetInstance", () => {
|
|
847
1222
|
S.resetInstance();
|
|
848
1223
|
});
|
|
849
|
-
let
|
|
850
|
-
class
|
|
1224
|
+
let u = h;
|
|
1225
|
+
class j extends k {
|
|
851
1226
|
constructor() {
|
|
852
1227
|
super(...arguments);
|
|
853
1228
|
i(this, "eventHandlers", /* @__PURE__ */ new Map());
|
|
@@ -867,7 +1242,20 @@ class U extends x {
|
|
|
867
1242
|
* @param action The action/event instance to be processed.
|
|
868
1243
|
*/
|
|
869
1244
|
i(this, "add", async (t) => {
|
|
870
|
-
|
|
1245
|
+
let s = t;
|
|
1246
|
+
try {
|
|
1247
|
+
s = this._plugins.transformEvent(t);
|
|
1248
|
+
} catch (r) {
|
|
1249
|
+
console.error("Error transforming event:", r);
|
|
1250
|
+
}
|
|
1251
|
+
if (s !== null) {
|
|
1252
|
+
try {
|
|
1253
|
+
this._plugins.notifyEvent(s);
|
|
1254
|
+
} catch (r) {
|
|
1255
|
+
console.error("Error notifying plugins of event:", r);
|
|
1256
|
+
}
|
|
1257
|
+
u.instance.plugins.notifyEventAdded(this, s), this._eventQueue.push(s), this._isProcessingEvent || await this._processEventQueue();
|
|
1258
|
+
}
|
|
871
1259
|
});
|
|
872
1260
|
}
|
|
873
1261
|
/**
|
|
@@ -878,7 +1266,7 @@ class U extends x {
|
|
|
878
1266
|
* The 'event' parameter in the handler will be typed to the specific eventConstructor.
|
|
879
1267
|
*/
|
|
880
1268
|
on(t, s) {
|
|
881
|
-
this.eventHandlers.has(t) &&
|
|
1269
|
+
this.eventHandlers.has(t) && u.warn(
|
|
882
1270
|
`[Bloc ${this._name}:${String(this._id)}] Handler for event '${t.name}' already registered. It will be overwritten.`
|
|
883
1271
|
), this.eventHandlers.set(
|
|
884
1272
|
t,
|
|
@@ -907,16 +1295,16 @@ class U extends x {
|
|
|
907
1295
|
* Processes a single event
|
|
908
1296
|
*/
|
|
909
1297
|
async _processEvent(t) {
|
|
910
|
-
const s = t.constructor,
|
|
911
|
-
if (
|
|
912
|
-
const
|
|
1298
|
+
const s = t.constructor, r = this.eventHandlers.get(s);
|
|
1299
|
+
if (r) {
|
|
1300
|
+
const n = (o) => {
|
|
913
1301
|
const a = this.state;
|
|
914
1302
|
this._pushState(o, a, t);
|
|
915
1303
|
};
|
|
916
1304
|
try {
|
|
917
|
-
await
|
|
1305
|
+
await r(t, n);
|
|
918
1306
|
} catch (o) {
|
|
919
|
-
const a = t.constructor.name || "UnnamedConstructor",
|
|
1307
|
+
const a = t.constructor.name || "UnnamedConstructor", l = {
|
|
920
1308
|
blocName: this._name,
|
|
921
1309
|
blocId: String(this._id),
|
|
922
1310
|
eventType: a,
|
|
@@ -924,18 +1312,32 @@ class U extends x {
|
|
|
924
1312
|
action: t,
|
|
925
1313
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
926
1314
|
};
|
|
927
|
-
if (
|
|
1315
|
+
if (u.error(
|
|
928
1316
|
`[Bloc ${this._name}:${String(this._id)}] Error in event handler for '${a}':`,
|
|
929
1317
|
o,
|
|
930
1318
|
"Context:",
|
|
931
|
-
|
|
932
|
-
), o instanceof Error
|
|
1319
|
+
l
|
|
1320
|
+
), o instanceof Error)
|
|
1321
|
+
try {
|
|
1322
|
+
this._plugins.notifyError(o, {
|
|
1323
|
+
phase: "event-processing",
|
|
1324
|
+
operation: "handler",
|
|
1325
|
+
metadata: { event: t }
|
|
1326
|
+
}), u.instance.plugins.notifyError(o, this, {
|
|
1327
|
+
phase: "event-processing",
|
|
1328
|
+
operation: "handler",
|
|
1329
|
+
metadata: { event: t }
|
|
1330
|
+
});
|
|
1331
|
+
} catch (d) {
|
|
1332
|
+
console.error("Error notifying plugins:", d);
|
|
1333
|
+
}
|
|
1334
|
+
if (o instanceof Error && o.name === "CriticalError")
|
|
933
1335
|
throw o;
|
|
934
1336
|
}
|
|
935
1337
|
} else {
|
|
936
|
-
const
|
|
937
|
-
|
|
938
|
-
`[Bloc ${this._name}:${String(this._id)}] No handler registered for action type: '${
|
|
1338
|
+
const n = t.constructor.name || "UnnamedConstructor";
|
|
1339
|
+
u.warn(
|
|
1340
|
+
`[Bloc ${this._name}:${String(this._id)}] No handler registered for action type: '${n}'.`,
|
|
939
1341
|
"Registered handlers:",
|
|
940
1342
|
Array.from(this.eventHandlers.keys()).map((o) => o.name),
|
|
941
1343
|
"Action was:",
|
|
@@ -944,7 +1346,7 @@ class U extends x {
|
|
|
944
1346
|
}
|
|
945
1347
|
}
|
|
946
1348
|
}
|
|
947
|
-
class
|
|
1349
|
+
class z extends k {
|
|
948
1350
|
/**
|
|
949
1351
|
* @internal
|
|
950
1352
|
* Protected method for useBloc to call
|
|
@@ -976,7 +1378,7 @@ class H extends x {
|
|
|
976
1378
|
*/
|
|
977
1379
|
patch(e, t = !1) {
|
|
978
1380
|
if (typeof this.state != "object" || this.state === null) {
|
|
979
|
-
|
|
1381
|
+
u.warn(
|
|
980
1382
|
"Cubit.patch: was called on a cubit where the state is not an object. This is a no-op."
|
|
981
1383
|
);
|
|
982
1384
|
return;
|
|
@@ -985,10 +1387,10 @@ class H extends x {
|
|
|
985
1387
|
if (t)
|
|
986
1388
|
s = !0;
|
|
987
1389
|
else
|
|
988
|
-
for (const
|
|
989
|
-
if (Object.prototype.hasOwnProperty.call(e,
|
|
990
|
-
const o = this.state[
|
|
991
|
-
if (!Object.is(e[
|
|
1390
|
+
for (const r in e)
|
|
1391
|
+
if (Object.prototype.hasOwnProperty.call(e, r)) {
|
|
1392
|
+
const o = this.state[r];
|
|
1393
|
+
if (!Object.is(e[r], o)) {
|
|
992
1394
|
s = !0;
|
|
993
1395
|
break;
|
|
994
1396
|
}
|
|
@@ -999,12 +1401,12 @@ class H extends x {
|
|
|
999
1401
|
});
|
|
1000
1402
|
}
|
|
1001
1403
|
}
|
|
1002
|
-
class
|
|
1404
|
+
class L {
|
|
1003
1405
|
constructor(e) {
|
|
1004
1406
|
this.props = e;
|
|
1005
1407
|
}
|
|
1006
1408
|
}
|
|
1007
|
-
function
|
|
1409
|
+
function N(c, e) {
|
|
1008
1410
|
if (Object.is(c, e))
|
|
1009
1411
|
return !0;
|
|
1010
1412
|
if (typeof c != "object" || c === null || typeof e != "object" || e === null)
|
|
@@ -1012,90 +1414,90 @@ function j(c, e) {
|
|
|
1012
1414
|
const t = Object.keys(c), s = Object.keys(e);
|
|
1013
1415
|
if (t.length !== s.length)
|
|
1014
1416
|
return !1;
|
|
1015
|
-
for (let
|
|
1016
|
-
const
|
|
1017
|
-
if (!Object.prototype.hasOwnProperty.call(e,
|
|
1417
|
+
for (let r = 0; r < t.length; r++) {
|
|
1418
|
+
const n = t[r];
|
|
1419
|
+
if (!Object.prototype.hasOwnProperty.call(e, n) || !Object.is(c[n], e[n]))
|
|
1018
1420
|
return !1;
|
|
1019
1421
|
}
|
|
1020
1422
|
return !0;
|
|
1021
1423
|
}
|
|
1022
|
-
class
|
|
1424
|
+
class q {
|
|
1023
1425
|
/**
|
|
1024
1426
|
* Sets up a clean test environment
|
|
1025
1427
|
*/
|
|
1026
1428
|
static setUp() {
|
|
1027
|
-
this.originalInstance =
|
|
1429
|
+
this.originalInstance = u.instance, u.resetInstance(), u.enableLog = !1;
|
|
1028
1430
|
}
|
|
1029
1431
|
/**
|
|
1030
1432
|
* Tears down the test environment and restores original state
|
|
1031
1433
|
*/
|
|
1032
1434
|
static tearDown() {
|
|
1033
|
-
|
|
1435
|
+
u.resetInstance();
|
|
1034
1436
|
}
|
|
1035
1437
|
/**
|
|
1036
1438
|
* Creates a test bloc with automatic cleanup
|
|
1037
1439
|
*/
|
|
1038
1440
|
static createBloc(e, ...t) {
|
|
1039
1441
|
const s = new e(...t);
|
|
1040
|
-
return
|
|
1442
|
+
return u.activateBloc(s), s;
|
|
1041
1443
|
}
|
|
1042
1444
|
/**
|
|
1043
1445
|
* Waits for a bloc to emit a specific state
|
|
1044
1446
|
*/
|
|
1045
1447
|
static async waitForState(e, t, s = 5e3) {
|
|
1046
|
-
return new Promise((
|
|
1448
|
+
return new Promise((r, n) => {
|
|
1047
1449
|
const o = setTimeout(() => {
|
|
1048
|
-
|
|
1450
|
+
n(
|
|
1049
1451
|
new Error(
|
|
1050
1452
|
`Timeout waiting for state matching predicate after ${s}ms`
|
|
1051
1453
|
)
|
|
1052
1454
|
);
|
|
1053
1455
|
}, s), a = e._observer.subscribe({
|
|
1054
1456
|
id: `test-waiter-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
|
|
1055
|
-
fn: (
|
|
1056
|
-
t(
|
|
1457
|
+
fn: (l) => {
|
|
1458
|
+
t(l) && (clearTimeout(o), a(), r(l));
|
|
1057
1459
|
}
|
|
1058
1460
|
});
|
|
1059
|
-
t(e.state) && (clearTimeout(o), a(),
|
|
1461
|
+
t(e.state) && (clearTimeout(o), a(), r(e.state));
|
|
1060
1462
|
});
|
|
1061
1463
|
}
|
|
1062
1464
|
/**
|
|
1063
1465
|
* Expects a bloc to emit specific states in order
|
|
1064
1466
|
*/
|
|
1065
1467
|
static async expectStates(e, t, s = 5e3) {
|
|
1066
|
-
const
|
|
1067
|
-
return new Promise((
|
|
1468
|
+
const r = [];
|
|
1469
|
+
return new Promise((n, o) => {
|
|
1068
1470
|
const a = setTimeout(() => {
|
|
1069
1471
|
o(
|
|
1070
1472
|
new Error(
|
|
1071
|
-
`Timeout waiting for states. Expected: ${JSON.stringify(t)}, Received: ${JSON.stringify(
|
|
1473
|
+
`Timeout waiting for states. Expected: ${JSON.stringify(t)}, Received: ${JSON.stringify(r)}`
|
|
1072
1474
|
)
|
|
1073
1475
|
);
|
|
1074
|
-
}, s),
|
|
1476
|
+
}, s), l = e._observer.subscribe({
|
|
1075
1477
|
id: `test-expecter-${crypto.randomUUID()}`,
|
|
1076
|
-
fn: (
|
|
1077
|
-
if (
|
|
1078
|
-
clearTimeout(a),
|
|
1079
|
-
for (let
|
|
1080
|
-
const m = t[
|
|
1081
|
-
if (JSON.stringify(m) !== JSON.stringify(
|
|
1478
|
+
fn: (d) => {
|
|
1479
|
+
if (r.push(d), r.length === t.length) {
|
|
1480
|
+
clearTimeout(a), l();
|
|
1481
|
+
for (let f = 0; f < t.length; f++) {
|
|
1482
|
+
const m = t[f], v = r[f];
|
|
1483
|
+
if (JSON.stringify(m) !== JSON.stringify(v)) {
|
|
1082
1484
|
o(
|
|
1083
1485
|
new Error(
|
|
1084
|
-
`State mismatch at index ${
|
|
1486
|
+
`State mismatch at index ${f}. Expected: ${JSON.stringify(m)}, Received: ${JSON.stringify(v)}`
|
|
1085
1487
|
)
|
|
1086
1488
|
);
|
|
1087
1489
|
return;
|
|
1088
1490
|
}
|
|
1089
1491
|
}
|
|
1090
|
-
|
|
1492
|
+
n();
|
|
1091
1493
|
}
|
|
1092
1494
|
}
|
|
1093
1495
|
});
|
|
1094
1496
|
});
|
|
1095
1497
|
}
|
|
1096
1498
|
}
|
|
1097
|
-
i(
|
|
1098
|
-
class
|
|
1499
|
+
i(q, "originalInstance");
|
|
1500
|
+
class F extends j {
|
|
1099
1501
|
constructor(t) {
|
|
1100
1502
|
super(t);
|
|
1101
1503
|
i(this, "mockHandlers", /* @__PURE__ */ new Map());
|
|
@@ -1119,7 +1521,7 @@ class Q extends U {
|
|
|
1119
1521
|
return this.eventHandlers.has(t);
|
|
1120
1522
|
}
|
|
1121
1523
|
}
|
|
1122
|
-
class
|
|
1524
|
+
class G extends z {
|
|
1123
1525
|
constructor(t) {
|
|
1124
1526
|
super(t);
|
|
1125
1527
|
i(this, "stateHistory", []);
|
|
@@ -1144,16 +1546,16 @@ class W extends H {
|
|
|
1144
1546
|
this.stateHistory = [this.state];
|
|
1145
1547
|
}
|
|
1146
1548
|
}
|
|
1147
|
-
class
|
|
1549
|
+
class J {
|
|
1148
1550
|
constructor() {
|
|
1149
1551
|
i(this, "initialStats");
|
|
1150
|
-
this.initialStats =
|
|
1552
|
+
this.initialStats = u.getMemoryStats();
|
|
1151
1553
|
}
|
|
1152
1554
|
/**
|
|
1153
1555
|
* Check for memory leaks and return a report
|
|
1154
1556
|
*/
|
|
1155
1557
|
checkForLeaks() {
|
|
1156
|
-
const e =
|
|
1558
|
+
const e = u.getMemoryStats(), t = e.registeredBlocs > this.initialStats.registeredBlocs || e.isolatedBlocs > this.initialStats.isolatedBlocs || e.keepAliveBlocs > this.initialStats.keepAliveBlocs, s = `
|
|
1157
1559
|
Memory Leak Detection Report:
|
|
1158
1560
|
- Initial registered blocs: ${this.initialStats.registeredBlocs}
|
|
1159
1561
|
- Current registered blocs: ${e.registeredBlocs}
|
|
@@ -1170,7 +1572,7 @@ Memory Leak Detection Report:
|
|
|
1170
1572
|
};
|
|
1171
1573
|
}
|
|
1172
1574
|
}
|
|
1173
|
-
class
|
|
1575
|
+
class K {
|
|
1174
1576
|
constructor() {
|
|
1175
1577
|
i(this, "consumers", /* @__PURE__ */ new WeakMap());
|
|
1176
1578
|
i(this, "registrationCount", 0);
|
|
@@ -1193,11 +1595,11 @@ class z {
|
|
|
1193
1595
|
unregister(e) {
|
|
1194
1596
|
e && this.consumers.get(e) && (this.consumers.delete(e), this.activeConsumers = Math.max(0, this.activeConsumers - 1));
|
|
1195
1597
|
}
|
|
1196
|
-
trackAccess(e, t, s,
|
|
1197
|
-
const
|
|
1198
|
-
if (!
|
|
1598
|
+
trackAccess(e, t, s, r) {
|
|
1599
|
+
const n = this.consumers.get(e);
|
|
1600
|
+
if (!n) return;
|
|
1199
1601
|
const o = Date.now();
|
|
1200
|
-
|
|
1602
|
+
n.firstAccessTime || (n.firstAccessTime = o), n.accessCount++, n.lastAccessTime = o, t === "state" ? (n.stateAccesses.add(s), r !== void 0 && n.stateValues.set(s, { value: r, lastAccessTime: o })) : (n.classAccesses.add(s), r !== void 0 && n.classValues.set(s, { value: r, lastAccessTime: o }));
|
|
1201
1603
|
}
|
|
1202
1604
|
resetTracking(e) {
|
|
1203
1605
|
const t = this.consumers.get(e);
|
|
@@ -1211,41 +1613,41 @@ class z {
|
|
|
1211
1613
|
} : null;
|
|
1212
1614
|
}
|
|
1213
1615
|
hasValuesChanged(e, t, s) {
|
|
1214
|
-
const
|
|
1215
|
-
if (!
|
|
1216
|
-
let
|
|
1616
|
+
const r = this.consumers.get(e);
|
|
1617
|
+
if (!r) return !0;
|
|
1618
|
+
let n = !1;
|
|
1217
1619
|
const o = Date.now();
|
|
1218
|
-
if (
|
|
1620
|
+
if (r.stateValues.size === 0 && r.classValues.size === 0 && (r.stateAccesses.size > 0 || r.classAccesses.size > 0))
|
|
1219
1621
|
return !0;
|
|
1220
|
-
for (const [a,
|
|
1622
|
+
for (const [a, l] of r.stateValues)
|
|
1221
1623
|
try {
|
|
1222
|
-
const
|
|
1223
|
-
|
|
1224
|
-
value:
|
|
1624
|
+
const d = this.getValueAtPath(t, a);
|
|
1625
|
+
d !== l.value && (r.stateValues.set(a, {
|
|
1626
|
+
value: d,
|
|
1225
1627
|
lastAccessTime: o
|
|
1226
|
-
}),
|
|
1628
|
+
}), n = !0);
|
|
1227
1629
|
} catch {
|
|
1228
|
-
|
|
1630
|
+
n = !0;
|
|
1229
1631
|
}
|
|
1230
|
-
for (const [a,
|
|
1632
|
+
for (const [a, l] of r.classValues)
|
|
1231
1633
|
try {
|
|
1232
|
-
const
|
|
1233
|
-
|
|
1234
|
-
value:
|
|
1634
|
+
const d = this.getValueAtPath(s, a);
|
|
1635
|
+
d !== l.value && (r.classValues.set(a, {
|
|
1636
|
+
value: d,
|
|
1235
1637
|
lastAccessTime: o
|
|
1236
|
-
}),
|
|
1638
|
+
}), n = !0);
|
|
1237
1639
|
} catch {
|
|
1238
|
-
|
|
1640
|
+
n = !0;
|
|
1239
1641
|
}
|
|
1240
|
-
return
|
|
1642
|
+
return n;
|
|
1241
1643
|
}
|
|
1242
1644
|
shouldNotifyConsumer(e, t) {
|
|
1243
1645
|
const s = this.consumers.get(e);
|
|
1244
1646
|
if (!s) return !1;
|
|
1245
|
-
for (const
|
|
1246
|
-
if (s.stateAccesses.has(
|
|
1247
|
-
for (const
|
|
1248
|
-
if (
|
|
1647
|
+
for (const r of t) {
|
|
1648
|
+
if (s.stateAccesses.has(r) || s.classAccesses.has(r)) return !0;
|
|
1649
|
+
for (const n of s.stateAccesses)
|
|
1650
|
+
if (r.startsWith(n + ".") || n.startsWith(r + "."))
|
|
1249
1651
|
return !0;
|
|
1250
1652
|
}
|
|
1251
1653
|
return !1;
|
|
@@ -1272,16 +1674,16 @@ class z {
|
|
|
1272
1674
|
}
|
|
1273
1675
|
getValueAtPath(e, t) {
|
|
1274
1676
|
const s = t.split(".");
|
|
1275
|
-
let
|
|
1276
|
-
for (const
|
|
1277
|
-
if (
|
|
1278
|
-
|
|
1677
|
+
let r = e;
|
|
1678
|
+
for (const n of s) {
|
|
1679
|
+
if (r == null) return;
|
|
1680
|
+
r = r[n];
|
|
1279
1681
|
}
|
|
1280
|
-
return
|
|
1682
|
+
return r;
|
|
1281
1683
|
}
|
|
1282
1684
|
}
|
|
1283
|
-
const
|
|
1284
|
-
let
|
|
1685
|
+
const x = /* @__PURE__ */ new WeakMap();
|
|
1686
|
+
let p = {
|
|
1285
1687
|
stateProxiesCreated: 0,
|
|
1286
1688
|
classProxiesCreated: 0,
|
|
1287
1689
|
cacheHits: 0,
|
|
@@ -1291,44 +1693,44 @@ let f = {
|
|
|
1291
1693
|
totalProxiesCreated: 0,
|
|
1292
1694
|
createdAt: Date.now()
|
|
1293
1695
|
};
|
|
1294
|
-
class
|
|
1696
|
+
class I {
|
|
1295
1697
|
static createStateProxy(e) {
|
|
1296
|
-
const { target: t, consumerRef: s, consumerTracker:
|
|
1297
|
-
if (!s || !
|
|
1698
|
+
const { target: t, consumerRef: s, consumerTracker: r, path: n = "" } = e;
|
|
1699
|
+
if (!s || !r || typeof t != "object" || t === null)
|
|
1298
1700
|
return t;
|
|
1299
|
-
let o =
|
|
1300
|
-
o || (o = /* @__PURE__ */ new WeakMap(),
|
|
1701
|
+
let o = x.get(t);
|
|
1702
|
+
o || (o = /* @__PURE__ */ new WeakMap(), x.set(t, o));
|
|
1301
1703
|
const a = o.get(s);
|
|
1302
1704
|
if (a)
|
|
1303
|
-
return
|
|
1304
|
-
|
|
1305
|
-
const
|
|
1306
|
-
get(
|
|
1705
|
+
return p.cacheHits++, a;
|
|
1706
|
+
p.cacheMisses++;
|
|
1707
|
+
const l = {
|
|
1708
|
+
get(f, m) {
|
|
1307
1709
|
if (typeof m == "symbol" || m === "constructor")
|
|
1308
|
-
return Reflect.get(
|
|
1309
|
-
const
|
|
1310
|
-
|
|
1311
|
-
const g = Reflect.get(
|
|
1312
|
-
if (
|
|
1313
|
-
const
|
|
1314
|
-
if (
|
|
1315
|
-
return
|
|
1710
|
+
return Reflect.get(f, m);
|
|
1711
|
+
const v = n ? `${n}.${m}` : m;
|
|
1712
|
+
p.propertyAccesses++;
|
|
1713
|
+
const g = Reflect.get(f, m), B = g && typeof g === "object" && g !== null ? void 0 : g;
|
|
1714
|
+
if (r.trackAccess(s, "state", v, B), g && typeof g == "object" && g !== null) {
|
|
1715
|
+
const w = Object.getPrototypeOf(g) === Object.prototype, T = Array.isArray(g);
|
|
1716
|
+
if (w || T)
|
|
1717
|
+
return p.nestedProxiesCreated++, I.createStateProxy({
|
|
1316
1718
|
target: g,
|
|
1317
1719
|
consumerRef: s,
|
|
1318
|
-
consumerTracker:
|
|
1319
|
-
path:
|
|
1720
|
+
consumerTracker: r,
|
|
1721
|
+
path: v
|
|
1320
1722
|
});
|
|
1321
1723
|
}
|
|
1322
1724
|
return g;
|
|
1323
1725
|
},
|
|
1324
|
-
has(
|
|
1325
|
-
return m in
|
|
1726
|
+
has(f, m) {
|
|
1727
|
+
return m in f;
|
|
1326
1728
|
},
|
|
1327
|
-
ownKeys(
|
|
1328
|
-
return Reflect.ownKeys(
|
|
1729
|
+
ownKeys(f) {
|
|
1730
|
+
return Reflect.ownKeys(f);
|
|
1329
1731
|
},
|
|
1330
|
-
getOwnPropertyDescriptor(
|
|
1331
|
-
return Reflect.getOwnPropertyDescriptor(
|
|
1732
|
+
getOwnPropertyDescriptor(f, m) {
|
|
1733
|
+
return Reflect.getOwnPropertyDescriptor(f, m);
|
|
1332
1734
|
},
|
|
1333
1735
|
set() {
|
|
1334
1736
|
return !1;
|
|
@@ -1336,90 +1738,90 @@ class b {
|
|
|
1336
1738
|
deleteProperty() {
|
|
1337
1739
|
return !1;
|
|
1338
1740
|
}
|
|
1339
|
-
},
|
|
1340
|
-
return o.set(s,
|
|
1741
|
+
}, d = new Proxy(t, l);
|
|
1742
|
+
return o.set(s, d), p.stateProxiesCreated++, p.totalProxiesCreated++, d;
|
|
1341
1743
|
}
|
|
1342
1744
|
static createClassProxy(e) {
|
|
1343
|
-
const { target: t, consumerRef: s, consumerTracker:
|
|
1344
|
-
if (!s || !
|
|
1745
|
+
const { target: t, consumerRef: s, consumerTracker: r } = e;
|
|
1746
|
+
if (!s || !r)
|
|
1345
1747
|
return t;
|
|
1346
|
-
let
|
|
1347
|
-
|
|
1348
|
-
const o =
|
|
1748
|
+
let n = x.get(t);
|
|
1749
|
+
n || (n = /* @__PURE__ */ new WeakMap(), x.set(t, n));
|
|
1750
|
+
const o = n.get(s);
|
|
1349
1751
|
if (o)
|
|
1350
|
-
return
|
|
1351
|
-
|
|
1752
|
+
return p.cacheHits++, o;
|
|
1753
|
+
p.cacheMisses++;
|
|
1352
1754
|
const a = {
|
|
1353
|
-
get(
|
|
1354
|
-
const m = Reflect.get(
|
|
1355
|
-
let
|
|
1356
|
-
const A = /* @__PURE__ */ new WeakSet(),
|
|
1357
|
-
let
|
|
1358
|
-
for (; g && !
|
|
1755
|
+
get(d, f) {
|
|
1756
|
+
const m = Reflect.get(d, f);
|
|
1757
|
+
let v = !1, g = d;
|
|
1758
|
+
const A = /* @__PURE__ */ new WeakSet(), P = 10;
|
|
1759
|
+
let B = 0;
|
|
1760
|
+
for (; g && !v && B < P && !A.has(g); ) {
|
|
1359
1761
|
A.add(g);
|
|
1360
1762
|
try {
|
|
1361
|
-
const
|
|
1763
|
+
const C = Object.getOwnPropertyDescriptor(
|
|
1362
1764
|
g,
|
|
1363
|
-
|
|
1765
|
+
f
|
|
1364
1766
|
);
|
|
1365
|
-
if (
|
|
1366
|
-
|
|
1767
|
+
if (C && C.get) {
|
|
1768
|
+
v = !0;
|
|
1367
1769
|
break;
|
|
1368
1770
|
}
|
|
1369
|
-
g = Object.getPrototypeOf(g),
|
|
1771
|
+
g = Object.getPrototypeOf(g), B++;
|
|
1370
1772
|
} catch {
|
|
1371
1773
|
break;
|
|
1372
1774
|
}
|
|
1373
1775
|
}
|
|
1374
|
-
if (!
|
|
1776
|
+
if (!v)
|
|
1375
1777
|
return m;
|
|
1376
|
-
|
|
1377
|
-
const
|
|
1378
|
-
return
|
|
1778
|
+
p.propertyAccesses++;
|
|
1779
|
+
const w = m, M = w !== null && typeof w != "object" ? w : void 0;
|
|
1780
|
+
return r.trackAccess(
|
|
1379
1781
|
s,
|
|
1380
1782
|
"class",
|
|
1381
|
-
String(
|
|
1783
|
+
String(f),
|
|
1382
1784
|
M
|
|
1383
1785
|
), m;
|
|
1384
1786
|
},
|
|
1385
|
-
has(
|
|
1386
|
-
return
|
|
1787
|
+
has(d, f) {
|
|
1788
|
+
return f in d;
|
|
1387
1789
|
},
|
|
1388
|
-
ownKeys(
|
|
1389
|
-
return Reflect.ownKeys(
|
|
1790
|
+
ownKeys(d) {
|
|
1791
|
+
return Reflect.ownKeys(d);
|
|
1390
1792
|
},
|
|
1391
|
-
getOwnPropertyDescriptor(
|
|
1392
|
-
return Reflect.getOwnPropertyDescriptor(
|
|
1793
|
+
getOwnPropertyDescriptor(d, f) {
|
|
1794
|
+
return Reflect.getOwnPropertyDescriptor(d, f);
|
|
1393
1795
|
}
|
|
1394
|
-
},
|
|
1395
|
-
return
|
|
1796
|
+
}, l = new Proxy(t, a);
|
|
1797
|
+
return n.set(s, l), p.classProxiesCreated++, p.totalProxiesCreated++, l;
|
|
1396
1798
|
}
|
|
1397
1799
|
static getProxyState(e) {
|
|
1398
|
-
return
|
|
1800
|
+
return I.createStateProxy({
|
|
1399
1801
|
target: e.state,
|
|
1400
1802
|
consumerRef: e.consumerRef,
|
|
1401
1803
|
consumerTracker: e.consumerTracker
|
|
1402
1804
|
});
|
|
1403
1805
|
}
|
|
1404
1806
|
static getProxyBlocInstance(e) {
|
|
1405
|
-
return
|
|
1807
|
+
return I.createClassProxy({
|
|
1406
1808
|
target: e.blocInstance,
|
|
1407
1809
|
consumerRef: e.consumerRef,
|
|
1408
1810
|
consumerTracker: e.consumerTracker
|
|
1409
1811
|
});
|
|
1410
1812
|
}
|
|
1411
1813
|
static getStats() {
|
|
1412
|
-
const e = Date.now() -
|
|
1814
|
+
const e = Date.now() - p.createdAt;
|
|
1413
1815
|
return {
|
|
1414
|
-
...
|
|
1415
|
-
totalProxies:
|
|
1416
|
-
cacheEfficiency:
|
|
1816
|
+
...p,
|
|
1817
|
+
totalProxies: p.stateProxiesCreated + p.classProxiesCreated,
|
|
1818
|
+
cacheEfficiency: p.cacheHits + p.cacheMisses > 0 ? `${(p.cacheHits / (p.cacheHits + p.cacheMisses) * 100).toFixed(1)}%` : "N/A",
|
|
1417
1819
|
lifetime: `${e}ms`,
|
|
1418
|
-
proxiesPerSecond: e > 0 ? (
|
|
1820
|
+
proxiesPerSecond: e > 0 ? (p.totalProxiesCreated / (e / 1e3)).toFixed(2) : "N/A"
|
|
1419
1821
|
};
|
|
1420
1822
|
}
|
|
1421
1823
|
static resetStats() {
|
|
1422
|
-
|
|
1824
|
+
p = {
|
|
1423
1825
|
stateProxiesCreated: 0,
|
|
1424
1826
|
classProxiesCreated: 0,
|
|
1425
1827
|
cacheHits: 0,
|
|
@@ -1431,7 +1833,7 @@ class b {
|
|
|
1431
1833
|
};
|
|
1432
1834
|
}
|
|
1433
1835
|
}
|
|
1434
|
-
const
|
|
1836
|
+
const b = class b {
|
|
1435
1837
|
constructor(e, t) {
|
|
1436
1838
|
i(this, "id", `consumer-${$()}`);
|
|
1437
1839
|
i(this, "blocConstructor");
|
|
@@ -1449,21 +1851,21 @@ const v = class v {
|
|
|
1449
1851
|
i(this, "hasMounted", !1);
|
|
1450
1852
|
i(this, "mountCount", 0);
|
|
1451
1853
|
i(this, "options");
|
|
1452
|
-
i(this, "createStateProxy", (e) =>
|
|
1854
|
+
i(this, "createStateProxy", (e) => I.createStateProxy({
|
|
1453
1855
|
target: e.target,
|
|
1454
1856
|
consumerRef: this.componentRef.current,
|
|
1455
1857
|
consumerTracker: this
|
|
1456
1858
|
}));
|
|
1457
|
-
i(this, "createClassProxy", (e) =>
|
|
1859
|
+
i(this, "createClassProxy", (e) => I.createClassProxy({
|
|
1458
1860
|
target: e.target,
|
|
1459
1861
|
consumerRef: this.componentRef.current,
|
|
1460
1862
|
consumerTracker: this
|
|
1461
1863
|
}));
|
|
1462
1864
|
i(this, "createSubscription", (e) => this.blocInstance._observer.subscribe({
|
|
1463
1865
|
id: this.id,
|
|
1464
|
-
fn: (s,
|
|
1465
|
-
var
|
|
1466
|
-
if (this.isUsingDependencies && ((
|
|
1866
|
+
fn: (s, r) => {
|
|
1867
|
+
var n;
|
|
1868
|
+
if (this.isUsingDependencies && ((n = this.options) != null && n.dependencies)) {
|
|
1467
1869
|
const o = this.options.dependencies(this.blocInstance);
|
|
1468
1870
|
if (!this.hasDependencyValuesChanged(
|
|
1469
1871
|
this.dependencyValues,
|
|
@@ -1471,7 +1873,7 @@ const v = class v {
|
|
|
1471
1873
|
))
|
|
1472
1874
|
return;
|
|
1473
1875
|
this.dependencyValues = o;
|
|
1474
|
-
} else if (
|
|
1876
|
+
} else if (u.config.proxyDependencyTracking) {
|
|
1475
1877
|
const o = this.consumerTracker.getConsumerInfo(
|
|
1476
1878
|
this.componentRef.current
|
|
1477
1879
|
);
|
|
@@ -1499,26 +1901,26 @@ const v = class v {
|
|
|
1499
1901
|
});
|
|
1500
1902
|
i(this, "unmount", () => {
|
|
1501
1903
|
var e;
|
|
1502
|
-
if (this.unmountTime = Date.now(), this.consumerTracker.unregister(this.componentRef.current), this.blocInstance._removeConsumer(this.id),
|
|
1904
|
+
if (this.unmountTime = Date.now(), this.consumerTracker.unregister(this.componentRef.current), this.blocInstance._removeConsumer(this.id), b.propsOwners.get(this.blocInstance) === this.id && b.propsOwners.delete(this.blocInstance), (e = this.options) != null && e.onUnmount)
|
|
1503
1905
|
try {
|
|
1504
1906
|
this.options.onUnmount(this.blocInstance);
|
|
1505
1907
|
} catch {
|
|
1506
1908
|
}
|
|
1507
1909
|
});
|
|
1508
|
-
i(this, "getProxyState", (e) => this.isUsingDependencies || !
|
|
1910
|
+
i(this, "getProxyState", (e) => this.isUsingDependencies || !u.config.proxyDependencyTracking ? e : I.getProxyState({
|
|
1509
1911
|
state: e,
|
|
1510
1912
|
consumerRef: this.componentRef.current,
|
|
1511
1913
|
consumerTracker: this
|
|
1512
1914
|
}));
|
|
1513
|
-
i(this, "getProxyBlocInstance", () => this.isUsingDependencies || !
|
|
1915
|
+
i(this, "getProxyBlocInstance", () => this.isUsingDependencies || !u.config.proxyDependencyTracking ? this.blocInstance : I.getProxyBlocInstance({
|
|
1514
1916
|
blocInstance: this.blocInstance,
|
|
1515
1917
|
consumerRef: this.componentRef.current,
|
|
1516
1918
|
consumerTracker: this
|
|
1517
1919
|
}));
|
|
1518
|
-
this.options = t, this.blocConstructor = e.blocConstructor, this.componentRef = e.componentRef, this.isUsingDependencies = !!(t != null && t.dependencies), this.consumerTracker = new
|
|
1920
|
+
this.options = t, this.blocConstructor = e.blocConstructor, this.componentRef = e.componentRef, this.isUsingDependencies = !!(t != null && t.dependencies), this.consumerTracker = new K(), this.blocInstance = this.updateBlocInstance(), this.consumerTracker.register(e.componentRef.current, this.id), this.isUsingDependencies && (t != null && t.dependencies) && (this.dependencyValues = t.dependencies(this.blocInstance)), (t == null ? void 0 : t.props) !== void 0 && this.updateProps(t.props);
|
|
1519
1921
|
}
|
|
1520
|
-
trackAccess(e, t, s,
|
|
1521
|
-
this.consumerTracker.trackAccess(e, t, s,
|
|
1922
|
+
trackAccess(e, t, s, r) {
|
|
1923
|
+
this.consumerTracker.trackAccess(e, t, s, r);
|
|
1522
1924
|
}
|
|
1523
1925
|
getConsumerDependencies(e) {
|
|
1524
1926
|
return this.consumerTracker.getDependencies(e);
|
|
@@ -1535,7 +1937,7 @@ const v = class v {
|
|
|
1535
1937
|
}
|
|
1536
1938
|
updateBlocInstance() {
|
|
1537
1939
|
var e, t;
|
|
1538
|
-
return this.blocInstance =
|
|
1940
|
+
return this.blocInstance = u.instance.getBloc(this.blocConstructor, {
|
|
1539
1941
|
props: (e = this.options) == null ? void 0 : e.props,
|
|
1540
1942
|
id: (t = this.options) == null ? void 0 : t.id,
|
|
1541
1943
|
instanceRef: this.id
|
|
@@ -1547,13 +1949,13 @@ const v = class v {
|
|
|
1547
1949
|
}
|
|
1548
1950
|
updateProps(e) {
|
|
1549
1951
|
const t = this.blocInstance;
|
|
1550
|
-
if (
|
|
1551
|
-
|
|
1952
|
+
if (b.propsOwners.has(t) || b.propsOwners.set(t, this.id), b.propsOwners.get(t) !== this.id) {
|
|
1953
|
+
u.warn(
|
|
1552
1954
|
`[BlacAdapter] Attempted to set props on ${t.constructor.name} from non-owner adapter`
|
|
1553
1955
|
);
|
|
1554
1956
|
return;
|
|
1555
1957
|
}
|
|
1556
|
-
t._disposalState ===
|
|
1958
|
+
t._disposalState === y.DISPOSED || t._disposalState === y.DISPOSING || N(this.lastProps, e) || ("add" in t && typeof t.add == "function" ? t.add(new L(e)) : "_updateProps" in t && typeof t._updateProps == "function" && t._updateProps(e), this.lastProps = e);
|
|
1557
1959
|
}
|
|
1558
1960
|
hasDependencyValuesChanged(e, t) {
|
|
1559
1961
|
if (!e || e.length !== t.length) return !0;
|
|
@@ -1564,25 +1966,27 @@ const v = class v {
|
|
|
1564
1966
|
}
|
|
1565
1967
|
};
|
|
1566
1968
|
// Props ownership tracking
|
|
1567
|
-
i(
|
|
1568
|
-
let
|
|
1969
|
+
i(b, "propsOwners", /* @__PURE__ */ new WeakMap());
|
|
1970
|
+
let D = b;
|
|
1569
1971
|
export {
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1972
|
+
u as Blac,
|
|
1973
|
+
D as BlacAdapter,
|
|
1974
|
+
H as BlacObservable,
|
|
1975
|
+
j as Bloc,
|
|
1976
|
+
k as BlocBase,
|
|
1977
|
+
y as BlocLifecycleState,
|
|
1978
|
+
V as BlocPluginRegistry,
|
|
1979
|
+
q as BlocTest,
|
|
1980
|
+
K as ConsumerTracker,
|
|
1981
|
+
z as Cubit,
|
|
1982
|
+
J as MemoryLeakDetector,
|
|
1983
|
+
F as MockBloc,
|
|
1984
|
+
G as MockCubit,
|
|
1985
|
+
L as PropsUpdated,
|
|
1986
|
+
I as ProxyFactory,
|
|
1987
|
+
U as SystemPluginRegistry,
|
|
1584
1988
|
$ as generateUUID,
|
|
1585
|
-
|
|
1586
|
-
|
|
1989
|
+
W as setBlacInstanceManager,
|
|
1990
|
+
N as shallowEqual
|
|
1587
1991
|
};
|
|
1588
1992
|
//# sourceMappingURL=index.es.js.map
|