@blac/core 2.0.0-rc-10 → 2.0.0-rc-11
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/README.md +27 -0
- package/dist/index.cjs.js +2 -2
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +40 -11
- package/dist/index.es.js +432 -364
- package/dist/index.es.js.map +1 -1
- package/package.json +1 -1
- package/src/Blac.ts +46 -7
- package/src/Bloc.ts +0 -49
- package/src/Cubit.ts +14 -0
- package/src/__tests__/Blac.config.test.ts +86 -0
- package/src/__tests__/props.test.ts +256 -0
- package/src/adapter/BlacAdapter.ts +73 -8
- package/src/events.ts +3 -0
- package/src/index.ts +2 -0
- package/src/types.ts +1 -10
- package/src/utils/shallowEqual.ts +40 -0
package/dist/index.es.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
class
|
|
1
|
+
var E = Object.defineProperty;
|
|
2
|
+
var O = (c, e, t) => e in c ? E(c, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : c[e] = t;
|
|
3
|
+
var i = (c, e, t) => O(c, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
class V {
|
|
5
5
|
/**
|
|
6
6
|
* Creates a new BlacObservable instance
|
|
7
7
|
* @param bloc - The Bloc instance to observe
|
|
8
8
|
*/
|
|
9
9
|
constructor(e) {
|
|
10
10
|
/** The Bloc instance this observable is associated with */
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
i(this, "bloc");
|
|
12
|
+
i(this, "_observers", /* @__PURE__ */ new Set());
|
|
13
13
|
this.bloc = e;
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
@@ -33,23 +33,23 @@ class E {
|
|
|
33
33
|
*/
|
|
34
34
|
subscribe(e) {
|
|
35
35
|
const t = this.bloc._disposalState;
|
|
36
|
-
return t === _.DISPOSED || t === _.DISPOSING ? (
|
|
36
|
+
return t === _.DISPOSED || t === _.DISPOSING ? (d.log(
|
|
37
37
|
"BlacObservable.subscribe: Cannot subscribe to disposed/disposing bloc.",
|
|
38
38
|
this.bloc,
|
|
39
39
|
e
|
|
40
40
|
), () => {
|
|
41
|
-
}) : (
|
|
41
|
+
}) : (d.log(
|
|
42
42
|
"BlacObservable.subscribe: Subscribing observer.",
|
|
43
43
|
this.bloc,
|
|
44
44
|
e
|
|
45
|
-
), this._observers.add(e), t === _.DISPOSAL_REQUESTED && (
|
|
45
|
+
), this._observers.add(e), t === _.DISPOSAL_REQUESTED && (d.log(
|
|
46
46
|
"BlacObservable.subscribe: Cancelling disposal due to new subscription.",
|
|
47
47
|
this.bloc
|
|
48
48
|
), this.bloc._atomicStateTransition(
|
|
49
49
|
_.DISPOSAL_REQUESTED,
|
|
50
50
|
_.ACTIVE
|
|
51
51
|
)), () => {
|
|
52
|
-
|
|
52
|
+
d.log(
|
|
53
53
|
"BlacObservable.subscribe: Unsubscribing observer.",
|
|
54
54
|
this.bloc,
|
|
55
55
|
e
|
|
@@ -61,7 +61,7 @@ class E {
|
|
|
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 && (d.log("BlacObservable.unsubscribe: No observers left.", this.bloc), this.bloc._consumers.size === 0 && !this.bloc._keepAlive && this.bloc._disposalState === _.ACTIVE && (d.log(
|
|
65
65
|
`[${this.bloc._name}:${this.bloc._id}] No observers or consumers left. Scheduling disposal.`
|
|
66
66
|
), this.bloc._scheduleDisposal()));
|
|
67
67
|
}
|
|
@@ -72,28 +72,28 @@ class E {
|
|
|
72
72
|
* @param action - Optional action that triggered the state change
|
|
73
73
|
*/
|
|
74
74
|
notify(e, t, s) {
|
|
75
|
-
this._observers.forEach((
|
|
75
|
+
this._observers.forEach((n) => {
|
|
76
76
|
let r = !1;
|
|
77
|
-
if (
|
|
78
|
-
const
|
|
77
|
+
if (n.dependencyArray) {
|
|
78
|
+
const o = n.lastState, a = n.dependencyArray(
|
|
79
79
|
e,
|
|
80
80
|
t,
|
|
81
81
|
this.bloc
|
|
82
82
|
);
|
|
83
|
-
if (!
|
|
83
|
+
if (!o)
|
|
84
84
|
r = !0;
|
|
85
|
-
else if (
|
|
85
|
+
else if (o.length !== a.length)
|
|
86
86
|
r = !0;
|
|
87
87
|
else
|
|
88
|
-
for (let
|
|
89
|
-
if (!Object.is(
|
|
88
|
+
for (let u = 0; u < a.length; u++)
|
|
89
|
+
if (!Object.is(o[u], a[u])) {
|
|
90
90
|
r = !0;
|
|
91
91
|
break;
|
|
92
92
|
}
|
|
93
|
-
|
|
93
|
+
n.lastState = a;
|
|
94
94
|
} else
|
|
95
95
|
r = !0;
|
|
96
|
-
r &&
|
|
96
|
+
r && n.fn(e, t, s);
|
|
97
97
|
});
|
|
98
98
|
}
|
|
99
99
|
/**
|
|
@@ -103,14 +103,14 @@ class E {
|
|
|
103
103
|
this._observers.clear();
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
|
-
function
|
|
107
|
-
return typeof crypto < "u" && crypto.randomUUID ? crypto.randomUUID() : "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(
|
|
106
|
+
function $() {
|
|
107
|
+
return typeof crypto < "u" && crypto.randomUUID ? crypto.randomUUID() : "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
|
108
108
|
const e = Math.random() * 16 | 0;
|
|
109
|
-
return (
|
|
109
|
+
return (c === "x" ? e : e & 3 | 8).toString(16);
|
|
110
110
|
});
|
|
111
111
|
}
|
|
112
|
-
var _ = /* @__PURE__ */ ((
|
|
113
|
-
class
|
|
112
|
+
var _ = /* @__PURE__ */ ((c) => (c.ACTIVE = "active", c.DISPOSAL_REQUESTED = "disposal_requested", c.DISPOSING = "disposing", c.DISPOSED = "disposed", c))(_ || {});
|
|
113
|
+
class x {
|
|
114
114
|
/**
|
|
115
115
|
* Creates a new BlocBase instance with the given initial state.
|
|
116
116
|
* Sets up the observer, registers with the Blac manager, and initializes addons.
|
|
@@ -118,88 +118,88 @@ class k {
|
|
|
118
118
|
* @param initialState The initial state value for this Bloc
|
|
119
119
|
*/
|
|
120
120
|
constructor(e) {
|
|
121
|
-
|
|
121
|
+
i(this, "uid", $());
|
|
122
122
|
/**
|
|
123
123
|
* Defines how dependencies are selected from the state for efficient updates.
|
|
124
124
|
* When provided, observers will only be notified when selected dependencies change.
|
|
125
125
|
*/
|
|
126
|
-
|
|
126
|
+
i(this, "defaultDependencySelector");
|
|
127
127
|
/**
|
|
128
128
|
* @internal
|
|
129
129
|
* Indicates if this specific Bloc instance is isolated from others of the same type.
|
|
130
130
|
*/
|
|
131
|
-
|
|
131
|
+
i(this, "_isolated", !1);
|
|
132
132
|
/**
|
|
133
133
|
* @internal
|
|
134
134
|
* Observable responsible for managing state listeners and notifying consumers.
|
|
135
135
|
*/
|
|
136
|
-
|
|
136
|
+
i(this, "_observer");
|
|
137
137
|
/**
|
|
138
138
|
* The unique identifier for this Bloc instance.
|
|
139
139
|
* Defaults to the class name, but can be customized.
|
|
140
140
|
*/
|
|
141
|
-
|
|
141
|
+
i(this, "_id");
|
|
142
142
|
/**
|
|
143
143
|
* @internal
|
|
144
144
|
* Reference string used internally for tracking and debugging.
|
|
145
145
|
*/
|
|
146
|
-
|
|
146
|
+
i(this, "_instanceRef");
|
|
147
147
|
/**
|
|
148
148
|
* @internal
|
|
149
149
|
* Indicates if this specific Bloc instance should be kept alive when no consumers are present.
|
|
150
150
|
*/
|
|
151
|
-
|
|
151
|
+
i(this, "_keepAlive", !1);
|
|
152
152
|
/**
|
|
153
153
|
* @readonly
|
|
154
154
|
* Timestamp when this Bloc instance was created, useful for debugging and performance tracking.
|
|
155
155
|
*/
|
|
156
|
-
|
|
156
|
+
i(this, "_createdAt", Date.now());
|
|
157
157
|
/**
|
|
158
158
|
* @internal
|
|
159
159
|
* Atomic disposal state to prevent race conditions
|
|
160
160
|
*/
|
|
161
|
-
|
|
161
|
+
i(this, "_disposalState", "active");
|
|
162
162
|
/**
|
|
163
163
|
* @internal
|
|
164
164
|
* Timestamp when disposal was requested (for React Strict Mode grace period)
|
|
165
165
|
*/
|
|
166
|
-
|
|
166
|
+
i(this, "_disposalRequestTime", 0);
|
|
167
167
|
/**
|
|
168
168
|
* @internal
|
|
169
169
|
* The current state of the Bloc.
|
|
170
170
|
*/
|
|
171
|
-
|
|
171
|
+
i(this, "_state");
|
|
172
172
|
/**
|
|
173
173
|
* @internal
|
|
174
174
|
* The previous state of the Bloc, maintained for comparison and history.
|
|
175
175
|
*/
|
|
176
|
-
|
|
176
|
+
i(this, "_oldState");
|
|
177
177
|
/**
|
|
178
178
|
* Props passed during Bloc instance creation.
|
|
179
179
|
* Can be used to configure or parameterize the Bloc's behavior.
|
|
180
180
|
*/
|
|
181
|
-
|
|
181
|
+
i(this, "props", null);
|
|
182
182
|
/**
|
|
183
183
|
* @internal
|
|
184
184
|
* Flag to prevent batching race conditions
|
|
185
185
|
*/
|
|
186
|
-
|
|
186
|
+
i(this, "_batchingLock", !1);
|
|
187
187
|
/**
|
|
188
188
|
* @internal
|
|
189
189
|
* Pending batched updates
|
|
190
190
|
*/
|
|
191
|
-
|
|
191
|
+
i(this, "_pendingUpdates", []);
|
|
192
192
|
/**
|
|
193
193
|
* @internal
|
|
194
194
|
* Map of consumer IDs to their WeakRef objects for proper cleanup
|
|
195
195
|
*/
|
|
196
|
-
|
|
196
|
+
i(this, "_consumerRefs", /* @__PURE__ */ new Map());
|
|
197
197
|
/**
|
|
198
198
|
* @internal
|
|
199
199
|
* Validates that all consumer references are still alive
|
|
200
200
|
* Removes dead consumers automatically
|
|
201
201
|
*/
|
|
202
|
-
|
|
202
|
+
i(this, "_validateConsumers", () => {
|
|
203
203
|
const e = [];
|
|
204
204
|
for (const [t, s] of this._consumerRefs)
|
|
205
205
|
s.deref() === void 0 && e.push(t);
|
|
@@ -214,7 +214,7 @@ class k {
|
|
|
214
214
|
*
|
|
215
215
|
* @param id The new ID to assign to this Bloc instance
|
|
216
216
|
*/
|
|
217
|
-
|
|
217
|
+
i(this, "_updateId", (e) => {
|
|
218
218
|
const t = this._id;
|
|
219
219
|
!e || e === t || (this._id = e);
|
|
220
220
|
});
|
|
@@ -222,12 +222,12 @@ class k {
|
|
|
222
222
|
* @internal
|
|
223
223
|
* Optional function to be called when the Bloc is disposed.
|
|
224
224
|
*/
|
|
225
|
-
|
|
225
|
+
i(this, "onDispose");
|
|
226
226
|
/**
|
|
227
227
|
* @internal
|
|
228
228
|
* Set of consumer IDs currently listening to this Bloc's state changes.
|
|
229
229
|
*/
|
|
230
|
-
|
|
230
|
+
i(this, "_consumers", /* @__PURE__ */ new Set());
|
|
231
231
|
/**
|
|
232
232
|
* @internal
|
|
233
233
|
* Registers a new consumer to this Bloc instance.
|
|
@@ -236,7 +236,7 @@ class k {
|
|
|
236
236
|
* @param consumerId The unique ID of the consumer being added
|
|
237
237
|
* @param consumerRef Optional reference to the consumer object for cleanup validation
|
|
238
238
|
*/
|
|
239
|
-
|
|
239
|
+
i(this, "_addConsumer", (e, t) => {
|
|
240
240
|
var s;
|
|
241
241
|
return this._disposalState !== "active" ? !1 : (this._consumers.has(e) || (this._consumers.add(e), t && this._consumerRefs.set(e, new WeakRef(t)), (s = globalThis.Blac) == null || s.log(
|
|
242
242
|
`[${this._name}:${this._id}] Consumer added. Total consumers: ${this._consumers.size}`
|
|
@@ -249,7 +249,7 @@ class k {
|
|
|
249
249
|
*
|
|
250
250
|
* @param consumerId The unique ID of the consumer being removed
|
|
251
251
|
*/
|
|
252
|
-
|
|
252
|
+
i(this, "_removeConsumer", (e) => {
|
|
253
253
|
var t, s;
|
|
254
254
|
this._consumers.has(e) && (this._consumers.delete(e), this._consumerRefs.delete(e), (t = globalThis.Blac) == null || t.log(
|
|
255
255
|
`[${this._name}:${this._id}] Consumer removed. Remaining consumers: ${this._consumers.size}, keepAlive: ${this._keepAlive}`
|
|
@@ -261,13 +261,13 @@ class k {
|
|
|
261
261
|
* @internal
|
|
262
262
|
* Handler function for disposal (can be set by Blac manager)
|
|
263
263
|
*/
|
|
264
|
-
|
|
265
|
-
|
|
264
|
+
i(this, "_disposalHandler");
|
|
265
|
+
i(this, "lastUpdate", Date.now());
|
|
266
266
|
/**
|
|
267
267
|
* @internal
|
|
268
268
|
* Flag to indicate if batching is enabled for this bloc
|
|
269
269
|
*/
|
|
270
|
-
|
|
270
|
+
i(this, "_batchingEnabled", !1);
|
|
271
271
|
/**
|
|
272
272
|
* @internal
|
|
273
273
|
* Updates the state and notifies all observers of the change.
|
|
@@ -276,7 +276,7 @@ class k {
|
|
|
276
276
|
* @param oldState The previous state for comparison
|
|
277
277
|
* @param action Optional metadata about what caused the state change
|
|
278
278
|
*/
|
|
279
|
-
|
|
279
|
+
i(this, "_pushState", (e, t, s) => {
|
|
280
280
|
if (e !== void 0 && !(s !== void 0 && typeof s != "object" && typeof s != "function")) {
|
|
281
281
|
if (this._batchingEnabled) {
|
|
282
282
|
this._pendingUpdates.push({ newState: e, oldState: t, action: s }), this._oldState = t, this._state = e;
|
|
@@ -289,7 +289,7 @@ class k {
|
|
|
289
289
|
* Enables batching for multiple state updates
|
|
290
290
|
* @param batchFn Function to execute with batching enabled
|
|
291
291
|
*/
|
|
292
|
-
|
|
292
|
+
i(this, "batch", (e) => {
|
|
293
293
|
if (this._batchingLock)
|
|
294
294
|
return e();
|
|
295
295
|
this._batchingLock = !0, this._batchingEnabled = !0, this._pendingUpdates = [];
|
|
@@ -308,7 +308,7 @@ class k {
|
|
|
308
308
|
this._batchingEnabled = !1, this._batchingLock = !1, this._pendingUpdates = [];
|
|
309
309
|
}
|
|
310
310
|
});
|
|
311
|
-
this._state = e, this._observer = new
|
|
311
|
+
this._state = e, this._observer = new V(this), this._id = this.constructor.name;
|
|
312
312
|
const t = this.constructor;
|
|
313
313
|
this._keepAlive = typeof t.keepAlive == "boolean" ? t.keepAlive : !1, this._isolated = typeof t.isolated == "boolean" ? t.isolated : !1;
|
|
314
314
|
}
|
|
@@ -348,18 +348,18 @@ class k {
|
|
|
348
348
|
* @returns Result indicating success/failure and state information
|
|
349
349
|
*/
|
|
350
350
|
_atomicStateTransition(e, t) {
|
|
351
|
-
var s,
|
|
351
|
+
var s, n, r, o;
|
|
352
352
|
if (this._disposalState === e) {
|
|
353
|
-
const
|
|
354
|
-
return this._disposalState = t, (s = globalThis.Blac) != null && s.enableLog && ((
|
|
355
|
-
`[${this._name}:${this._id}] State transition: ${
|
|
353
|
+
const a = this._disposalState;
|
|
354
|
+
return this._disposalState = t, (s = globalThis.Blac) != null && s.enableLog && ((n = globalThis.Blac) == null || n.log(
|
|
355
|
+
`[${this._name}:${this._id}] State transition: ${a} -> ${t} (SUCCESS)`
|
|
356
356
|
)), {
|
|
357
357
|
success: !0,
|
|
358
358
|
currentState: t,
|
|
359
|
-
previousState:
|
|
359
|
+
previousState: a
|
|
360
360
|
};
|
|
361
361
|
}
|
|
362
|
-
return (r = globalThis.Blac) != null && r.enableLog && ((
|
|
362
|
+
return (r = globalThis.Blac) != null && r.enableLog && ((o = globalThis.Blac) == null || o.log(
|
|
363
363
|
`[${this._name}:${this._id}] State transition failed: expected ${e}, current ${this._disposalState}`
|
|
364
364
|
)), {
|
|
365
365
|
success: !1,
|
|
@@ -436,101 +436,101 @@ class k {
|
|
|
436
436
|
* Use this when state should not be shared between components.
|
|
437
437
|
* @default false
|
|
438
438
|
*/
|
|
439
|
-
|
|
439
|
+
i(x, "isolated", !1), /**
|
|
440
440
|
* When true, the Bloc instance persists even when there are no active consumers.
|
|
441
441
|
* Useful for maintaining state between component unmount/remount cycles.
|
|
442
442
|
* @default false
|
|
443
443
|
*/
|
|
444
|
-
|
|
445
|
-
const
|
|
444
|
+
i(x, "keepAlive", !1);
|
|
445
|
+
const y = class y {
|
|
446
446
|
getInstance() {
|
|
447
|
-
return
|
|
447
|
+
return y._instance || (y._instance = new d({
|
|
448
448
|
__unsafe_ignore_singleton: !0
|
|
449
|
-
})),
|
|
449
|
+
})), y._instance;
|
|
450
450
|
}
|
|
451
451
|
setInstance(e) {
|
|
452
|
-
|
|
452
|
+
y._instance = e;
|
|
453
453
|
}
|
|
454
454
|
resetInstance() {
|
|
455
|
-
const e =
|
|
456
|
-
if (
|
|
455
|
+
const e = y._instance;
|
|
456
|
+
if (y._instance = new d({
|
|
457
457
|
__unsafe_ignore_singleton: !0
|
|
458
458
|
}), e)
|
|
459
459
|
for (const t of e.keepAliveBlocs)
|
|
460
|
-
|
|
460
|
+
y._instance.keepAliveBlocs.add(t), y._instance.uidRegistry.set(t.uid, t);
|
|
461
461
|
}
|
|
462
462
|
};
|
|
463
|
-
|
|
464
|
-
let
|
|
465
|
-
function
|
|
466
|
-
|
|
463
|
+
i(y, "_instance");
|
|
464
|
+
let C = y, S = new C();
|
|
465
|
+
function q(c) {
|
|
466
|
+
S = c;
|
|
467
467
|
}
|
|
468
|
-
const
|
|
468
|
+
const l = class l {
|
|
469
469
|
/**
|
|
470
470
|
* Creates a new Blac instance.
|
|
471
471
|
* @param options - Configuration options including singleton control
|
|
472
472
|
*/
|
|
473
473
|
constructor(e = {}) {
|
|
474
474
|
/** Timestamp when the instance was created */
|
|
475
|
-
|
|
475
|
+
i(this, "createdAt", Date.now());
|
|
476
476
|
/** Map storing all registered bloc instances by their class name and ID */
|
|
477
|
-
|
|
477
|
+
i(this, "blocInstanceMap", /* @__PURE__ */ new Map());
|
|
478
478
|
/** Map storing isolated bloc instances grouped by their constructor */
|
|
479
479
|
// Using BlocConstructor<BlocBase<unknown>> would break type inference when storing
|
|
480
480
|
// different bloc types in the same map. The 'any' allows proper polymorphic storage
|
|
481
481
|
// while maintaining type safety at usage sites through the BlocConstructor constraint.
|
|
482
|
-
|
|
482
|
+
i(this, "isolatedBlocMap", /* @__PURE__ */ new Map());
|
|
483
483
|
/** Map for O(1) lookup of isolated blocs by UID */
|
|
484
|
-
|
|
484
|
+
i(this, "isolatedBlocIndex", /* @__PURE__ */ new Map());
|
|
485
485
|
/** Map tracking UIDs to prevent memory leaks */
|
|
486
|
-
|
|
486
|
+
i(this, "uidRegistry", /* @__PURE__ */ new Map());
|
|
487
487
|
/** Set of keep-alive blocs for controlled cleanup */
|
|
488
|
-
|
|
488
|
+
i(this, "keepAliveBlocs", /* @__PURE__ */ new Set());
|
|
489
489
|
/** Flag to control whether changes should be posted to document */
|
|
490
|
-
|
|
490
|
+
i(this, "postChangesToDocument", !1);
|
|
491
491
|
/**
|
|
492
492
|
* Logs messages to console when logging is enabled
|
|
493
493
|
* @param args - Arguments to log
|
|
494
494
|
*/
|
|
495
|
-
|
|
496
|
-
|
|
495
|
+
i(this, "log", (...e) => {
|
|
496
|
+
l.logSpy && l.logSpy(e), l.enableLog && l.logLevel, l.enableLog && l.logLevel;
|
|
497
497
|
});
|
|
498
498
|
/**
|
|
499
499
|
* Logs a warning message
|
|
500
500
|
* @param message - Warning message
|
|
501
501
|
* @param args - Additional arguments
|
|
502
502
|
*/
|
|
503
|
-
|
|
504
|
-
|
|
503
|
+
i(this, "warn", (e, ...t) => {
|
|
504
|
+
l.enableLog;
|
|
505
505
|
});
|
|
506
506
|
/**
|
|
507
507
|
* Logs an error message
|
|
508
508
|
* @param message - Error message
|
|
509
509
|
* @param args - Additional arguments
|
|
510
510
|
*/
|
|
511
|
-
|
|
512
|
-
|
|
511
|
+
i(this, "error", (e, ...t) => {
|
|
512
|
+
l.enableLog;
|
|
513
513
|
});
|
|
514
514
|
/**
|
|
515
515
|
* Resets the Blac instance to a new one, disposing non-keepAlive blocs
|
|
516
516
|
* from the old instance.
|
|
517
517
|
*/
|
|
518
|
-
|
|
518
|
+
i(this, "resetInstance", () => {
|
|
519
519
|
this.log("Reset Blac instance");
|
|
520
520
|
const e = new Map(this.blocInstanceMap), t = new Map(this.isolatedBlocMap);
|
|
521
521
|
e.forEach((s) => {
|
|
522
522
|
!s._keepAlive && s._disposalState === _.ACTIVE && this.disposeBloc(s);
|
|
523
523
|
}), t.forEach((s) => {
|
|
524
|
-
s.forEach((
|
|
525
|
-
!
|
|
524
|
+
s.forEach((n) => {
|
|
525
|
+
!n._keepAlive && n._disposalState === _.ACTIVE && this.disposeBloc(n);
|
|
526
526
|
});
|
|
527
|
-
}), this.blocInstanceMap.clear(), this.isolatedBlocMap.clear(), this.isolatedBlocIndex.clear(),
|
|
527
|
+
}), this.blocInstanceMap.clear(), this.isolatedBlocMap.clear(), this.isolatedBlocIndex.clear(), S.resetInstance();
|
|
528
528
|
});
|
|
529
529
|
/**
|
|
530
530
|
* Disposes of a bloc instance by removing it from the appropriate registry
|
|
531
531
|
* @param bloc - The bloc instance to dispose
|
|
532
532
|
*/
|
|
533
|
-
|
|
533
|
+
i(this, "disposeBloc", (e) => {
|
|
534
534
|
const t = e._disposalState;
|
|
535
535
|
if (![
|
|
536
536
|
_.ACTIVE,
|
|
@@ -541,12 +541,12 @@ const c = class c {
|
|
|
541
541
|
);
|
|
542
542
|
return;
|
|
543
543
|
}
|
|
544
|
-
const
|
|
544
|
+
const n = e.constructor, r = this.createBlocInstanceMapKey(e._name, e._id);
|
|
545
545
|
this.log(
|
|
546
|
-
`[${e._name}:${String(e._id)}] disposeBloc called. Isolated: ${String(
|
|
547
|
-
), e._dispose(),
|
|
546
|
+
`[${e._name}:${String(e._id)}] disposeBloc called. Isolated: ${String(n.isolated)}`
|
|
547
|
+
), e._dispose(), n.isolated ? (this.unregisterIsolatedBlocInstance(e), this.blocInstanceMap.delete(r)) : this.unregisterBlocInstance(e), this.log("dispatched bloc", e);
|
|
548
548
|
});
|
|
549
|
-
|
|
549
|
+
i(this, "activateBloc", (e) => {
|
|
550
550
|
if (e._disposalState !== _.ACTIVE) {
|
|
551
551
|
this.log(
|
|
552
552
|
`[${e._name}:${String(e._id)}] activateBloc called on disposed bloc. Ignoring.`
|
|
@@ -569,41 +569,41 @@ const c = class c {
|
|
|
569
569
|
* - instanceRef: Optional reference string for the instance
|
|
570
570
|
* @returns The bloc instance
|
|
571
571
|
*/
|
|
572
|
-
|
|
573
|
-
const { id: s, forceNewInstance:
|
|
574
|
-
if (this.log(`[${e.name}:${String(
|
|
572
|
+
i(this, "getBloc", (e, t = {}) => {
|
|
573
|
+
const { id: s, forceNewInstance: n } = t, r = e, o = s ?? e.name;
|
|
574
|
+
if (this.log(`[${e.name}:${String(o)}] (getBloc) Called:`, {
|
|
575
575
|
options: t,
|
|
576
576
|
base: r
|
|
577
|
-
}), !
|
|
577
|
+
}), !n)
|
|
578
578
|
if (r.isolated) {
|
|
579
|
-
const
|
|
579
|
+
const u = this.findIsolatedBlocInstance(
|
|
580
580
|
e,
|
|
581
|
-
t.instanceRef ??
|
|
581
|
+
t.instanceRef ?? o
|
|
582
582
|
);
|
|
583
|
-
if (
|
|
584
|
-
return
|
|
583
|
+
if (u)
|
|
584
|
+
return u;
|
|
585
585
|
if (t.throwIfNotFound)
|
|
586
586
|
throw new Error(`Isolated bloc ${e.name} not found`);
|
|
587
587
|
} else {
|
|
588
|
-
const
|
|
588
|
+
const u = this.findRegisteredBlocInstance(
|
|
589
589
|
e,
|
|
590
|
-
|
|
590
|
+
o
|
|
591
591
|
);
|
|
592
|
-
if (
|
|
593
|
-
return
|
|
592
|
+
if (u)
|
|
593
|
+
return u;
|
|
594
594
|
if (t.throwIfNotFound)
|
|
595
595
|
throw new Error(`Registered bloc ${e.name} not found`);
|
|
596
596
|
}
|
|
597
|
-
const
|
|
597
|
+
const a = this.createNewBlocInstance(e, o, t);
|
|
598
598
|
if (this.log(
|
|
599
|
-
`[${e.name}:${String(
|
|
599
|
+
`[${e.name}:${String(o)}] (getBloc) No existing instance found. Creating new one.`,
|
|
600
600
|
t,
|
|
601
|
-
|
|
602
|
-
), !
|
|
601
|
+
a
|
|
602
|
+
), !a)
|
|
603
603
|
throw new Error(
|
|
604
604
|
`[getBloc] Failed to create bloc instance for ${e.name}. This should never happen.`
|
|
605
605
|
);
|
|
606
|
-
return
|
|
606
|
+
return a;
|
|
607
607
|
});
|
|
608
608
|
/**
|
|
609
609
|
* Gets a bloc instance or throws an error if it doesn't exist
|
|
@@ -613,8 +613,8 @@ const c = class c {
|
|
|
613
613
|
* - props: Properties to pass to the bloc constructor
|
|
614
614
|
* - instanceRef: Optional reference string for the instance
|
|
615
615
|
*/
|
|
616
|
-
|
|
617
|
-
const s = e.isolated,
|
|
616
|
+
i(this, "getBlocOrThrow", (e, t = {}) => {
|
|
617
|
+
const s = e.isolated, n = t.id || e.name, r = s ? this.findIsolatedBlocInstance(e, n) : this.findRegisteredBlocInstance(e, n);
|
|
618
618
|
if (r)
|
|
619
619
|
return r;
|
|
620
620
|
throw new Error(`Bloc ${e.name} not found`);
|
|
@@ -626,13 +626,13 @@ const c = class c {
|
|
|
626
626
|
* - searchIsolated: Whether to search in isolated blocs (defaults to bloc's isolated property)
|
|
627
627
|
* @returns Array of matching bloc instances
|
|
628
628
|
*/
|
|
629
|
-
|
|
629
|
+
i(this, "getAllBlocs", (e, t = {}) => {
|
|
630
630
|
const s = [];
|
|
631
|
-
if (this.blocInstanceMap.forEach((
|
|
632
|
-
|
|
631
|
+
if (this.blocInstanceMap.forEach((n) => {
|
|
632
|
+
n.constructor === e && s.push(n);
|
|
633
633
|
}), t.searchIsolated !== !1) {
|
|
634
|
-
const
|
|
635
|
-
|
|
634
|
+
const n = this.isolatedBlocMap.get(e);
|
|
635
|
+
n && s.push(...n.map((r) => r));
|
|
636
636
|
}
|
|
637
637
|
return s;
|
|
638
638
|
});
|
|
@@ -640,7 +640,7 @@ const c = class c {
|
|
|
640
640
|
* Disposes all keep-alive blocs of a specific type
|
|
641
641
|
* @param blocClass - The bloc class to dispose
|
|
642
642
|
*/
|
|
643
|
-
|
|
643
|
+
i(this, "disposeKeepAliveBlocs", (e) => {
|
|
644
644
|
const t = [];
|
|
645
645
|
for (const s of this.keepAliveBlocs)
|
|
646
646
|
(!e || s.constructor === e) && t.push(s);
|
|
@@ -650,19 +650,19 @@ const c = class c {
|
|
|
650
650
|
* Disposes all blocs matching a pattern
|
|
651
651
|
* @param predicate - Function to test each bloc for disposal
|
|
652
652
|
*/
|
|
653
|
-
|
|
653
|
+
i(this, "disposeBlocs", (e) => {
|
|
654
654
|
const t = [];
|
|
655
655
|
for (const s of this.blocInstanceMap.values())
|
|
656
656
|
e(s) && t.push(s);
|
|
657
657
|
for (const s of this.isolatedBlocMap.values())
|
|
658
|
-
for (const
|
|
659
|
-
e(
|
|
658
|
+
for (const n of s)
|
|
659
|
+
e(n) && t.push(n);
|
|
660
660
|
t.forEach((s) => s._dispose());
|
|
661
661
|
});
|
|
662
662
|
/**
|
|
663
663
|
* Gets memory usage statistics for debugging
|
|
664
664
|
*/
|
|
665
|
-
|
|
665
|
+
i(this, "getMemoryStats", () => ({
|
|
666
666
|
totalBlocs: this.uidRegistry.size,
|
|
667
667
|
registeredBlocs: this.blocInstanceMap.size,
|
|
668
668
|
isolatedBlocs: Array.from(this.isolatedBlocMap.values()).reduce(
|
|
@@ -675,7 +675,7 @@ const c = class c {
|
|
|
675
675
|
/**
|
|
676
676
|
* Validates consumer references and cleans up orphaned consumers
|
|
677
677
|
*/
|
|
678
|
-
|
|
678
|
+
i(this, "validateConsumers", () => {
|
|
679
679
|
for (const e of this.uidRegistry.values())
|
|
680
680
|
e._validateConsumers(), e._consumers.size === 0 && !e._keepAlive && e._disposalState === _.ACTIVE && setTimeout(() => {
|
|
681
681
|
e._consumers.size === 0 && !e._keepAlive && e._disposalState === _.ACTIVE && this.disposeBloc(e);
|
|
@@ -683,33 +683,52 @@ const c = class c {
|
|
|
683
683
|
});
|
|
684
684
|
const { __unsafe_ignore_singleton: t = !1 } = e;
|
|
685
685
|
if (!t)
|
|
686
|
-
return
|
|
687
|
-
|
|
686
|
+
return l.instance;
|
|
687
|
+
S.setInstance(this);
|
|
688
688
|
}
|
|
689
689
|
static get instance() {
|
|
690
|
-
return
|
|
690
|
+
return S.getInstance();
|
|
691
691
|
}
|
|
692
692
|
static get getAllBlocs() {
|
|
693
|
-
return
|
|
693
|
+
return l.instance.getAllBlocs;
|
|
694
|
+
}
|
|
695
|
+
/** Get current configuration */
|
|
696
|
+
static get config() {
|
|
697
|
+
return { ...this._config };
|
|
698
|
+
}
|
|
699
|
+
/**
|
|
700
|
+
* Set or update Blac configuration
|
|
701
|
+
* @param config - Partial configuration to merge with existing config
|
|
702
|
+
* @throws Error if configuration is invalid
|
|
703
|
+
*/
|
|
704
|
+
static setConfig(e) {
|
|
705
|
+
if (e.proxyDependencyTracking !== void 0 && typeof e.proxyDependencyTracking != "boolean")
|
|
706
|
+
throw new Error("BlacConfig.proxyDependencyTracking must be a boolean");
|
|
707
|
+
if (e.exposeBlacInstance !== void 0 && typeof e.exposeBlacInstance != "boolean")
|
|
708
|
+
throw new Error("BlacConfig.exposeBlacInstance must be a boolean");
|
|
709
|
+
this._config = {
|
|
710
|
+
...this._config,
|
|
711
|
+
...e
|
|
712
|
+
}, this.enableLog && this.instance.log("Blac config updated:", this._config);
|
|
694
713
|
}
|
|
695
714
|
static get log() {
|
|
696
|
-
return
|
|
715
|
+
return l.instance.log;
|
|
697
716
|
}
|
|
698
717
|
/**
|
|
699
718
|
* Gets the current Blac instance
|
|
700
719
|
* @returns The Blac instance
|
|
701
720
|
*/
|
|
702
721
|
static getInstance() {
|
|
703
|
-
return
|
|
722
|
+
return S.getInstance();
|
|
704
723
|
}
|
|
705
724
|
static get warn() {
|
|
706
|
-
return
|
|
725
|
+
return l.instance.warn;
|
|
707
726
|
}
|
|
708
727
|
static get error() {
|
|
709
|
-
return
|
|
728
|
+
return l.instance.error;
|
|
710
729
|
}
|
|
711
730
|
static get disposeBloc() {
|
|
712
|
-
return
|
|
731
|
+
return l.instance.disposeBloc;
|
|
713
732
|
}
|
|
714
733
|
/**
|
|
715
734
|
* Creates a unique key for a bloc instance in the map based on the bloc class name and instance ID
|
|
@@ -744,8 +763,8 @@ const c = class c {
|
|
|
744
763
|
*/
|
|
745
764
|
findRegisteredBlocInstance(e, t) {
|
|
746
765
|
if (e.isolated) return;
|
|
747
|
-
const
|
|
748
|
-
return this.blocInstanceMap.get(
|
|
766
|
+
const n = this.createBlocInstanceMapKey(e.name, t);
|
|
767
|
+
return this.blocInstanceMap.get(n);
|
|
749
768
|
}
|
|
750
769
|
/**
|
|
751
770
|
* Registers an isolated bloc instance in the isolated registry
|
|
@@ -761,14 +780,14 @@ const c = class c {
|
|
|
761
780
|
*/
|
|
762
781
|
unregisterIsolatedBlocInstance(e) {
|
|
763
782
|
const t = e.constructor, s = this.isolatedBlocMap.get(t);
|
|
764
|
-
let
|
|
783
|
+
let n = !1;
|
|
765
784
|
if (s) {
|
|
766
|
-
const
|
|
767
|
-
|
|
785
|
+
const o = s.findIndex((a) => a.uid === e.uid);
|
|
786
|
+
o !== -1 && (s.splice(o, 1), n = !0), s.length === 0 && this.isolatedBlocMap.delete(t);
|
|
768
787
|
}
|
|
769
788
|
const r = this.isolatedBlocIndex.delete(e.uid);
|
|
770
|
-
this.uidRegistry.delete(e.uid), this.keepAliveBlocs.delete(e),
|
|
771
|
-
`[Blac] Inconsistent state detected during isolated bloc cleanup for ${e._name}:${e.uid}. Map removal: ${
|
|
789
|
+
this.uidRegistry.delete(e.uid), this.keepAliveBlocs.delete(e), n !== r && this.warn(
|
|
790
|
+
`[Blac] Inconsistent state detected during isolated bloc cleanup for ${e._name}:${e.uid}. Map removal: ${n}, Index removal: ${r}`
|
|
772
791
|
);
|
|
773
792
|
}
|
|
774
793
|
/**
|
|
@@ -776,8 +795,8 @@ const c = class c {
|
|
|
776
795
|
*/
|
|
777
796
|
findIsolatedBlocInstance(e, t) {
|
|
778
797
|
if (!e.isolated) return;
|
|
779
|
-
const
|
|
780
|
-
return
|
|
798
|
+
const n = this.isolatedBlocMap.get(e);
|
|
799
|
+
return n ? n.find((o) => o._id === t) : void 0;
|
|
781
800
|
}
|
|
782
801
|
/**
|
|
783
802
|
* Finds an isolated bloc instance by UID (O(1) lookup)
|
|
@@ -794,59 +813,60 @@ const c = class c {
|
|
|
794
813
|
* @returns The newly created bloc instance
|
|
795
814
|
*/
|
|
796
815
|
createNewBlocInstance(e, t, s = {}) {
|
|
797
|
-
const { props:
|
|
798
|
-
return
|
|
816
|
+
const { props: n, instanceRef: r } = s, o = new e(n);
|
|
817
|
+
return o._instanceRef = r, o.props = n || null, o._updateId(t), o._setDisposalHandler((a) => this.disposeBloc(a)), o.isIsolated ? (this.registerIsolatedBlocInstance(o), o) : (this.registerBlocInstance(o), o);
|
|
799
818
|
}
|
|
800
819
|
static get activateBloc() {
|
|
801
|
-
return
|
|
820
|
+
return l.instance.activateBloc;
|
|
802
821
|
}
|
|
803
822
|
static get getBloc() {
|
|
804
|
-
return
|
|
823
|
+
return l.instance.getBloc;
|
|
805
824
|
}
|
|
806
825
|
static get getBlocOrThrow() {
|
|
807
|
-
return
|
|
826
|
+
return l.instance.getBlocOrThrow;
|
|
808
827
|
}
|
|
809
828
|
static get disposeKeepAliveBlocs() {
|
|
810
|
-
return
|
|
829
|
+
return l.instance.disposeKeepAliveBlocs;
|
|
811
830
|
}
|
|
812
831
|
static get disposeBlocs() {
|
|
813
|
-
return
|
|
832
|
+
return l.instance.disposeBlocs;
|
|
814
833
|
}
|
|
815
834
|
static get getMemoryStats() {
|
|
816
|
-
return
|
|
835
|
+
return l.instance.getMemoryStats;
|
|
817
836
|
}
|
|
818
837
|
static get validateConsumers() {
|
|
819
|
-
return
|
|
838
|
+
return l.instance.validateConsumers;
|
|
820
839
|
}
|
|
821
840
|
};
|
|
822
|
-
/**
|
|
823
|
-
|
|
824
|
-
|
|
841
|
+
/** Private static configuration */
|
|
842
|
+
i(l, "_config", {
|
|
843
|
+
exposeBlacInstance: !1,
|
|
844
|
+
proxyDependencyTracking: !0
|
|
845
|
+
}), /** Flag to enable/disable logging */
|
|
846
|
+
i(l, "enableLog", !1), i(l, "logLevel", "warn"), i(l, "logSpy", null), i(l, "resetInstance", () => {
|
|
847
|
+
S.resetInstance();
|
|
825
848
|
});
|
|
826
|
-
let
|
|
827
|
-
class
|
|
849
|
+
let d = l;
|
|
850
|
+
class U extends x {
|
|
828
851
|
constructor() {
|
|
829
852
|
super(...arguments);
|
|
830
|
-
|
|
831
|
-
// The handler's event parameter will be correctly typed to the specific EventConstructor
|
|
832
|
-
// by the 'on' method's signature.
|
|
833
|
-
n(this, "eventHandlers", /* @__PURE__ */ new Map());
|
|
853
|
+
i(this, "eventHandlers", /* @__PURE__ */ new Map());
|
|
834
854
|
/**
|
|
835
855
|
* @internal
|
|
836
856
|
* Event queue to ensure sequential processing of async events
|
|
837
857
|
*/
|
|
838
|
-
|
|
858
|
+
i(this, "_eventQueue", []);
|
|
839
859
|
/**
|
|
840
860
|
* @internal
|
|
841
861
|
* Flag indicating if an event is currently being processed
|
|
842
862
|
*/
|
|
843
|
-
|
|
863
|
+
i(this, "_isProcessingEvent", !1);
|
|
844
864
|
/**
|
|
845
865
|
* Dispatches an action/event to the Bloc.
|
|
846
866
|
* Events are queued and processed sequentially to prevent race conditions.
|
|
847
867
|
* @param action The action/event instance to be processed.
|
|
848
868
|
*/
|
|
849
|
-
|
|
869
|
+
i(this, "add", async (t) => {
|
|
850
870
|
this._eventQueue.push(t), this._isProcessingEvent || await this._processEventQueue();
|
|
851
871
|
});
|
|
852
872
|
}
|
|
@@ -858,7 +878,7 @@ class O extends k {
|
|
|
858
878
|
* The 'event' parameter in the handler will be typed to the specific eventConstructor.
|
|
859
879
|
*/
|
|
860
880
|
on(t, s) {
|
|
861
|
-
this.eventHandlers.has(t) &&
|
|
881
|
+
this.eventHandlers.has(t) && d.warn(
|
|
862
882
|
`[Bloc ${this._name}:${String(this._id)}] Handler for event '${t.name}' already registered. It will be overwritten.`
|
|
863
883
|
), this.eventHandlers.set(
|
|
864
884
|
t,
|
|
@@ -887,44 +907,53 @@ class O extends k {
|
|
|
887
907
|
* Processes a single event
|
|
888
908
|
*/
|
|
889
909
|
async _processEvent(t) {
|
|
890
|
-
const s = t.constructor,
|
|
891
|
-
if (
|
|
892
|
-
const r = (
|
|
893
|
-
const
|
|
894
|
-
this._pushState(
|
|
910
|
+
const s = t.constructor, n = this.eventHandlers.get(s);
|
|
911
|
+
if (n) {
|
|
912
|
+
const r = (o) => {
|
|
913
|
+
const a = this.state;
|
|
914
|
+
this._pushState(o, a, t);
|
|
895
915
|
};
|
|
896
916
|
try {
|
|
897
|
-
await
|
|
898
|
-
} catch (
|
|
899
|
-
const
|
|
917
|
+
await n(t, r);
|
|
918
|
+
} catch (o) {
|
|
919
|
+
const a = t.constructor.name || "UnnamedConstructor", u = {
|
|
900
920
|
blocName: this._name,
|
|
901
921
|
blocId: String(this._id),
|
|
902
|
-
eventType:
|
|
922
|
+
eventType: a,
|
|
903
923
|
currentState: this.state,
|
|
904
924
|
action: t,
|
|
905
925
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
906
926
|
};
|
|
907
|
-
if (
|
|
908
|
-
`[Bloc ${this._name}:${String(this._id)}] Error in event handler for '${
|
|
909
|
-
|
|
927
|
+
if (d.error(
|
|
928
|
+
`[Bloc ${this._name}:${String(this._id)}] Error in event handler for '${a}':`,
|
|
929
|
+
o,
|
|
910
930
|
"Context:",
|
|
911
|
-
|
|
912
|
-
),
|
|
913
|
-
throw
|
|
931
|
+
u
|
|
932
|
+
), o instanceof Error && o.name === "CriticalError")
|
|
933
|
+
throw o;
|
|
914
934
|
}
|
|
915
935
|
} else {
|
|
916
936
|
const r = t.constructor.name || "UnnamedConstructor";
|
|
917
|
-
|
|
937
|
+
d.warn(
|
|
918
938
|
`[Bloc ${this._name}:${String(this._id)}] No handler registered for action type: '${r}'.`,
|
|
919
939
|
"Registered handlers:",
|
|
920
|
-
Array.from(this.eventHandlers.keys()).map((
|
|
940
|
+
Array.from(this.eventHandlers.keys()).map((o) => o.name),
|
|
921
941
|
"Action was:",
|
|
922
942
|
t
|
|
923
943
|
);
|
|
924
944
|
}
|
|
925
945
|
}
|
|
926
946
|
}
|
|
927
|
-
class
|
|
947
|
+
class H extends x {
|
|
948
|
+
/**
|
|
949
|
+
* @internal
|
|
950
|
+
* Protected method for useBloc to call
|
|
951
|
+
*/
|
|
952
|
+
_updateProps(e) {
|
|
953
|
+
var s;
|
|
954
|
+
const t = this.props;
|
|
955
|
+
this.props = e, (s = this.onPropsChanged) == null || s.call(this, t, e);
|
|
956
|
+
}
|
|
928
957
|
/**
|
|
929
958
|
* Updates the current state and notifies all observers of the change.
|
|
930
959
|
* If the new state is identical to the current state (using Object.is),
|
|
@@ -947,7 +976,7 @@ class V extends k {
|
|
|
947
976
|
*/
|
|
948
977
|
patch(e, t = !1) {
|
|
949
978
|
if (typeof this.state != "object" || this.state === null) {
|
|
950
|
-
|
|
979
|
+
d.warn(
|
|
951
980
|
"Cubit.patch: was called on a cubit where the state is not an object. This is a no-op."
|
|
952
981
|
);
|
|
953
982
|
return;
|
|
@@ -956,10 +985,10 @@ class V extends k {
|
|
|
956
985
|
if (t)
|
|
957
986
|
s = !0;
|
|
958
987
|
else
|
|
959
|
-
for (const
|
|
960
|
-
if (Object.prototype.hasOwnProperty.call(e,
|
|
961
|
-
const
|
|
962
|
-
if (!Object.is(e[
|
|
988
|
+
for (const n in e)
|
|
989
|
+
if (Object.prototype.hasOwnProperty.call(e, n)) {
|
|
990
|
+
const o = this.state[n];
|
|
991
|
+
if (!Object.is(e[n], o)) {
|
|
963
992
|
s = !0;
|
|
964
993
|
break;
|
|
965
994
|
}
|
|
@@ -970,69 +999,89 @@ class V extends k {
|
|
|
970
999
|
});
|
|
971
1000
|
}
|
|
972
1001
|
}
|
|
973
|
-
class
|
|
1002
|
+
class N {
|
|
1003
|
+
constructor(e) {
|
|
1004
|
+
this.props = e;
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
function j(c, e) {
|
|
1008
|
+
if (Object.is(c, e))
|
|
1009
|
+
return !0;
|
|
1010
|
+
if (typeof c != "object" || c === null || typeof e != "object" || e === null)
|
|
1011
|
+
return !1;
|
|
1012
|
+
const t = Object.keys(c), s = Object.keys(e);
|
|
1013
|
+
if (t.length !== s.length)
|
|
1014
|
+
return !1;
|
|
1015
|
+
for (let n = 0; n < t.length; n++) {
|
|
1016
|
+
const r = t[n];
|
|
1017
|
+
if (!Object.prototype.hasOwnProperty.call(e, r) || !Object.is(c[r], e[r]))
|
|
1018
|
+
return !1;
|
|
1019
|
+
}
|
|
1020
|
+
return !0;
|
|
1021
|
+
}
|
|
1022
|
+
class L {
|
|
974
1023
|
/**
|
|
975
1024
|
* Sets up a clean test environment
|
|
976
1025
|
*/
|
|
977
1026
|
static setUp() {
|
|
978
|
-
this.originalInstance =
|
|
1027
|
+
this.originalInstance = d.instance, d.resetInstance(), d.enableLog = !1;
|
|
979
1028
|
}
|
|
980
1029
|
/**
|
|
981
1030
|
* Tears down the test environment and restores original state
|
|
982
1031
|
*/
|
|
983
1032
|
static tearDown() {
|
|
984
|
-
|
|
1033
|
+
d.resetInstance();
|
|
985
1034
|
}
|
|
986
1035
|
/**
|
|
987
1036
|
* Creates a test bloc with automatic cleanup
|
|
988
1037
|
*/
|
|
989
1038
|
static createBloc(e, ...t) {
|
|
990
1039
|
const s = new e(...t);
|
|
991
|
-
return
|
|
1040
|
+
return d.activateBloc(s), s;
|
|
992
1041
|
}
|
|
993
1042
|
/**
|
|
994
1043
|
* Waits for a bloc to emit a specific state
|
|
995
1044
|
*/
|
|
996
1045
|
static async waitForState(e, t, s = 5e3) {
|
|
997
|
-
return new Promise((
|
|
998
|
-
const
|
|
1046
|
+
return new Promise((n, r) => {
|
|
1047
|
+
const o = setTimeout(() => {
|
|
999
1048
|
r(
|
|
1000
1049
|
new Error(
|
|
1001
1050
|
`Timeout waiting for state matching predicate after ${s}ms`
|
|
1002
1051
|
)
|
|
1003
1052
|
);
|
|
1004
|
-
}, s),
|
|
1053
|
+
}, s), a = e._observer.subscribe({
|
|
1005
1054
|
id: `test-waiter-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
|
|
1006
|
-
fn: (
|
|
1007
|
-
t(
|
|
1055
|
+
fn: (u) => {
|
|
1056
|
+
t(u) && (clearTimeout(o), a(), n(u));
|
|
1008
1057
|
}
|
|
1009
1058
|
});
|
|
1010
|
-
t(e.state) && (clearTimeout(
|
|
1059
|
+
t(e.state) && (clearTimeout(o), a(), n(e.state));
|
|
1011
1060
|
});
|
|
1012
1061
|
}
|
|
1013
1062
|
/**
|
|
1014
1063
|
* Expects a bloc to emit specific states in order
|
|
1015
1064
|
*/
|
|
1016
1065
|
static async expectStates(e, t, s = 5e3) {
|
|
1017
|
-
const
|
|
1018
|
-
return new Promise((r,
|
|
1019
|
-
const
|
|
1020
|
-
|
|
1066
|
+
const n = [];
|
|
1067
|
+
return new Promise((r, o) => {
|
|
1068
|
+
const a = setTimeout(() => {
|
|
1069
|
+
o(
|
|
1021
1070
|
new Error(
|
|
1022
|
-
`Timeout waiting for states. Expected: ${JSON.stringify(t)}, Received: ${JSON.stringify(
|
|
1071
|
+
`Timeout waiting for states. Expected: ${JSON.stringify(t)}, Received: ${JSON.stringify(n)}`
|
|
1023
1072
|
)
|
|
1024
1073
|
);
|
|
1025
|
-
}, s),
|
|
1074
|
+
}, s), u = e._observer.subscribe({
|
|
1026
1075
|
id: `test-expecter-${crypto.randomUUID()}`,
|
|
1027
1076
|
fn: (p) => {
|
|
1028
|
-
if (
|
|
1029
|
-
clearTimeout(
|
|
1030
|
-
for (let
|
|
1031
|
-
const m = t[
|
|
1032
|
-
if (JSON.stringify(m) !== JSON.stringify(
|
|
1033
|
-
|
|
1077
|
+
if (n.push(p), n.length === t.length) {
|
|
1078
|
+
clearTimeout(a), u();
|
|
1079
|
+
for (let h = 0; h < t.length; h++) {
|
|
1080
|
+
const m = t[h], I = n[h];
|
|
1081
|
+
if (JSON.stringify(m) !== JSON.stringify(I)) {
|
|
1082
|
+
o(
|
|
1034
1083
|
new Error(
|
|
1035
|
-
`State mismatch at index ${
|
|
1084
|
+
`State mismatch at index ${h}. Expected: ${JSON.stringify(m)}, Received: ${JSON.stringify(I)}`
|
|
1036
1085
|
)
|
|
1037
1086
|
);
|
|
1038
1087
|
return;
|
|
@@ -1045,11 +1094,11 @@ class U {
|
|
|
1045
1094
|
});
|
|
1046
1095
|
}
|
|
1047
1096
|
}
|
|
1048
|
-
|
|
1049
|
-
class
|
|
1097
|
+
i(L, "originalInstance");
|
|
1098
|
+
class Q extends U {
|
|
1050
1099
|
constructor(t) {
|
|
1051
1100
|
super(t);
|
|
1052
|
-
|
|
1101
|
+
i(this, "mockHandlers", /* @__PURE__ */ new Map());
|
|
1053
1102
|
}
|
|
1054
1103
|
/**
|
|
1055
1104
|
* Mock an event handler for testing
|
|
@@ -1070,10 +1119,10 @@ class z extends O {
|
|
|
1070
1119
|
return this.eventHandlers.has(t);
|
|
1071
1120
|
}
|
|
1072
1121
|
}
|
|
1073
|
-
class
|
|
1122
|
+
class W extends H {
|
|
1074
1123
|
constructor(t) {
|
|
1075
1124
|
super(t);
|
|
1076
|
-
|
|
1125
|
+
i(this, "stateHistory", []);
|
|
1077
1126
|
this.stateHistory.push(t);
|
|
1078
1127
|
}
|
|
1079
1128
|
/**
|
|
@@ -1095,16 +1144,16 @@ class j extends V {
|
|
|
1095
1144
|
this.stateHistory = [this.state];
|
|
1096
1145
|
}
|
|
1097
1146
|
}
|
|
1098
|
-
class
|
|
1147
|
+
class F {
|
|
1099
1148
|
constructor() {
|
|
1100
|
-
|
|
1101
|
-
this.initialStats =
|
|
1149
|
+
i(this, "initialStats");
|
|
1150
|
+
this.initialStats = d.getMemoryStats();
|
|
1102
1151
|
}
|
|
1103
1152
|
/**
|
|
1104
1153
|
* Check for memory leaks and return a report
|
|
1105
1154
|
*/
|
|
1106
1155
|
checkForLeaks() {
|
|
1107
|
-
const e =
|
|
1156
|
+
const e = d.getMemoryStats(), t = e.registeredBlocs > this.initialStats.registeredBlocs || e.isolatedBlocs > this.initialStats.isolatedBlocs || e.keepAliveBlocs > this.initialStats.keepAliveBlocs, s = `
|
|
1108
1157
|
Memory Leak Detection Report:
|
|
1109
1158
|
- Initial registered blocs: ${this.initialStats.registeredBlocs}
|
|
1110
1159
|
- Current registered blocs: ${e.registeredBlocs}
|
|
@@ -1121,11 +1170,11 @@ Memory Leak Detection Report:
|
|
|
1121
1170
|
};
|
|
1122
1171
|
}
|
|
1123
1172
|
}
|
|
1124
|
-
class
|
|
1173
|
+
class z {
|
|
1125
1174
|
constructor() {
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1175
|
+
i(this, "consumers", /* @__PURE__ */ new WeakMap());
|
|
1176
|
+
i(this, "registrationCount", 0);
|
|
1177
|
+
i(this, "activeConsumers", 0);
|
|
1129
1178
|
}
|
|
1130
1179
|
register(e, t) {
|
|
1131
1180
|
this.registrationCount++, this.consumers.get(e) || this.activeConsumers++, this.consumers.set(e, {
|
|
@@ -1144,11 +1193,11 @@ class H {
|
|
|
1144
1193
|
unregister(e) {
|
|
1145
1194
|
e && this.consumers.get(e) && (this.consumers.delete(e), this.activeConsumers = Math.max(0, this.activeConsumers - 1));
|
|
1146
1195
|
}
|
|
1147
|
-
trackAccess(e, t, s,
|
|
1196
|
+
trackAccess(e, t, s, n) {
|
|
1148
1197
|
const r = this.consumers.get(e);
|
|
1149
1198
|
if (!r) return;
|
|
1150
|
-
const
|
|
1151
|
-
r.firstAccessTime || (r.firstAccessTime =
|
|
1199
|
+
const o = Date.now();
|
|
1200
|
+
r.firstAccessTime || (r.firstAccessTime = o), r.accessCount++, r.lastAccessTime = o, t === "state" ? (r.stateAccesses.add(s), n !== void 0 && r.stateValues.set(s, { value: n, lastAccessTime: o })) : (r.classAccesses.add(s), n !== void 0 && r.classValues.set(s, { value: n, lastAccessTime: o }));
|
|
1152
1201
|
}
|
|
1153
1202
|
resetTracking(e) {
|
|
1154
1203
|
const t = this.consumers.get(e);
|
|
@@ -1162,28 +1211,28 @@ class H {
|
|
|
1162
1211
|
} : null;
|
|
1163
1212
|
}
|
|
1164
1213
|
hasValuesChanged(e, t, s) {
|
|
1165
|
-
const
|
|
1166
|
-
if (!
|
|
1214
|
+
const n = this.consumers.get(e);
|
|
1215
|
+
if (!n) return !0;
|
|
1167
1216
|
let r = !1;
|
|
1168
|
-
const
|
|
1169
|
-
if (
|
|
1217
|
+
const o = Date.now();
|
|
1218
|
+
if (n.stateValues.size === 0 && n.classValues.size === 0 && (n.stateAccesses.size > 0 || n.classAccesses.size > 0))
|
|
1170
1219
|
return !0;
|
|
1171
|
-
for (const [
|
|
1220
|
+
for (const [a, u] of n.stateValues)
|
|
1172
1221
|
try {
|
|
1173
|
-
const p = this.getValueAtPath(t,
|
|
1174
|
-
p !==
|
|
1222
|
+
const p = this.getValueAtPath(t, a);
|
|
1223
|
+
p !== u.value && (n.stateValues.set(a, {
|
|
1175
1224
|
value: p,
|
|
1176
|
-
lastAccessTime:
|
|
1225
|
+
lastAccessTime: o
|
|
1177
1226
|
}), r = !0);
|
|
1178
1227
|
} catch {
|
|
1179
1228
|
r = !0;
|
|
1180
1229
|
}
|
|
1181
|
-
for (const [
|
|
1230
|
+
for (const [a, u] of n.classValues)
|
|
1182
1231
|
try {
|
|
1183
|
-
const p = this.getValueAtPath(s,
|
|
1184
|
-
p !==
|
|
1232
|
+
const p = this.getValueAtPath(s, a);
|
|
1233
|
+
p !== u.value && (n.classValues.set(a, {
|
|
1185
1234
|
value: p,
|
|
1186
|
-
lastAccessTime:
|
|
1235
|
+
lastAccessTime: o
|
|
1187
1236
|
}), r = !0);
|
|
1188
1237
|
} catch {
|
|
1189
1238
|
r = !0;
|
|
@@ -1193,10 +1242,10 @@ class H {
|
|
|
1193
1242
|
shouldNotifyConsumer(e, t) {
|
|
1194
1243
|
const s = this.consumers.get(e);
|
|
1195
1244
|
if (!s) return !1;
|
|
1196
|
-
for (const
|
|
1197
|
-
if (s.stateAccesses.has(
|
|
1245
|
+
for (const n of t) {
|
|
1246
|
+
if (s.stateAccesses.has(n) || s.classAccesses.has(n)) return !0;
|
|
1198
1247
|
for (const r of s.stateAccesses)
|
|
1199
|
-
if (
|
|
1248
|
+
if (n.startsWith(r + ".") || r.startsWith(n + "."))
|
|
1200
1249
|
return !0;
|
|
1201
1250
|
}
|
|
1202
1251
|
return !1;
|
|
@@ -1223,16 +1272,16 @@ class H {
|
|
|
1223
1272
|
}
|
|
1224
1273
|
getValueAtPath(e, t) {
|
|
1225
1274
|
const s = t.split(".");
|
|
1226
|
-
let
|
|
1275
|
+
let n = e;
|
|
1227
1276
|
for (const r of s) {
|
|
1228
|
-
if (
|
|
1229
|
-
|
|
1277
|
+
if (n == null) return;
|
|
1278
|
+
n = n[r];
|
|
1230
1279
|
}
|
|
1231
|
-
return
|
|
1280
|
+
return n;
|
|
1232
1281
|
}
|
|
1233
1282
|
}
|
|
1234
|
-
const
|
|
1235
|
-
let
|
|
1283
|
+
const k = /* @__PURE__ */ new WeakMap();
|
|
1284
|
+
let f = {
|
|
1236
1285
|
stateProxiesCreated: 0,
|
|
1237
1286
|
classProxiesCreated: 0,
|
|
1238
1287
|
cacheHits: 0,
|
|
@@ -1242,44 +1291,44 @@ let h = {
|
|
|
1242
1291
|
totalProxiesCreated: 0,
|
|
1243
1292
|
createdAt: Date.now()
|
|
1244
1293
|
};
|
|
1245
|
-
class
|
|
1294
|
+
class b {
|
|
1246
1295
|
static createStateProxy(e) {
|
|
1247
|
-
const { target: t, consumerRef: s, consumerTracker:
|
|
1248
|
-
if (!s || !
|
|
1296
|
+
const { target: t, consumerRef: s, consumerTracker: n, path: r = "" } = e;
|
|
1297
|
+
if (!s || !n || typeof t != "object" || t === null)
|
|
1249
1298
|
return t;
|
|
1250
|
-
let
|
|
1251
|
-
|
|
1252
|
-
const
|
|
1253
|
-
if (
|
|
1254
|
-
return
|
|
1255
|
-
|
|
1256
|
-
const
|
|
1257
|
-
get(
|
|
1299
|
+
let o = k.get(t);
|
|
1300
|
+
o || (o = /* @__PURE__ */ new WeakMap(), k.set(t, o));
|
|
1301
|
+
const a = o.get(s);
|
|
1302
|
+
if (a)
|
|
1303
|
+
return f.cacheHits++, a;
|
|
1304
|
+
f.cacheMisses++;
|
|
1305
|
+
const u = {
|
|
1306
|
+
get(h, m) {
|
|
1258
1307
|
if (typeof m == "symbol" || m === "constructor")
|
|
1259
|
-
return Reflect.get(
|
|
1260
|
-
const
|
|
1261
|
-
|
|
1262
|
-
const g = Reflect.get(
|
|
1263
|
-
if (
|
|
1264
|
-
const B = Object.getPrototypeOf(g) === Object.prototype,
|
|
1265
|
-
if (B ||
|
|
1266
|
-
return
|
|
1308
|
+
return Reflect.get(h, m);
|
|
1309
|
+
const I = r ? `${r}.${m}` : m;
|
|
1310
|
+
f.propertyAccesses++;
|
|
1311
|
+
const g = Reflect.get(h, m), w = g && typeof g === "object" && g !== null ? void 0 : g;
|
|
1312
|
+
if (n.trackAccess(s, "state", I, w), g && typeof g == "object" && g !== null) {
|
|
1313
|
+
const B = Object.getPrototypeOf(g) === Object.prototype, P = Array.isArray(g);
|
|
1314
|
+
if (B || P)
|
|
1315
|
+
return f.nestedProxiesCreated++, b.createStateProxy({
|
|
1267
1316
|
target: g,
|
|
1268
1317
|
consumerRef: s,
|
|
1269
|
-
consumerTracker:
|
|
1270
|
-
path:
|
|
1318
|
+
consumerTracker: n,
|
|
1319
|
+
path: I
|
|
1271
1320
|
});
|
|
1272
1321
|
}
|
|
1273
1322
|
return g;
|
|
1274
1323
|
},
|
|
1275
|
-
has(
|
|
1276
|
-
return m in
|
|
1324
|
+
has(h, m) {
|
|
1325
|
+
return m in h;
|
|
1277
1326
|
},
|
|
1278
|
-
ownKeys(
|
|
1279
|
-
return Reflect.ownKeys(
|
|
1327
|
+
ownKeys(h) {
|
|
1328
|
+
return Reflect.ownKeys(h);
|
|
1280
1329
|
},
|
|
1281
|
-
getOwnPropertyDescriptor(
|
|
1282
|
-
return Reflect.getOwnPropertyDescriptor(
|
|
1330
|
+
getOwnPropertyDescriptor(h, m) {
|
|
1331
|
+
return Reflect.getOwnPropertyDescriptor(h, m);
|
|
1283
1332
|
},
|
|
1284
1333
|
set() {
|
|
1285
1334
|
return !1;
|
|
@@ -1287,90 +1336,90 @@ class y {
|
|
|
1287
1336
|
deleteProperty() {
|
|
1288
1337
|
return !1;
|
|
1289
1338
|
}
|
|
1290
|
-
}, p = new Proxy(t,
|
|
1291
|
-
return
|
|
1339
|
+
}, p = new Proxy(t, u);
|
|
1340
|
+
return o.set(s, p), f.stateProxiesCreated++, f.totalProxiesCreated++, p;
|
|
1292
1341
|
}
|
|
1293
1342
|
static createClassProxy(e) {
|
|
1294
|
-
const { target: t, consumerRef: s, consumerTracker:
|
|
1295
|
-
if (!s || !
|
|
1343
|
+
const { target: t, consumerRef: s, consumerTracker: n } = e;
|
|
1344
|
+
if (!s || !n)
|
|
1296
1345
|
return t;
|
|
1297
|
-
let r =
|
|
1298
|
-
r || (r = /* @__PURE__ */ new WeakMap(),
|
|
1299
|
-
const
|
|
1300
|
-
if (
|
|
1301
|
-
return
|
|
1302
|
-
|
|
1303
|
-
const
|
|
1304
|
-
get(p,
|
|
1305
|
-
const m = Reflect.get(p,
|
|
1306
|
-
let
|
|
1307
|
-
const A = /* @__PURE__ */ new WeakSet(),
|
|
1308
|
-
let
|
|
1309
|
-
for (; g && !
|
|
1346
|
+
let r = k.get(t);
|
|
1347
|
+
r || (r = /* @__PURE__ */ new WeakMap(), k.set(t, r));
|
|
1348
|
+
const o = r.get(s);
|
|
1349
|
+
if (o)
|
|
1350
|
+
return f.cacheHits++, o;
|
|
1351
|
+
f.cacheMisses++;
|
|
1352
|
+
const a = {
|
|
1353
|
+
get(p, h) {
|
|
1354
|
+
const m = Reflect.get(p, h);
|
|
1355
|
+
let I = !1, g = p;
|
|
1356
|
+
const A = /* @__PURE__ */ new WeakSet(), D = 10;
|
|
1357
|
+
let w = 0;
|
|
1358
|
+
for (; g && !I && w < D && !A.has(g); ) {
|
|
1310
1359
|
A.add(g);
|
|
1311
1360
|
try {
|
|
1312
|
-
const
|
|
1361
|
+
const T = Object.getOwnPropertyDescriptor(
|
|
1313
1362
|
g,
|
|
1314
|
-
|
|
1363
|
+
h
|
|
1315
1364
|
);
|
|
1316
|
-
if (
|
|
1317
|
-
|
|
1365
|
+
if (T && T.get) {
|
|
1366
|
+
I = !0;
|
|
1318
1367
|
break;
|
|
1319
1368
|
}
|
|
1320
|
-
g = Object.getPrototypeOf(g),
|
|
1369
|
+
g = Object.getPrototypeOf(g), w++;
|
|
1321
1370
|
} catch {
|
|
1322
1371
|
break;
|
|
1323
1372
|
}
|
|
1324
1373
|
}
|
|
1325
|
-
if (!
|
|
1374
|
+
if (!I)
|
|
1326
1375
|
return m;
|
|
1327
|
-
|
|
1328
|
-
const B = m,
|
|
1329
|
-
return
|
|
1376
|
+
f.propertyAccesses++;
|
|
1377
|
+
const B = m, M = B !== null && typeof B != "object" ? B : void 0;
|
|
1378
|
+
return n.trackAccess(
|
|
1330
1379
|
s,
|
|
1331
1380
|
"class",
|
|
1332
|
-
String(
|
|
1333
|
-
|
|
1381
|
+
String(h),
|
|
1382
|
+
M
|
|
1334
1383
|
), m;
|
|
1335
1384
|
},
|
|
1336
|
-
has(p,
|
|
1337
|
-
return
|
|
1385
|
+
has(p, h) {
|
|
1386
|
+
return h in p;
|
|
1338
1387
|
},
|
|
1339
1388
|
ownKeys(p) {
|
|
1340
1389
|
return Reflect.ownKeys(p);
|
|
1341
1390
|
},
|
|
1342
|
-
getOwnPropertyDescriptor(p,
|
|
1343
|
-
return Reflect.getOwnPropertyDescriptor(p,
|
|
1391
|
+
getOwnPropertyDescriptor(p, h) {
|
|
1392
|
+
return Reflect.getOwnPropertyDescriptor(p, h);
|
|
1344
1393
|
}
|
|
1345
|
-
},
|
|
1346
|
-
return r.set(s,
|
|
1394
|
+
}, u = new Proxy(t, a);
|
|
1395
|
+
return r.set(s, u), f.classProxiesCreated++, f.totalProxiesCreated++, u;
|
|
1347
1396
|
}
|
|
1348
1397
|
static getProxyState(e) {
|
|
1349
|
-
return
|
|
1398
|
+
return b.createStateProxy({
|
|
1350
1399
|
target: e.state,
|
|
1351
1400
|
consumerRef: e.consumerRef,
|
|
1352
1401
|
consumerTracker: e.consumerTracker
|
|
1353
1402
|
});
|
|
1354
1403
|
}
|
|
1355
1404
|
static getProxyBlocInstance(e) {
|
|
1356
|
-
return
|
|
1405
|
+
return b.createClassProxy({
|
|
1357
1406
|
target: e.blocInstance,
|
|
1358
1407
|
consumerRef: e.consumerRef,
|
|
1359
1408
|
consumerTracker: e.consumerTracker
|
|
1360
1409
|
});
|
|
1361
1410
|
}
|
|
1362
1411
|
static getStats() {
|
|
1363
|
-
const e = Date.now() -
|
|
1412
|
+
const e = Date.now() - f.createdAt;
|
|
1364
1413
|
return {
|
|
1365
|
-
...
|
|
1366
|
-
totalProxies:
|
|
1367
|
-
cacheEfficiency:
|
|
1414
|
+
...f,
|
|
1415
|
+
totalProxies: f.stateProxiesCreated + f.classProxiesCreated,
|
|
1416
|
+
cacheEfficiency: f.cacheHits + f.cacheMisses > 0 ? `${(f.cacheHits / (f.cacheHits + f.cacheMisses) * 100).toFixed(1)}%` : "N/A",
|
|
1368
1417
|
lifetime: `${e}ms`,
|
|
1369
|
-
proxiesPerSecond: e > 0 ? (
|
|
1418
|
+
proxiesPerSecond: e > 0 ? (f.totalProxiesCreated / (e / 1e3)).toFixed(2) : "N/A"
|
|
1370
1419
|
};
|
|
1371
1420
|
}
|
|
1372
1421
|
static resetStats() {
|
|
1373
|
-
|
|
1422
|
+
f = {
|
|
1374
1423
|
stateProxiesCreated: 0,
|
|
1375
1424
|
classProxiesCreated: 0,
|
|
1376
1425
|
cacheHits: 0,
|
|
@@ -1382,60 +1431,64 @@ class y {
|
|
|
1382
1431
|
};
|
|
1383
1432
|
}
|
|
1384
1433
|
}
|
|
1385
|
-
class
|
|
1434
|
+
const v = class v {
|
|
1386
1435
|
constructor(e, t) {
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1436
|
+
i(this, "id", `consumer-${$()}`);
|
|
1437
|
+
i(this, "blocConstructor");
|
|
1438
|
+
i(this, "componentRef", { current: {} });
|
|
1439
|
+
i(this, "blocInstance");
|
|
1391
1440
|
// Core components
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1441
|
+
i(this, "consumerTracker");
|
|
1442
|
+
i(this, "lastProps");
|
|
1443
|
+
i(this, "unmountTime", 0);
|
|
1444
|
+
i(this, "mountTime", 0);
|
|
1395
1445
|
// Dependency tracking
|
|
1396
|
-
|
|
1397
|
-
|
|
1446
|
+
i(this, "dependencyValues");
|
|
1447
|
+
i(this, "isUsingDependencies", !1);
|
|
1398
1448
|
// Lifecycle state
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1449
|
+
i(this, "hasMounted", !1);
|
|
1450
|
+
i(this, "mountCount", 0);
|
|
1451
|
+
i(this, "options");
|
|
1452
|
+
i(this, "createStateProxy", (e) => b.createStateProxy({
|
|
1403
1453
|
target: e.target,
|
|
1404
1454
|
consumerRef: this.componentRef.current,
|
|
1405
1455
|
consumerTracker: this
|
|
1406
1456
|
}));
|
|
1407
|
-
|
|
1457
|
+
i(this, "createClassProxy", (e) => b.createClassProxy({
|
|
1408
1458
|
target: e.target,
|
|
1409
1459
|
consumerRef: this.componentRef.current,
|
|
1410
1460
|
consumerTracker: this
|
|
1411
1461
|
}));
|
|
1412
|
-
|
|
1462
|
+
i(this, "createSubscription", (e) => this.blocInstance._observer.subscribe({
|
|
1413
1463
|
id: this.id,
|
|
1414
|
-
fn: (s,
|
|
1464
|
+
fn: (s, n) => {
|
|
1415
1465
|
var r;
|
|
1416
1466
|
if (this.isUsingDependencies && ((r = this.options) != null && r.dependencies)) {
|
|
1417
|
-
const
|
|
1467
|
+
const o = this.options.dependencies(this.blocInstance);
|
|
1418
1468
|
if (!this.hasDependencyValuesChanged(
|
|
1419
1469
|
this.dependencyValues,
|
|
1420
|
-
|
|
1470
|
+
o
|
|
1421
1471
|
))
|
|
1422
1472
|
return;
|
|
1423
|
-
this.dependencyValues =
|
|
1424
|
-
} else {
|
|
1425
|
-
const
|
|
1473
|
+
this.dependencyValues = o;
|
|
1474
|
+
} else if (d.config.proxyDependencyTracking) {
|
|
1475
|
+
const o = this.consumerTracker.getConsumerInfo(
|
|
1426
1476
|
this.componentRef.current
|
|
1427
1477
|
);
|
|
1428
|
-
if (
|
|
1478
|
+
if (o && o.hasRendered && !this.consumerTracker.hasValuesChanged(
|
|
1429
1479
|
this.componentRef.current,
|
|
1430
1480
|
s,
|
|
1431
1481
|
this.blocInstance
|
|
1432
1482
|
))
|
|
1433
1483
|
return;
|
|
1484
|
+
} else {
|
|
1485
|
+
e.onChange();
|
|
1486
|
+
return;
|
|
1434
1487
|
}
|
|
1435
1488
|
e.onChange();
|
|
1436
1489
|
}
|
|
1437
1490
|
}));
|
|
1438
|
-
|
|
1491
|
+
i(this, "mount", () => {
|
|
1439
1492
|
var e, t;
|
|
1440
1493
|
if (this.isUsingDependencies && ((e = this.options) != null && e.dependencies) && (this.dependencyValues = this.options.dependencies(this.blocInstance)), this.mountCount++, this.blocInstance._addConsumer(this.id, this.componentRef.current), !this.hasMounted && (this.hasMounted = !0, this.mountTime = Date.now(), (t = this.options) != null && t.onMount))
|
|
1441
1494
|
try {
|
|
@@ -1444,28 +1497,28 @@ class q {
|
|
|
1444
1497
|
throw s;
|
|
1445
1498
|
}
|
|
1446
1499
|
});
|
|
1447
|
-
|
|
1500
|
+
i(this, "unmount", () => {
|
|
1448
1501
|
var e;
|
|
1449
|
-
if (this.unmountTime = Date.now(), this.consumerTracker.unregister(this.componentRef.current), this.blocInstance._removeConsumer(this.id), (e = this.options) != null && e.onUnmount)
|
|
1502
|
+
if (this.unmountTime = Date.now(), this.consumerTracker.unregister(this.componentRef.current), this.blocInstance._removeConsumer(this.id), v.propsOwners.get(this.blocInstance) === this.id && v.propsOwners.delete(this.blocInstance), (e = this.options) != null && e.onUnmount)
|
|
1450
1503
|
try {
|
|
1451
1504
|
this.options.onUnmount(this.blocInstance);
|
|
1452
1505
|
} catch {
|
|
1453
1506
|
}
|
|
1454
1507
|
});
|
|
1455
|
-
|
|
1508
|
+
i(this, "getProxyState", (e) => this.isUsingDependencies || !d.config.proxyDependencyTracking ? e : b.getProxyState({
|
|
1456
1509
|
state: e,
|
|
1457
1510
|
consumerRef: this.componentRef.current,
|
|
1458
1511
|
consumerTracker: this
|
|
1459
1512
|
}));
|
|
1460
|
-
|
|
1513
|
+
i(this, "getProxyBlocInstance", () => this.isUsingDependencies || !d.config.proxyDependencyTracking ? this.blocInstance : b.getProxyBlocInstance({
|
|
1461
1514
|
blocInstance: this.blocInstance,
|
|
1462
1515
|
consumerRef: this.componentRef.current,
|
|
1463
1516
|
consumerTracker: this
|
|
1464
1517
|
}));
|
|
1465
|
-
this.options = t, this.blocConstructor = e.blocConstructor, this.componentRef = e.componentRef, this.isUsingDependencies = !!(t != null && t.dependencies), this.consumerTracker = new
|
|
1518
|
+
this.options = t, this.blocConstructor = e.blocConstructor, this.componentRef = e.componentRef, this.isUsingDependencies = !!(t != null && t.dependencies), this.consumerTracker = new z(), 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);
|
|
1466
1519
|
}
|
|
1467
|
-
trackAccess(e, t, s,
|
|
1468
|
-
this.consumerTracker.trackAccess(e, t, s,
|
|
1520
|
+
trackAccess(e, t, s, n) {
|
|
1521
|
+
this.consumerTracker.trackAccess(e, t, s, n);
|
|
1469
1522
|
}
|
|
1470
1523
|
getConsumerDependencies(e) {
|
|
1471
1524
|
return this.consumerTracker.getDependencies(e);
|
|
@@ -1482,7 +1535,7 @@ class q {
|
|
|
1482
1535
|
}
|
|
1483
1536
|
updateBlocInstance() {
|
|
1484
1537
|
var e, t;
|
|
1485
|
-
return this.blocInstance =
|
|
1538
|
+
return this.blocInstance = d.instance.getBloc(this.blocConstructor, {
|
|
1486
1539
|
props: (e = this.options) == null ? void 0 : e.props,
|
|
1487
1540
|
id: (t = this.options) == null ? void 0 : t.id,
|
|
1488
1541
|
instanceRef: this.id
|
|
@@ -1492,6 +1545,16 @@ class q {
|
|
|
1492
1545
|
get calledOnMount() {
|
|
1493
1546
|
return this.hasMounted;
|
|
1494
1547
|
}
|
|
1548
|
+
updateProps(e) {
|
|
1549
|
+
const t = this.blocInstance;
|
|
1550
|
+
if (v.propsOwners.has(t) || v.propsOwners.set(t, this.id), v.propsOwners.get(t) !== this.id) {
|
|
1551
|
+
d.warn(
|
|
1552
|
+
`[BlacAdapter] Attempted to set props on ${t.constructor.name} from non-owner adapter`
|
|
1553
|
+
);
|
|
1554
|
+
return;
|
|
1555
|
+
}
|
|
1556
|
+
t._disposalState === _.DISPOSED || t._disposalState === _.DISPOSING || j(this.lastProps, e) || ("add" in t && typeof t.add == "function" ? t.add(new N(e)) : "_updateProps" in t && typeof t._updateProps == "function" && t._updateProps(e), this.lastProps = e);
|
|
1557
|
+
}
|
|
1495
1558
|
hasDependencyValuesChanged(e, t) {
|
|
1496
1559
|
if (!e || e.length !== t.length) return !0;
|
|
1497
1560
|
for (let s = 0; s < e.length; s++)
|
|
@@ -1499,22 +1562,27 @@ class q {
|
|
|
1499
1562
|
return !0;
|
|
1500
1563
|
return !1;
|
|
1501
1564
|
}
|
|
1502
|
-
}
|
|
1565
|
+
};
|
|
1566
|
+
// Props ownership tracking
|
|
1567
|
+
i(v, "propsOwners", /* @__PURE__ */ new WeakMap());
|
|
1568
|
+
let R = v;
|
|
1503
1569
|
export {
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1570
|
+
d as Blac,
|
|
1571
|
+
R as BlacAdapter,
|
|
1572
|
+
V as BlacObservable,
|
|
1573
|
+
U as Bloc,
|
|
1574
|
+
x as BlocBase,
|
|
1509
1575
|
_ as BlocLifecycleState,
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1576
|
+
L as BlocTest,
|
|
1577
|
+
z as ConsumerTracker,
|
|
1578
|
+
H as Cubit,
|
|
1579
|
+
F as MemoryLeakDetector,
|
|
1580
|
+
Q as MockBloc,
|
|
1581
|
+
W as MockCubit,
|
|
1582
|
+
N as PropsUpdated,
|
|
1583
|
+
b as ProxyFactory,
|
|
1584
|
+
$ as generateUUID,
|
|
1585
|
+
q as setBlacInstanceManager,
|
|
1586
|
+
j as shallowEqual
|
|
1519
1587
|
};
|
|
1520
1588
|
//# sourceMappingURL=index.es.js.map
|