@blac/core 2.0.0-rc-13 → 2.0.0-rc-14
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 +522 -297
- package/dist/index.es.js +1833 -1550
- package/dist/index.es.js.map +1 -1
- package/package.json +6 -7
- package/src/Blac.ts +38 -71
- package/src/Bloc.ts +8 -9
- package/src/BlocBase.ts +246 -540
- package/src/Cubit.ts +1 -16
- package/src/__tests__/Blac.config.test.ts +10 -17
- package/src/__tests__/Bloc.event.test.ts +27 -52
- package/src/__tests__/BlocBase.subscription.test.ts +349 -0
- package/src/__tests__/Cubit.test.ts +39 -50
- package/src/__tests__/memory-leaks.test.ts +383 -0
- package/src/__tests__/plugins.test.ts +107 -97
- package/src/adapter/BlacAdapter.ts +347 -207
- package/src/adapter/ProxyFactory.ts +196 -255
- package/src/adapter/__tests__/BlacAdapter.test.ts +71 -77
- package/src/adapter/__tests__/ProxyFactory.test.ts +1 -1
- package/src/adapter/index.ts +0 -1
- package/src/errors/BlacError.ts +69 -0
- package/src/errors/ErrorManager.ts +101 -0
- package/src/errors/handleError.ts +114 -0
- package/src/errors/index.ts +13 -0
- package/src/events.ts +7 -1
- package/src/index.ts +7 -1
- package/src/lifecycle/BlocLifecycle.ts +156 -0
- package/src/lifecycle/index.ts +1 -0
- package/src/plugins/BlocPluginRegistry.ts +71 -51
- package/src/plugins/SystemPluginRegistry.ts +63 -13
- package/src/plugins/__tests__/BlocPluginRegistry.test.ts +450 -0
- package/src/plugins/__tests__/SystemPluginRegistry.test.ts +404 -0
- package/src/plugins/types.ts +32 -3
- package/src/subscription/README.md +132 -0
- package/src/subscription/SubscriptionManager.ts +395 -0
- package/src/subscription/__tests__/SubscriptionManager.test.ts +355 -0
- package/src/subscription/index.ts +2 -0
- package/src/subscription/types.ts +90 -0
- package/src/testing.ts +31 -37
- package/src/types.ts +4 -21
- package/src/utils/BatchingManager.ts +59 -0
- package/src/utils/RerenderLogger.ts +265 -0
- package/src/utils/__tests__/generateInstanceId.test.ts +104 -0
- package/src/utils/__tests__/shallowEqual.test.ts +171 -0
- package/src/utils/__tests__/uuid.test.ts +144 -0
- package/src/utils/generateInstanceId.ts +54 -0
- package/src/utils/shallowEqual.ts +1 -1
- package/README.md +0 -329
- package/src/BlacObserver.ts +0 -189
- package/src/__tests__/BlocBase.lifecycle.test.ts +0 -441
- package/src/__tests__/props.test.ts +0 -256
- package/src/adapter/ConsumerTracker.ts +0 -241
- package/src/adapter/__tests__/ConsumerTracker.test.ts +0 -562
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Adapter metadata provided to plugins
|
|
3
|
+
*/
|
|
4
|
+
export declare interface AdapterMetadata {
|
|
5
|
+
componentName?: string;
|
|
6
|
+
blocInstance: BlocBase<any>;
|
|
7
|
+
renderCount: number;
|
|
8
|
+
trackedPaths?: string[];
|
|
9
|
+
isUsingDependencies?: boolean;
|
|
10
|
+
lastState?: any;
|
|
11
|
+
lastDependencyValues?: any[];
|
|
12
|
+
currentDependencyValues?: any[];
|
|
13
|
+
}
|
|
6
14
|
|
|
7
15
|
export declare interface AdapterOptions<B extends BlocBase<any>> {
|
|
8
|
-
|
|
16
|
+
instanceId?: string;
|
|
9
17
|
dependencies?: (bloc: B) => unknown[];
|
|
10
|
-
|
|
18
|
+
staticProps?: any;
|
|
11
19
|
onMount?: (bloc: B) => void;
|
|
12
20
|
onUnmount?: (bloc: B) => void;
|
|
13
21
|
}
|
|
@@ -26,6 +34,7 @@ export declare class Blac {
|
|
|
26
34
|
static get instance(): Blac;
|
|
27
35
|
/** Timestamp when the instance was created */
|
|
28
36
|
createdAt: number;
|
|
37
|
+
private errorManager;
|
|
29
38
|
static get getAllBlocs(): <B extends BlocConstructor<any>>(blocClass: B, options?: {
|
|
30
39
|
searchIsolated?: boolean;
|
|
31
40
|
}) => InstanceType<B>[];
|
|
@@ -167,24 +176,6 @@ export declare class Blac {
|
|
|
167
176
|
*/
|
|
168
177
|
getBloc: <B extends BlocConstructor<BlocBase<any>>>(blocClass: B, options?: GetBlocOptions<InstanceType<B>>) => InstanceType<B>;
|
|
169
178
|
static get getBloc(): <B extends BlocConstructor<BlocBase<any>>>(blocClass: B, options?: GetBlocOptions<InstanceType<B>>) => InstanceType<B>;
|
|
170
|
-
/**
|
|
171
|
-
* Gets a bloc instance or throws an error if it doesn't exist
|
|
172
|
-
* @param blocClass - The bloc class to get
|
|
173
|
-
* @param options - Options including:
|
|
174
|
-
* - id: The instance ID (defaults to class name if not provided)
|
|
175
|
-
* - props: Properties to pass to the bloc constructor
|
|
176
|
-
* - instanceRef: Optional reference string for the instance
|
|
177
|
-
*/
|
|
178
|
-
getBlocOrThrow: <B extends BlocConstructor<any>>(blocClass: B, options?: {
|
|
179
|
-
id?: BlocInstanceId;
|
|
180
|
-
props?: InferPropsFromGeneric<B>;
|
|
181
|
-
instanceRef?: string;
|
|
182
|
-
}) => InstanceType<B>;
|
|
183
|
-
static get getBlocOrThrow(): <B extends BlocConstructor<any>>(blocClass: B, options?: {
|
|
184
|
-
id?: BlocInstanceId;
|
|
185
|
-
props?: InferPropsFromGeneric<B> | undefined;
|
|
186
|
-
instanceRef?: string;
|
|
187
|
-
}) => InstanceType<B>;
|
|
188
179
|
/**
|
|
189
180
|
* Gets all instances of a specific bloc class
|
|
190
181
|
* @param blocClass - The bloc class to search for
|
|
@@ -225,7 +216,7 @@ export declare class Blac {
|
|
|
225
216
|
isolatedBlocTypes: number;
|
|
226
217
|
};
|
|
227
218
|
/**
|
|
228
|
-
* Validates
|
|
219
|
+
* Validates subscription references and cleans up orphaned blocs
|
|
229
220
|
*/
|
|
230
221
|
validateConsumers: () => void;
|
|
231
222
|
static get validateConsumers(): () => void;
|
|
@@ -250,15 +241,24 @@ export declare class BlacAdapter<B extends BlocConstructor<BlocBase<any>>> {
|
|
|
250
241
|
current: object;
|
|
251
242
|
};
|
|
252
243
|
blocInstance: InstanceType<B>;
|
|
253
|
-
private consumerTracker;
|
|
254
|
-
private static propsOwners;
|
|
255
|
-
private lastProps?;
|
|
256
244
|
unmountTime: number;
|
|
257
245
|
mountTime: number;
|
|
246
|
+
private subscriptionId?;
|
|
247
|
+
private unsubscribe?;
|
|
258
248
|
private dependencyValues?;
|
|
259
249
|
private isUsingDependencies;
|
|
250
|
+
private trackedPaths;
|
|
251
|
+
private pendingTrackedPaths;
|
|
252
|
+
private cachedStateProxy?;
|
|
253
|
+
private cachedBlocProxy?;
|
|
254
|
+
private lastProxiedState?;
|
|
260
255
|
private hasMounted;
|
|
261
256
|
private mountCount;
|
|
257
|
+
private lastState?;
|
|
258
|
+
private lastDependencyValues?;
|
|
259
|
+
private componentName?;
|
|
260
|
+
private renderCount;
|
|
261
|
+
private lastDependenciesFn?;
|
|
262
262
|
options?: AdapterOptions<InstanceType<B>>;
|
|
263
263
|
constructor(instanceProps: {
|
|
264
264
|
componentRef: {
|
|
@@ -267,35 +267,35 @@ export declare class BlacAdapter<B extends BlocConstructor<BlocBase<any>>> {
|
|
|
267
267
|
blocConstructor: B;
|
|
268
268
|
}, options?: typeof BlacAdapter.options);
|
|
269
269
|
trackAccess(consumerRef: object, type: 'state' | 'class', path: string, value?: any): void;
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
270
|
+
updateBlocInstance(): InstanceType<B>;
|
|
271
|
+
createSubscription: (options: {
|
|
272
|
+
onChange: () => void;
|
|
273
|
+
}) => () => void;
|
|
274
|
+
hasDependencyValuesChanged: (oldValues: unknown[] | undefined, newValues: unknown[]) => boolean;
|
|
275
|
+
getStateProxy: () => BlocState<InstanceType<B>>;
|
|
276
|
+
getBlocProxy: () => InstanceType<B>;
|
|
274
277
|
createStateProxy: <T extends object>(props: {
|
|
275
278
|
target: T;
|
|
276
279
|
}) => T;
|
|
277
280
|
createClassProxy: <T extends object>(props: {
|
|
278
281
|
target: T;
|
|
279
282
|
}) => T;
|
|
280
|
-
updateBlocInstance(): InstanceType<B>;
|
|
281
|
-
createSubscription: (options: {
|
|
282
|
-
onChange: () => void;
|
|
283
|
-
}) => () => void;
|
|
284
283
|
mount: () => void;
|
|
285
284
|
unmount: () => void;
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
private
|
|
285
|
+
resetTracking(): void;
|
|
286
|
+
setComponentName(name: string): void;
|
|
287
|
+
notifyRender(): void;
|
|
288
|
+
private getAdapterMetadata;
|
|
289
|
+
private getValueAtPath;
|
|
290
|
+
private getStateChangedPaths;
|
|
291
|
+
private getDeepChangedPaths;
|
|
292
|
+
getLastRerenderReason(): any;
|
|
291
293
|
}
|
|
292
294
|
|
|
293
295
|
/**
|
|
294
296
|
* Configuration options for the Blac instance
|
|
295
297
|
*/
|
|
296
298
|
export declare interface BlacConfig {
|
|
297
|
-
/** Whether to expose the Blac instance globally */
|
|
298
|
-
exposeBlacInstance?: boolean;
|
|
299
299
|
/**
|
|
300
300
|
* Whether to enable proxy dependency tracking for automatic re-render optimization.
|
|
301
301
|
* When false, state changes always cause re-renders unless dependencies are manually specified.
|
|
@@ -304,6 +304,24 @@ export declare interface BlacConfig {
|
|
|
304
304
|
proxyDependencyTracking?: boolean;
|
|
305
305
|
}
|
|
306
306
|
|
|
307
|
+
export declare class BlacError extends Error {
|
|
308
|
+
readonly category: ErrorCategory;
|
|
309
|
+
readonly severity: ErrorSeverity;
|
|
310
|
+
readonly context?: BlacErrorContext | undefined;
|
|
311
|
+
readonly cause?: unknown | undefined;
|
|
312
|
+
constructor(message: string, category: ErrorCategory, severity: ErrorSeverity, context?: BlacErrorContext | undefined, cause?: unknown | undefined);
|
|
313
|
+
toString(): string;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
export declare type BlacErrorContext = {
|
|
317
|
+
blocName?: string;
|
|
318
|
+
blocId?: string;
|
|
319
|
+
consumerId?: string;
|
|
320
|
+
pluginName?: string;
|
|
321
|
+
operation?: string;
|
|
322
|
+
metadata?: Record<string, unknown>;
|
|
323
|
+
};
|
|
324
|
+
|
|
307
325
|
/**
|
|
308
326
|
* Interface for Blac instance management
|
|
309
327
|
*/
|
|
@@ -313,70 +331,6 @@ export declare interface BlacInstanceManager {
|
|
|
313
331
|
resetInstance(): void;
|
|
314
332
|
}
|
|
315
333
|
|
|
316
|
-
/**
|
|
317
|
-
* A class that manages observers for a Bloc's state changes
|
|
318
|
-
* @template S - The type of state being observed
|
|
319
|
-
*/
|
|
320
|
-
export declare class BlacObservable<S = unknown> {
|
|
321
|
-
/** The Bloc instance this observable is associated with */
|
|
322
|
-
bloc: BlocBase<S>;
|
|
323
|
-
/**
|
|
324
|
-
* Creates a new BlacObservable instance
|
|
325
|
-
* @param bloc - The Bloc instance to observe
|
|
326
|
-
*/
|
|
327
|
-
constructor(bloc: BlocBase<S>);
|
|
328
|
-
private _observers;
|
|
329
|
-
/**
|
|
330
|
-
* Gets the number of active observers
|
|
331
|
-
* @returns The number of observers currently subscribed
|
|
332
|
-
*/
|
|
333
|
-
get size(): number;
|
|
334
|
-
/**
|
|
335
|
-
* Gets the set of all observers
|
|
336
|
-
* @returns The Set of all BlacObserver instances
|
|
337
|
-
*/
|
|
338
|
-
get observers(): Set<BlacObserver<S>>;
|
|
339
|
-
/**
|
|
340
|
-
* Subscribes an observer to state changes
|
|
341
|
-
* @param observer - The observer to subscribe
|
|
342
|
-
* @returns A function that can be called to unsubscribe the observer
|
|
343
|
-
*/
|
|
344
|
-
subscribe(observer: BlacObserver<S>): () => void;
|
|
345
|
-
/**
|
|
346
|
-
* Unsubscribes an observer from state changes
|
|
347
|
-
* @param observer - The observer to unsubscribe
|
|
348
|
-
*/
|
|
349
|
-
unsubscribe(observer: BlacObserver<S>): void;
|
|
350
|
-
/**
|
|
351
|
-
* Notifies all observers of a state change
|
|
352
|
-
* @param newState - The new state value
|
|
353
|
-
* @param oldState - The previous state value
|
|
354
|
-
* @param action - Optional action that triggered the state change
|
|
355
|
-
*/
|
|
356
|
-
notify(newState: S, oldState: S, action?: unknown): void;
|
|
357
|
-
/**
|
|
358
|
-
* Clears the observer set
|
|
359
|
-
*/
|
|
360
|
-
clear(): void;
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
/**
|
|
364
|
-
* Represents an observer that can subscribe to state changes in a Bloc
|
|
365
|
-
* @template S - The type of state being observed
|
|
366
|
-
*/
|
|
367
|
-
export declare type BlacObserver<S> = {
|
|
368
|
-
/** Function to be called when state changes */
|
|
369
|
-
fn: (newState: S, oldState: S, action?: unknown) => void | Promise<void>;
|
|
370
|
-
/** Optional function to determine if the observer should be notified of state changes */
|
|
371
|
-
dependencyArray?: BlocHookDependencyArrayFn<S>;
|
|
372
|
-
/** Dispose function for the observer */
|
|
373
|
-
dispose?: () => void;
|
|
374
|
-
/** Cached state values used for dependency comparison */
|
|
375
|
-
lastState?: unknown[];
|
|
376
|
-
/** Unique identifier for the observer */
|
|
377
|
-
id: string;
|
|
378
|
-
};
|
|
379
|
-
|
|
380
334
|
/**
|
|
381
335
|
* System-wide plugin that observes all blocs
|
|
382
336
|
*/
|
|
@@ -390,11 +344,15 @@ export declare interface BlacPlugin extends Plugin_2 {
|
|
|
390
344
|
onStateChanged?(bloc: BlocBase<any>, previousState: any, currentState: any): void;
|
|
391
345
|
onEventAdded?(bloc: Bloc<any, any>, event: any): void;
|
|
392
346
|
onError?(error: Error, bloc: BlocBase<unknown>, context: ErrorContext): void;
|
|
347
|
+
onAdapterCreated?(adapter: any, metadata: AdapterMetadata): void;
|
|
348
|
+
onAdapterMount?(adapter: any, metadata: AdapterMetadata): void;
|
|
349
|
+
onAdapterUnmount?(adapter: any, metadata: AdapterMetadata): void;
|
|
350
|
+
onAdapterRender?(adapter: any, metadata: AdapterMetadata): void;
|
|
351
|
+
onAdapterDisposed?(adapter: any, metadata: AdapterMetadata): void;
|
|
393
352
|
}
|
|
394
353
|
|
|
395
354
|
export declare abstract class Bloc<S, // State type
|
|
396
|
-
A extends BlocEventConstraint = BlocEventConstraint
|
|
397
|
-
P = unknown> extends BlocBase<S, P> {
|
|
355
|
+
A extends BlocEventConstraint = BlocEventConstraint> extends BlocBase<S> {
|
|
398
356
|
readonly eventHandlers: Map<new (...args: any[]) => A, (event: A, emit: (newState: S) => void) => void | Promise<void>>;
|
|
399
357
|
/* Excluded from this release type: _eventQueue */
|
|
400
358
|
/* Excluded from this release type: _isProcessingEvent */
|
|
@@ -417,126 +375,113 @@ P = unknown> extends BlocBase<S, P> {
|
|
|
417
375
|
}
|
|
418
376
|
|
|
419
377
|
/**
|
|
420
|
-
* Base class for both Blocs and Cubits
|
|
421
|
-
* Handles state transitions, observer notifications, lifecycle management, and addon integration.
|
|
422
|
-
*
|
|
423
|
-
* @abstract This class should be extended, not instantiated directly
|
|
424
|
-
* @template S The type of state managed by this Bloc
|
|
425
|
-
* @template P The type of props that can be passed during instance creation (optional)
|
|
378
|
+
* Base class for both Blocs and Cubits using unified subscription model.
|
|
426
379
|
*/
|
|
427
|
-
export declare abstract class BlocBase<S
|
|
380
|
+
export declare abstract class BlocBase<S> {
|
|
428
381
|
uid: string;
|
|
429
|
-
|
|
430
|
-
* When true, every consumer will receive its own unique instance of this Bloc.
|
|
431
|
-
* Use this when state should not be shared between components.
|
|
432
|
-
* @default false
|
|
433
|
-
*/
|
|
382
|
+
blacInstance?: Blac;
|
|
434
383
|
static isolated: boolean;
|
|
435
384
|
get isIsolated(): boolean;
|
|
436
|
-
/**
|
|
437
|
-
* When true, the Bloc instance persists even when there are no active consumers.
|
|
438
|
-
* Useful for maintaining state between component unmount/remount cycles.
|
|
439
|
-
* @default false
|
|
440
|
-
*/
|
|
441
385
|
static keepAlive: boolean;
|
|
442
386
|
get isKeepAlive(): boolean;
|
|
387
|
+
_isolated: boolean;
|
|
388
|
+
_id: BlocInstanceId;
|
|
389
|
+
_instanceRef?: string;
|
|
390
|
+
_name: string;
|
|
443
391
|
/**
|
|
444
|
-
*
|
|
445
|
-
* When provided, observers will only be notified when selected dependencies change.
|
|
392
|
+
* Unified subscription manager for all state notifications
|
|
446
393
|
*/
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
394
|
+
_subscriptionManager: SubscriptionManager<S>;
|
|
395
|
+
_state: S;
|
|
396
|
+
private _lifecycleManager;
|
|
397
|
+
private _batchingManager;
|
|
398
|
+
_keepAlive: boolean;
|
|
399
|
+
lastUpdate?: number;
|
|
400
|
+
_plugins: BlocPluginRegistry<S, any>;
|
|
401
|
+
onDispose?: () => void;
|
|
450
402
|
/**
|
|
451
|
-
*
|
|
452
|
-
* Defaults to the class name, but can be customized.
|
|
403
|
+
* Creates a new BlocBase instance with unified subscription management
|
|
453
404
|
*/
|
|
454
|
-
|
|
455
|
-
/* Excluded from this release type: _instanceRef */
|
|
456
|
-
/* Excluded from this release type: _keepAlive */
|
|
405
|
+
constructor(initialState: S);
|
|
457
406
|
/**
|
|
458
|
-
*
|
|
459
|
-
* Timestamp when this Bloc instance was created, useful for debugging and performance tracking.
|
|
407
|
+
* Returns the current state
|
|
460
408
|
*/
|
|
461
|
-
|
|
462
|
-
/* Excluded from this release type: _disposalState */
|
|
463
|
-
/* Excluded from this release type: _disposalRequestTime */
|
|
464
|
-
/* Excluded from this release type: _state */
|
|
465
|
-
/* Excluded from this release type: _oldState */
|
|
409
|
+
get state(): S;
|
|
466
410
|
/**
|
|
467
|
-
*
|
|
468
|
-
* Can be used to configure or parameterize the Bloc's behavior.
|
|
411
|
+
* Subscribe to all state changes
|
|
469
412
|
*/
|
|
470
|
-
|
|
471
|
-
/* Excluded from this release type: _batchingLock */
|
|
472
|
-
/* Excluded from this release type: _pendingUpdates */
|
|
473
|
-
/* Excluded from this release type: _consumerRefs */
|
|
413
|
+
subscribe(callback: (state: S) => void): () => void;
|
|
474
414
|
/**
|
|
475
|
-
*
|
|
415
|
+
* Subscribe with a selector for optimized updates
|
|
476
416
|
*/
|
|
477
|
-
|
|
478
|
-
/* Excluded from this release type: _validateConsumers */
|
|
417
|
+
subscribeWithSelector<T>(selector: (state: S) => T, callback: (value: T) => void, equalityFn?: (a: T, b: T) => boolean): () => void;
|
|
479
418
|
/**
|
|
480
|
-
*
|
|
481
|
-
* Sets up the observer, registers with the Blac manager, and initializes addons.
|
|
482
|
-
*
|
|
483
|
-
* @param initialState The initial state value for this Bloc
|
|
419
|
+
* Subscribe with React component reference for automatic cleanup
|
|
484
420
|
*/
|
|
485
|
-
|
|
421
|
+
subscribeComponent(componentRef: WeakRef<object>, callback: () => void): () => void;
|
|
486
422
|
/**
|
|
487
|
-
*
|
|
488
|
-
* Use this getter to access the state in a read-only manner.
|
|
489
|
-
* Returns the state even during transitional lifecycle states for React compatibility.
|
|
423
|
+
* Get current subscription count
|
|
490
424
|
*/
|
|
491
|
-
get
|
|
425
|
+
get subscriptionCount(): number;
|
|
492
426
|
/**
|
|
493
|
-
*
|
|
494
|
-
* @returns true if the bloc is in DISPOSED state
|
|
427
|
+
* Track property access for a subscription
|
|
495
428
|
*/
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
/* Excluded from this release type: _atomicStateTransition */
|
|
500
|
-
/* Excluded from this release type: _dispose */
|
|
501
|
-
/* Excluded from this release type: onDispose */
|
|
502
|
-
/* Excluded from this release type: _consumers */
|
|
503
|
-
/* Excluded from this release type: _addConsumer */
|
|
504
|
-
/* Excluded from this release type: _removeConsumer */
|
|
505
|
-
/* Excluded from this release type: _disposalHandler */
|
|
506
|
-
/* Excluded from this release type: _setDisposalHandler */
|
|
507
|
-
/* Excluded from this release type: _scheduleDisposal */
|
|
508
|
-
lastUpdate: number;
|
|
509
|
-
/* Excluded from this release type: _batchingEnabled */
|
|
510
|
-
/* Excluded from this release type: _pushState */
|
|
511
|
-
/* Excluded from this release type: _notifyObservers */
|
|
512
|
-
/**
|
|
513
|
-
* Enables batching for multiple state updates
|
|
514
|
-
* @param batchFn Function to execute with batching enabled
|
|
515
|
-
*/
|
|
516
|
-
batch: <T>(batchFn: () => T) => T;
|
|
517
|
-
/**
|
|
518
|
-
* Add a plugin to this bloc instance
|
|
429
|
+
trackAccess(subscriptionId: string, path: string, value?: unknown): void;
|
|
430
|
+
/**
|
|
431
|
+
* Emit a new state
|
|
519
432
|
*/
|
|
520
|
-
|
|
433
|
+
protected emit(newState: S, action?: unknown): void;
|
|
521
434
|
/**
|
|
522
|
-
*
|
|
435
|
+
* Internal state push method used by Bloc
|
|
523
436
|
*/
|
|
524
|
-
|
|
437
|
+
_pushState(newState: S, oldState: S, action?: unknown): void;
|
|
438
|
+
_batchUpdates(callback: () => void): void;
|
|
525
439
|
/**
|
|
526
|
-
*
|
|
440
|
+
* Add a plugin
|
|
527
441
|
*/
|
|
528
|
-
|
|
442
|
+
addPlugin(plugin: BlocPlugin<S, any>): void;
|
|
443
|
+
/**
|
|
444
|
+
* Remove a plugin
|
|
445
|
+
*/
|
|
446
|
+
removePlugin(plugin: BlocPlugin<S, any>): void;
|
|
529
447
|
/**
|
|
530
448
|
* Get all plugins
|
|
531
449
|
*/
|
|
532
|
-
|
|
533
|
-
|
|
450
|
+
get plugins(): ReadonlyArray<BlocPlugin<S, any>>;
|
|
451
|
+
/**
|
|
452
|
+
* Disposal management
|
|
453
|
+
*/
|
|
454
|
+
get isDisposed(): boolean;
|
|
455
|
+
/**
|
|
456
|
+
* Atomic state transition for disposal
|
|
457
|
+
*/
|
|
458
|
+
_atomicStateTransition(expectedState: BlocLifecycleState, newState: BlocLifecycleState): StateTransitionResult;
|
|
459
|
+
/**
|
|
460
|
+
* Dispose the bloc and clean up resources
|
|
461
|
+
*/
|
|
462
|
+
dispose(): Promise<void>;
|
|
463
|
+
/**
|
|
464
|
+
* Schedule disposal when no subscriptions remain
|
|
465
|
+
*/
|
|
466
|
+
_scheduleDisposal(): void;
|
|
467
|
+
/**
|
|
468
|
+
* Set disposal handler
|
|
469
|
+
*/
|
|
470
|
+
setDisposalHandler(handler: (bloc: BlocBase<unknown>) => void): void;
|
|
471
|
+
/**
|
|
472
|
+
* Check if disposal should be scheduled (called by subscription manager)
|
|
473
|
+
*/
|
|
474
|
+
checkDisposal(): void;
|
|
475
|
+
/**
|
|
476
|
+
* Cancel disposal if bloc is in disposal_requested state
|
|
477
|
+
*/
|
|
478
|
+
_cancelDisposalIfRequested(): void;
|
|
534
479
|
}
|
|
535
480
|
|
|
536
481
|
/**
|
|
537
482
|
* Represents the abstract base types for Bloc and Cubit
|
|
538
483
|
*/
|
|
539
|
-
export declare type BlocBaseAbstract = typeof Bloc<any, any
|
|
484
|
+
export declare type BlocBaseAbstract = typeof Bloc<any, any> | typeof Cubit<any>;
|
|
540
485
|
|
|
541
486
|
/**
|
|
542
487
|
* Represents a constructor type for a Bloc that takes no parameters
|
|
@@ -553,11 +498,7 @@ export declare type BlocConstructor<B> = (new (...args: any) => B) & {
|
|
|
553
498
|
keepAlive?: boolean;
|
|
554
499
|
};
|
|
555
500
|
|
|
556
|
-
|
|
557
|
-
* Extracts the constructor parameters type from a BlocBase
|
|
558
|
-
* @template B - The BlocBase type to extract the constructor parameters from
|
|
559
|
-
*/
|
|
560
|
-
export declare type BlocConstructorParameters<B extends BlocBase<any>> = BlocConstructor<B> extends new (...args: infer P) => B ? P : never;
|
|
501
|
+
export declare type BlocConstructorParams<B extends BlocConstructor<BlocBase<any>>> = ConstructorParameters<B>[0];
|
|
561
502
|
|
|
562
503
|
/**
|
|
563
504
|
* Error boundary interface for Bloc error handling
|
|
@@ -589,9 +530,45 @@ export declare type BlocHookDependencyArrayFn<S, I = any> = (currentState: S, pr
|
|
|
589
530
|
|
|
590
531
|
export declare type BlocInstanceId = string | number | undefined;
|
|
591
532
|
|
|
533
|
+
/**
|
|
534
|
+
* Manages the lifecycle state transitions for Bloc instances.
|
|
535
|
+
* Ensures atomic state transitions to prevent race conditions during disposal.
|
|
536
|
+
*/
|
|
537
|
+
export declare class BlocLifecycleManager {
|
|
538
|
+
private disposalState;
|
|
539
|
+
private disposalLock;
|
|
540
|
+
private disposalTimer?;
|
|
541
|
+
private disposalHandler?;
|
|
542
|
+
get currentState(): BlocLifecycleState;
|
|
543
|
+
get isDisposed(): boolean;
|
|
544
|
+
/**
|
|
545
|
+
* Atomic state transition for disposal
|
|
546
|
+
*/
|
|
547
|
+
atomicStateTransition(expectedState: BlocLifecycleState, newState: BlocLifecycleState): StateTransitionResult;
|
|
548
|
+
/**
|
|
549
|
+
* Schedule disposal after a delay
|
|
550
|
+
*/
|
|
551
|
+
scheduleDisposal(delay: number, canDispose: () => boolean, onDispose: () => void): void;
|
|
552
|
+
/**
|
|
553
|
+
* Cancel disposal if in disposal requested state
|
|
554
|
+
*/
|
|
555
|
+
cancelDisposal(): boolean;
|
|
556
|
+
/**
|
|
557
|
+
* Set disposal handler
|
|
558
|
+
*/
|
|
559
|
+
setDisposalHandler(handler: (bloc: unknown) => void): void;
|
|
560
|
+
/**
|
|
561
|
+
* Get disposal handler
|
|
562
|
+
*/
|
|
563
|
+
getDisposalHandler(): ((bloc: unknown) => void) | undefined;
|
|
564
|
+
/**
|
|
565
|
+
* Clear disposal timer
|
|
566
|
+
*/
|
|
567
|
+
clearDisposalTimer(): void;
|
|
568
|
+
}
|
|
569
|
+
|
|
592
570
|
/**
|
|
593
571
|
* Enum representing the lifecycle states of a Bloc instance
|
|
594
|
-
* Used for atomic state transitions to prevent race conditions
|
|
595
572
|
*/
|
|
596
573
|
export declare enum BlocLifecycleState {
|
|
597
574
|
ACTIVE = "active",
|
|
@@ -606,7 +583,7 @@ export declare enum BlocLifecycleState {
|
|
|
606
583
|
export declare interface BlocPlugin<TState = any, TEvent = never> extends Plugin_2 {
|
|
607
584
|
transformState?(previousState: TState, nextState: TState): TState;
|
|
608
585
|
transformEvent?(event: TEvent): TEvent | null;
|
|
609
|
-
onAttach?(bloc: BlocBase<TState
|
|
586
|
+
onAttach?(bloc: BlocBase<TState>): void;
|
|
610
587
|
onDetach?(): void;
|
|
611
588
|
onStateChange?(previousState: TState, currentState: TState): void;
|
|
612
589
|
onEvent?(event: TEvent): void;
|
|
@@ -616,14 +593,14 @@ export declare interface BlocPlugin<TState = any, TEvent = never> extends Plugin
|
|
|
616
593
|
/**
|
|
617
594
|
* Registry for bloc-specific plugins
|
|
618
595
|
*/
|
|
619
|
-
export declare class BlocPluginRegistry<TState, TEvent = never> implements
|
|
596
|
+
export declare class BlocPluginRegistry<TState, TEvent = never> implements PluginRegistry<BlocPlugin<TState, TEvent>> {
|
|
620
597
|
private plugins;
|
|
621
598
|
private executionOrder;
|
|
622
599
|
private attached;
|
|
623
600
|
/**
|
|
624
601
|
* Add a bloc plugin
|
|
625
602
|
*/
|
|
626
|
-
add(plugin:
|
|
603
|
+
add(plugin: BlocPlugin<TState, TEvent>): void;
|
|
627
604
|
/**
|
|
628
605
|
* Remove a bloc plugin
|
|
629
606
|
*/
|
|
@@ -631,11 +608,11 @@ export declare class BlocPluginRegistry<TState, TEvent = never> implements Plugi
|
|
|
631
608
|
/**
|
|
632
609
|
* Get a plugin by name
|
|
633
610
|
*/
|
|
634
|
-
get(pluginName: string):
|
|
611
|
+
get(pluginName: string): BlocPlugin<TState, TEvent> | undefined;
|
|
635
612
|
/**
|
|
636
613
|
* Get all plugins in execution order
|
|
637
614
|
*/
|
|
638
|
-
getAll(): ReadonlyArray<
|
|
615
|
+
getAll(): ReadonlyArray<BlocPlugin<TState, TEvent>>;
|
|
639
616
|
/**
|
|
640
617
|
* Clear all plugins
|
|
641
618
|
*/
|
|
@@ -663,7 +640,7 @@ export declare class BlocPluginRegistry<TState, TEvent = never> implements Plugi
|
|
|
663
640
|
/**
|
|
664
641
|
* Notify plugins of error
|
|
665
642
|
*/
|
|
666
|
-
notifyError(error: Error, context:
|
|
643
|
+
notifyError(error: Error, context: ErrorContext): void;
|
|
667
644
|
private validateCapabilities;
|
|
668
645
|
private canReadState;
|
|
669
646
|
private canTransformState;
|
|
@@ -703,61 +680,26 @@ export declare class BlocTest {
|
|
|
703
680
|
static expectStates<T extends BlocBase<S>, S>(bloc: T, expectedStates: S[], timeout?: number): Promise<void>;
|
|
704
681
|
}
|
|
705
682
|
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
lastNotified: number;
|
|
709
|
-
hasRendered: boolean;
|
|
710
|
-
stateAccesses: Set<string>;
|
|
711
|
-
classAccesses: Set<string>;
|
|
712
|
-
stateValues: Map<string, TrackedValue>;
|
|
713
|
-
classValues: Map<string, TrackedValue>;
|
|
714
|
-
accessCount: number;
|
|
715
|
-
lastAccessTime: number;
|
|
716
|
-
firstAccessTime: number;
|
|
683
|
+
declare interface ConsumerTracker {
|
|
684
|
+
trackAccess: (consumerRef: object, type: 'state' | 'class', path: string, value?: any) => void;
|
|
717
685
|
}
|
|
718
686
|
|
|
719
687
|
/**
|
|
720
|
-
*
|
|
721
|
-
* It uses a WeakMap for automatic garbage collection when consumers are no longer referenced.
|
|
688
|
+
* Creates a proxy for bloc instances that tracks getter access
|
|
722
689
|
*/
|
|
723
|
-
export declare
|
|
724
|
-
private consumers;
|
|
725
|
-
private registrationCount;
|
|
726
|
-
private activeConsumers;
|
|
727
|
-
register(consumerRef: object, consumerId: string): void;
|
|
728
|
-
unregister(consumerRef: object): void;
|
|
729
|
-
trackAccess(consumerRef: object, type: 'state' | 'class', path: string, value?: any): void;
|
|
730
|
-
resetTracking(consumerRef: object): void;
|
|
731
|
-
getDependencies(consumerRef: object): DependencyArray | null;
|
|
732
|
-
hasValuesChanged(consumerRef: object, newState: any, newBlocInstance: any): boolean;
|
|
733
|
-
shouldNotifyConsumer(consumerRef: object, changedPaths: Set<string>): boolean;
|
|
734
|
-
updateLastNotified(consumerRef: object): void;
|
|
735
|
-
getConsumerInfo(consumerRef: object): ConsumerInfo | undefined;
|
|
736
|
-
setHasRendered(consumerRef: object, hasRendered: boolean): void;
|
|
737
|
-
hasConsumer(consumerRef: object): boolean;
|
|
738
|
-
getStats(): {
|
|
739
|
-
totalRegistrations: number;
|
|
740
|
-
activeConsumers: number;
|
|
741
|
-
};
|
|
742
|
-
private getValueAtPath;
|
|
743
|
-
}
|
|
690
|
+
export declare const createBlocProxy: <T extends object>(target: T, consumerRef: object, consumerTracker: ConsumerTracker) => T;
|
|
744
691
|
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
692
|
+
/**
|
|
693
|
+
* Creates a proxy for state objects that tracks property access
|
|
694
|
+
*/
|
|
695
|
+
export declare const createStateProxy: <T extends object>(target: T, consumerRef: object, consumerTracker: ConsumerTracker, path?: string) => T;
|
|
748
696
|
|
|
749
697
|
/**
|
|
750
698
|
* A Cubit is a simpler version of a Bloc that doesn't handle events.
|
|
751
699
|
* It manages state and provides methods to update it.
|
|
752
700
|
* @template S - The type of state this Cubit manages
|
|
753
|
-
* @template P - The type of parameters (optional, defaults to null)
|
|
754
701
|
*/
|
|
755
|
-
export declare abstract class Cubit<S
|
|
756
|
-
/* Excluded from this release type: _updateProps */
|
|
757
|
-
/**
|
|
758
|
-
* Optional override for props handling
|
|
759
|
-
*/
|
|
760
|
-
protected onPropsChanged?(oldProps: P | undefined, newProps: P): void;
|
|
702
|
+
export declare abstract class Cubit<S> extends BlocBase<S> {
|
|
761
703
|
/**
|
|
762
704
|
* Updates the current state and notifies all observers of the change.
|
|
763
705
|
* If the new state is identical to the current state (using Object.is),
|
|
@@ -776,12 +718,16 @@ export declare abstract class Cubit<S, P = null> extends BlocBase<S, P> {
|
|
|
776
718
|
patch(statePatch: S extends object ? Partial<S> : S, ignoreChangeCheck?: boolean): void;
|
|
777
719
|
}
|
|
778
720
|
|
|
779
|
-
export declare
|
|
780
|
-
statePaths: string[];
|
|
781
|
-
classPaths: string[];
|
|
782
|
-
}
|
|
721
|
+
export declare const DefaultErrorStrategy: ErrorHandlingStrategy;
|
|
783
722
|
|
|
784
|
-
declare
|
|
723
|
+
export declare enum ErrorCategory {
|
|
724
|
+
LIFECYCLE = "LIFECYCLE",
|
|
725
|
+
STATE = "STATE",
|
|
726
|
+
PLUGIN = "PLUGIN",
|
|
727
|
+
VALIDATION = "VALIDATION",
|
|
728
|
+
DISPOSAL = "DISPOSAL",
|
|
729
|
+
CONSUMER = "CONSUMER"
|
|
730
|
+
}
|
|
785
731
|
|
|
786
732
|
/**
|
|
787
733
|
* Error context provided to error handlers
|
|
@@ -792,6 +738,70 @@ export declare interface ErrorContext {
|
|
|
792
738
|
readonly metadata?: Record<string, unknown>;
|
|
793
739
|
}
|
|
794
740
|
|
|
741
|
+
export declare type ErrorHandler = (error: BlacError) => void;
|
|
742
|
+
|
|
743
|
+
export declare type ErrorHandlingStrategy = {
|
|
744
|
+
shouldPropagate: (error: BlacError) => boolean;
|
|
745
|
+
shouldLog: (error: BlacError) => boolean;
|
|
746
|
+
handle: (error: BlacError) => void;
|
|
747
|
+
};
|
|
748
|
+
|
|
749
|
+
/**
|
|
750
|
+
* Centralized error management system for BlaC framework.
|
|
751
|
+
* Handles error processing, logging, and propagation strategies.
|
|
752
|
+
*/
|
|
753
|
+
export declare class ErrorManager {
|
|
754
|
+
private static instance;
|
|
755
|
+
private handlers;
|
|
756
|
+
private strategy;
|
|
757
|
+
/**
|
|
758
|
+
* Get the singleton instance of ErrorManager
|
|
759
|
+
*/
|
|
760
|
+
static getInstance(): ErrorManager;
|
|
761
|
+
/**
|
|
762
|
+
* Set a custom error handling strategy
|
|
763
|
+
*/
|
|
764
|
+
setStrategy(strategy: ErrorHandlingStrategy): void;
|
|
765
|
+
/**
|
|
766
|
+
* Add a custom error handler that will be called for all errors
|
|
767
|
+
*/
|
|
768
|
+
addHandler(handler: ErrorHandler): void;
|
|
769
|
+
/**
|
|
770
|
+
* Remove a previously added error handler
|
|
771
|
+
*/
|
|
772
|
+
removeHandler(handler: ErrorHandler): void;
|
|
773
|
+
/**
|
|
774
|
+
* Process an error through all handlers and apply the configured strategy
|
|
775
|
+
*/
|
|
776
|
+
handle(error: BlacError): void;
|
|
777
|
+
/**
|
|
778
|
+
* Convenience method for wrapping operations with error handling
|
|
779
|
+
*/
|
|
780
|
+
wrap<T>(operation: () => T, errorFactory: (error: unknown) => BlacError): T;
|
|
781
|
+
/**
|
|
782
|
+
* Async version of wrap
|
|
783
|
+
*/
|
|
784
|
+
wrapAsync<T>(operation: () => Promise<T>, errorFactory: (error: unknown) => BlacError): Promise<T>;
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
export declare enum ErrorSeverity {
|
|
788
|
+
FATAL = "FATAL",// System cannot continue
|
|
789
|
+
ERROR = "ERROR",// Operation failed but system continues
|
|
790
|
+
WARNING = "WARNING",// Potential issue but operation succeeded
|
|
791
|
+
INFO = "INFO"
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
/**
|
|
795
|
+
* Generates a deterministic instance ID from static props by extracting primitive values
|
|
796
|
+
*
|
|
797
|
+
* Rules:
|
|
798
|
+
* 1. Only considers primitive types: string, number, boolean, null, undefined
|
|
799
|
+
* 2. Ignores complex types: objects, arrays, functions, symbols
|
|
800
|
+
* 3. Sorts keys alphabetically for deterministic output
|
|
801
|
+
* 4. Returns undefined if no primitives found (caller should use default ID)
|
|
802
|
+
*/
|
|
803
|
+
export declare function generateInstanceIdFromProps(props: unknown): string | undefined;
|
|
804
|
+
|
|
795
805
|
/**
|
|
796
806
|
* Cross-platform UUID v4 generator that works in all environments including React Native/Hermes
|
|
797
807
|
* Falls back to crypto.randomUUID() when available, otherwise uses Math.random()
|
|
@@ -805,7 +815,7 @@ export declare function generateUUID(): string;
|
|
|
805
815
|
export declare interface GetBlocOptions<B extends BlocBase<unknown>> {
|
|
806
816
|
id?: string;
|
|
807
817
|
selector?: BlocHookDependencyArrayFn<BlocState<B>>;
|
|
808
|
-
|
|
818
|
+
constructorParams?: ConstructorParameters<BlocConstructor<B>>[];
|
|
809
819
|
onMount?: (bloc: B) => void;
|
|
810
820
|
instanceRef?: string;
|
|
811
821
|
throwIfNotFound?: boolean;
|
|
@@ -814,10 +824,27 @@ export declare interface GetBlocOptions<B extends BlocBase<unknown>> {
|
|
|
814
824
|
}
|
|
815
825
|
|
|
816
826
|
/**
|
|
817
|
-
*
|
|
818
|
-
*
|
|
827
|
+
* Standard error handling helper for BlaC
|
|
828
|
+
*
|
|
829
|
+
* Usage:
|
|
830
|
+
* - For fatal errors that should propagate: handleError.fatal(...)
|
|
831
|
+
* - For recoverable errors: handleError.error(...)
|
|
832
|
+
* - For warnings: handleError.warn(...)
|
|
819
833
|
*/
|
|
820
|
-
export declare
|
|
834
|
+
export declare const handleError: {
|
|
835
|
+
fatal: (message: string, category: ErrorCategory, context?: BlacErrorContext, cause?: unknown) => never;
|
|
836
|
+
error: (message: string, category: ErrorCategory, context?: BlacErrorContext, cause?: unknown) => void;
|
|
837
|
+
warn: (message: string, category: ErrorCategory, context?: BlacErrorContext, cause?: unknown) => void;
|
|
838
|
+
info: (message: string, category: ErrorCategory, context?: BlacErrorContext) => void;
|
|
839
|
+
/**
|
|
840
|
+
* Wraps a function to catch and handle errors
|
|
841
|
+
*/
|
|
842
|
+
wrap: <T>(fn: () => T, category: ErrorCategory, context?: BlacErrorContext, severity?: ErrorSeverity) => T | undefined;
|
|
843
|
+
/**
|
|
844
|
+
* Wraps an async function to catch and handle errors
|
|
845
|
+
*/
|
|
846
|
+
wrapAsync: <T>(fn: () => Promise<T>, category: ErrorCategory, context?: BlacErrorContext, severity?: ErrorSeverity) => Promise<T | undefined>;
|
|
847
|
+
};
|
|
821
848
|
|
|
822
849
|
/**
|
|
823
850
|
* Memory leak detector for tests
|
|
@@ -929,35 +956,42 @@ export declare interface PluginRegistry<T extends Plugin_2> {
|
|
|
929
956
|
clear(): void;
|
|
930
957
|
}
|
|
931
958
|
|
|
959
|
+
/**
|
|
960
|
+
* Event fired when props are updated on a Bloc or Cubit instance.
|
|
961
|
+
* This is primarily used internally by the framework to notify
|
|
962
|
+
* about prop changes in React components.
|
|
963
|
+
* @template P - The type of props being updated
|
|
964
|
+
*/
|
|
932
965
|
export declare class PropsUpdated<P = any> {
|
|
933
966
|
readonly props: P;
|
|
934
967
|
constructor(props: P);
|
|
935
968
|
}
|
|
936
969
|
|
|
937
|
-
export declare
|
|
938
|
-
|
|
939
|
-
target:
|
|
970
|
+
export declare const ProxyFactory: {
|
|
971
|
+
createStateProxy: (options: {
|
|
972
|
+
target: any;
|
|
940
973
|
consumerRef: object;
|
|
941
|
-
consumerTracker:
|
|
974
|
+
consumerTracker: ConsumerTracker;
|
|
942
975
|
path?: string;
|
|
943
|
-
})
|
|
944
|
-
|
|
945
|
-
target:
|
|
976
|
+
}) => any;
|
|
977
|
+
createClassProxy: (options: {
|
|
978
|
+
target: any;
|
|
946
979
|
consumerRef: object;
|
|
947
|
-
consumerTracker:
|
|
948
|
-
})
|
|
949
|
-
|
|
950
|
-
state:
|
|
980
|
+
consumerTracker: ConsumerTracker;
|
|
981
|
+
}) => any;
|
|
982
|
+
getProxyState: <B extends BlocBase<any>>(options: {
|
|
983
|
+
state: any;
|
|
951
984
|
consumerRef: object;
|
|
952
|
-
consumerTracker:
|
|
953
|
-
})
|
|
954
|
-
|
|
985
|
+
consumerTracker: ConsumerTracker;
|
|
986
|
+
}) => any;
|
|
987
|
+
getProxyBlocInstance: <B extends BlocBase<any>>(options: {
|
|
955
988
|
blocInstance: B;
|
|
956
989
|
consumerRef: object;
|
|
957
|
-
consumerTracker:
|
|
958
|
-
})
|
|
959
|
-
|
|
960
|
-
|
|
990
|
+
consumerTracker: ConsumerTracker;
|
|
991
|
+
}) => B;
|
|
992
|
+
getStats: () => {
|
|
993
|
+
propertyAccesses: number;
|
|
994
|
+
nestedProxiesCreated: number;
|
|
961
995
|
cacheEfficiency: string;
|
|
962
996
|
lifetime: string;
|
|
963
997
|
proxiesPerSecond: string;
|
|
@@ -965,12 +999,71 @@ export declare class ProxyFactory {
|
|
|
965
999
|
classProxiesCreated: number;
|
|
966
1000
|
cacheHits: number;
|
|
967
1001
|
cacheMisses: number;
|
|
968
|
-
propertyAccesses: number;
|
|
969
|
-
nestedProxiesCreated: number;
|
|
970
1002
|
totalProxiesCreated: number;
|
|
971
|
-
createdAt: number;
|
|
972
1003
|
};
|
|
973
|
-
|
|
1004
|
+
resetStats: () => void;
|
|
1005
|
+
};
|
|
1006
|
+
|
|
1007
|
+
export declare interface RerenderInfo {
|
|
1008
|
+
componentName: string;
|
|
1009
|
+
blocName: string;
|
|
1010
|
+
blocId: string;
|
|
1011
|
+
renderCount: number;
|
|
1012
|
+
reason: RerenderReason;
|
|
1013
|
+
timestamp: number;
|
|
1014
|
+
duration?: number;
|
|
1015
|
+
stackTrace?: string;
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
/**
|
|
1019
|
+
* Utility class for logging component rerenders with detailed debugging information
|
|
1020
|
+
*/
|
|
1021
|
+
export declare class RerenderLogger {
|
|
1022
|
+
private static componentRenderCounts;
|
|
1023
|
+
private static lastRenderTimestamps;
|
|
1024
|
+
private static groupedLogs;
|
|
1025
|
+
private static groupTimeouts;
|
|
1026
|
+
/**
|
|
1027
|
+
* Log a component rerender with detailed information
|
|
1028
|
+
*/
|
|
1029
|
+
static logRerender(info: RerenderInfo): void;
|
|
1030
|
+
/**
|
|
1031
|
+
* Parse the logging configuration
|
|
1032
|
+
*/
|
|
1033
|
+
private static parseConfig;
|
|
1034
|
+
/**
|
|
1035
|
+
* Log immediately without grouping
|
|
1036
|
+
*/
|
|
1037
|
+
private static logImmediate;
|
|
1038
|
+
/**
|
|
1039
|
+
* Log with grouping (batch multiple rerenders)
|
|
1040
|
+
*/
|
|
1041
|
+
private static logGrouped;
|
|
1042
|
+
/**
|
|
1043
|
+
* Format the log message based on level
|
|
1044
|
+
*/
|
|
1045
|
+
private static formatMessage;
|
|
1046
|
+
/**
|
|
1047
|
+
* Get emoji for reason type
|
|
1048
|
+
*/
|
|
1049
|
+
private static getReasonEmoji;
|
|
1050
|
+
/**
|
|
1051
|
+
* Clear all tracking data
|
|
1052
|
+
*/
|
|
1053
|
+
static clear(): void;
|
|
1054
|
+
/**
|
|
1055
|
+
* Get render count for a component
|
|
1056
|
+
*/
|
|
1057
|
+
static getRenderCount(componentName: string, blocId: string): number;
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
export declare interface RerenderReason {
|
|
1061
|
+
type: 'state-change' | 'dependency-change' | 'mount' | 'props-change' | 'unknown';
|
|
1062
|
+
changedPaths?: string[];
|
|
1063
|
+
oldValues?: Record<string, any>;
|
|
1064
|
+
newValues?: Record<string, any>;
|
|
1065
|
+
dependencies?: string[];
|
|
1066
|
+
description?: string;
|
|
974
1067
|
}
|
|
975
1068
|
|
|
976
1069
|
/**
|
|
@@ -987,26 +1080,155 @@ export declare function setBlacInstanceManager(manager: BlacInstanceManager): vo
|
|
|
987
1080
|
*/
|
|
988
1081
|
export declare function shallowEqual(a: any, b: any): boolean;
|
|
989
1082
|
|
|
990
|
-
/**
|
|
991
|
-
* Result of an atomic state transition operation
|
|
992
|
-
*/
|
|
993
1083
|
export declare interface StateTransitionResult {
|
|
994
1084
|
success: boolean;
|
|
995
1085
|
currentState: BlocLifecycleState;
|
|
996
1086
|
previousState: BlocLifecycleState;
|
|
997
1087
|
}
|
|
998
1088
|
|
|
1089
|
+
/**
|
|
1090
|
+
* Unified subscription interface that replaces the dual consumer/observer system
|
|
1091
|
+
*/
|
|
1092
|
+
export declare interface Subscription<S = unknown> {
|
|
1093
|
+
/** Unique identifier for the subscription */
|
|
1094
|
+
id: string;
|
|
1095
|
+
/** Type of subscription for backward compatibility */
|
|
1096
|
+
type: 'consumer' | 'observer';
|
|
1097
|
+
/** Optional selector function to derive values from state */
|
|
1098
|
+
selector?: (state: S, bloc?: BlocBase<S>) => unknown;
|
|
1099
|
+
/** Custom equality function for selector results (defaults to Object.is) */
|
|
1100
|
+
equalityFn?: (prev: unknown, next: unknown) => boolean;
|
|
1101
|
+
/** Notification callback when state changes */
|
|
1102
|
+
notify: (value: unknown, oldValue?: unknown, action?: unknown) => void;
|
|
1103
|
+
/** Priority for notification order (higher = earlier) */
|
|
1104
|
+
priority?: number;
|
|
1105
|
+
/** WeakRef to the subscriber for automatic cleanup (React components) */
|
|
1106
|
+
weakRef?: WeakRef<object>;
|
|
1107
|
+
/** Last computed selector value for comparison */
|
|
1108
|
+
lastValue?: unknown;
|
|
1109
|
+
/** Tracked state path dependencies */
|
|
1110
|
+
dependencies?: Set<string>;
|
|
1111
|
+
/** Metadata for tracking and debugging */
|
|
1112
|
+
metadata?: SubscriptionMetadata;
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
/**
|
|
1116
|
+
* Unified subscription manager that replaces the dual consumer/observer system.
|
|
1117
|
+
* Handles all state change subscriptions with a single, consistent interface.
|
|
1118
|
+
*/
|
|
1119
|
+
export declare class SubscriptionManager<S = unknown> {
|
|
1120
|
+
private bloc;
|
|
1121
|
+
private subscriptions;
|
|
1122
|
+
private pathToSubscriptions;
|
|
1123
|
+
private weakRefCleanupScheduled;
|
|
1124
|
+
private totalNotifications;
|
|
1125
|
+
constructor(bloc: BlocBase<S>);
|
|
1126
|
+
/**
|
|
1127
|
+
* Subscribe to state changes
|
|
1128
|
+
*/
|
|
1129
|
+
subscribe(options: SubscriptionOptions<S>): () => void;
|
|
1130
|
+
/**
|
|
1131
|
+
* Unsubscribe by ID
|
|
1132
|
+
*/
|
|
1133
|
+
unsubscribe(id: string): void;
|
|
1134
|
+
/**
|
|
1135
|
+
* Notify all subscriptions of state change
|
|
1136
|
+
*/
|
|
1137
|
+
notify(newState: S, oldState: S, action?: unknown): void;
|
|
1138
|
+
/**
|
|
1139
|
+
* Track a path access for a subscription
|
|
1140
|
+
*/
|
|
1141
|
+
trackAccess(subscriptionId: string, path: string, value?: unknown): void;
|
|
1142
|
+
/**
|
|
1143
|
+
* Get the paths that changed between two states
|
|
1144
|
+
*/
|
|
1145
|
+
private getChangedPaths;
|
|
1146
|
+
/**
|
|
1147
|
+
* Check if a subscription should be notified based on changed paths
|
|
1148
|
+
*/
|
|
1149
|
+
shouldNotifyForPaths(subscriptionId: string, changedPaths: Set<string>): boolean;
|
|
1150
|
+
/**
|
|
1151
|
+
* Get statistics about subscriptions
|
|
1152
|
+
*/
|
|
1153
|
+
getStats(): SubscriptionManagerStats;
|
|
1154
|
+
/**
|
|
1155
|
+
* Clear all subscriptions
|
|
1156
|
+
*/
|
|
1157
|
+
clear(): void;
|
|
1158
|
+
/**
|
|
1159
|
+
* Get subscription by ID
|
|
1160
|
+
*/
|
|
1161
|
+
getSubscription(id: string): Subscription<S> | undefined;
|
|
1162
|
+
/**
|
|
1163
|
+
* Check if there are any active subscriptions
|
|
1164
|
+
*/
|
|
1165
|
+
get hasSubscriptions(): boolean;
|
|
1166
|
+
/**
|
|
1167
|
+
* Get count of active subscriptions
|
|
1168
|
+
*/
|
|
1169
|
+
get size(): number;
|
|
1170
|
+
/**
|
|
1171
|
+
* Clean up subscriptions with dead weak references
|
|
1172
|
+
*/
|
|
1173
|
+
private cleanupDeadReferences;
|
|
1174
|
+
/**
|
|
1175
|
+
* Schedule weak reference cleanup for next tick
|
|
1176
|
+
*/
|
|
1177
|
+
private scheduleWeakRefCleanup;
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
export declare interface SubscriptionManagerStats {
|
|
1181
|
+
/** Total number of active subscriptions */
|
|
1182
|
+
activeSubscriptions: number;
|
|
1183
|
+
/** Number of consumer subscriptions */
|
|
1184
|
+
consumerCount: number;
|
|
1185
|
+
/** Number of observer subscriptions */
|
|
1186
|
+
observerCount: number;
|
|
1187
|
+
/** Total notifications sent */
|
|
1188
|
+
totalNotifications: number;
|
|
1189
|
+
/** Number of tracked dependencies */
|
|
1190
|
+
trackedDependencies: number;
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
export declare interface SubscriptionMetadata {
|
|
1194
|
+
/** Timestamp of last notification */
|
|
1195
|
+
lastNotified?: number;
|
|
1196
|
+
/** Whether the subscriber has rendered (React-specific) */
|
|
1197
|
+
hasRendered?: boolean;
|
|
1198
|
+
/** Number of times this subscription accessed state */
|
|
1199
|
+
accessCount?: number;
|
|
1200
|
+
/** First access timestamp */
|
|
1201
|
+
firstAccessTime?: number;
|
|
1202
|
+
/** Last access timestamp */
|
|
1203
|
+
lastAccessTime?: number;
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
export declare interface SubscriptionOptions<S> {
|
|
1207
|
+
/** Type of subscription */
|
|
1208
|
+
type: 'consumer' | 'observer';
|
|
1209
|
+
/** Optional selector function */
|
|
1210
|
+
selector?: (state: S, bloc?: BlocBase<S>) => unknown;
|
|
1211
|
+
/** Custom equality function */
|
|
1212
|
+
equalityFn?: (prev: unknown, next: unknown) => boolean;
|
|
1213
|
+
/** Notification callback */
|
|
1214
|
+
notify: (value: unknown, oldValue?: unknown, action?: unknown) => void;
|
|
1215
|
+
/** Priority for notifications */
|
|
1216
|
+
priority?: number;
|
|
1217
|
+
/** WeakRef to subscriber */
|
|
1218
|
+
weakRef?: WeakRef<object>;
|
|
1219
|
+
}
|
|
1220
|
+
|
|
999
1221
|
/**
|
|
1000
1222
|
* Registry for system-wide plugins
|
|
1001
1223
|
*/
|
|
1002
|
-
export declare class SystemPluginRegistry implements
|
|
1224
|
+
export declare class SystemPluginRegistry implements PluginRegistry<BlacPlugin> {
|
|
1003
1225
|
private plugins;
|
|
1004
1226
|
private metrics;
|
|
1005
1227
|
private executionOrder;
|
|
1006
1228
|
/**
|
|
1007
1229
|
* Add a system plugin
|
|
1008
1230
|
*/
|
|
1009
|
-
add(plugin:
|
|
1231
|
+
add(plugin: BlacPlugin): void;
|
|
1010
1232
|
/**
|
|
1011
1233
|
* Remove a system plugin
|
|
1012
1234
|
*/
|
|
@@ -1014,11 +1236,11 @@ export declare class SystemPluginRegistry implements PluginRegistry_2<BlacPlugin
|
|
|
1014
1236
|
/**
|
|
1015
1237
|
* Get a plugin by name
|
|
1016
1238
|
*/
|
|
1017
|
-
get(pluginName: string):
|
|
1239
|
+
get(pluginName: string): BlacPlugin | undefined;
|
|
1018
1240
|
/**
|
|
1019
1241
|
* Get all plugins in execution order
|
|
1020
1242
|
*/
|
|
1021
|
-
getAll(): ReadonlyArray<
|
|
1243
|
+
getAll(): ReadonlyArray<BlacPlugin>;
|
|
1022
1244
|
/**
|
|
1023
1245
|
* Clear all plugins
|
|
1024
1246
|
*/
|
|
@@ -1026,7 +1248,7 @@ export declare class SystemPluginRegistry implements PluginRegistry_2<BlacPlugin
|
|
|
1026
1248
|
/**
|
|
1027
1249
|
* Execute a hook on all plugins
|
|
1028
1250
|
*/
|
|
1029
|
-
executeHook(hookName: keyof
|
|
1251
|
+
executeHook(hookName: keyof BlacPlugin, args: unknown[], errorHandler?: (error: Error, plugin: BlacPlugin) => void): void;
|
|
1030
1252
|
/**
|
|
1031
1253
|
* Bootstrap all plugins
|
|
1032
1254
|
*/
|
|
@@ -1054,21 +1276,24 @@ export declare class SystemPluginRegistry implements PluginRegistry_2<BlacPlugin
|
|
|
1054
1276
|
/**
|
|
1055
1277
|
* Notify plugins of errors
|
|
1056
1278
|
*/
|
|
1057
|
-
notifyError(error: Error, bloc: BlocBase<unknown>, context:
|
|
1279
|
+
notifyError(error: Error, bloc: BlocBase<unknown>, context: ErrorContext): void;
|
|
1280
|
+
/**
|
|
1281
|
+
* Notify plugins of adapter lifecycle events
|
|
1282
|
+
*/
|
|
1283
|
+
notifyAdapterCreated(adapter: any, metadata: AdapterMetadata): void;
|
|
1284
|
+
notifyAdapterMount(adapter: any, metadata: AdapterMetadata): void;
|
|
1285
|
+
notifyAdapterUnmount(adapter: any, metadata: AdapterMetadata): void;
|
|
1286
|
+
notifyAdapterRender(adapter: any, metadata: AdapterMetadata): void;
|
|
1287
|
+
notifyAdapterDisposed(adapter: any, metadata: AdapterMetadata): void;
|
|
1058
1288
|
/**
|
|
1059
1289
|
* Get metrics for a plugin
|
|
1060
1290
|
*/
|
|
1061
|
-
getMetrics(pluginName: string): Map<string,
|
|
1291
|
+
getMetrics(pluginName: string): Map<string, PluginMetrics> | undefined;
|
|
1062
1292
|
private initializeMetrics;
|
|
1063
1293
|
private recordSuccess;
|
|
1064
1294
|
private recordError;
|
|
1065
1295
|
}
|
|
1066
1296
|
|
|
1067
|
-
export declare interface TrackedValue {
|
|
1068
|
-
value: any;
|
|
1069
|
-
lastAccessTime: number;
|
|
1070
|
-
}
|
|
1071
|
-
|
|
1072
1297
|
/**
|
|
1073
1298
|
* Extracts the state type from a BlocBase instance
|
|
1074
1299
|
* @template B - The BlocBase type to extract the state from
|