@blac/core 2.0.0-rc.16 → 2.0.0-rc.17
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 +1041 -297
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +619 -224
- package/dist/index.d.ts +619 -224
- package/dist/index.js +986 -276
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,20 +1,52 @@
|
|
|
1
1
|
/* Excluded from this release type: __resetIdCounters */
|
|
2
2
|
|
|
3
|
+
export declare function acquire<T extends StateContainerConstructor>(BlocClass: T, instanceKey?: string, options?: AcquireOptions<T>): InstanceType<T>;
|
|
4
|
+
|
|
5
|
+
export declare interface AcquireOptions<T extends StateContainerConstructor> {
|
|
6
|
+
props?: ExtractProps<T>;
|
|
7
|
+
}
|
|
8
|
+
|
|
3
9
|
/**
|
|
4
10
|
* Internal state for framework adapters, holding tracking and caching data.
|
|
5
11
|
* @template TBloc - The state container type
|
|
6
12
|
*/
|
|
7
13
|
export declare interface AdapterState<TBloc extends StateContainerConstructor> {
|
|
8
|
-
/**
|
|
9
|
-
|
|
14
|
+
/** Dependency tracker for state property access tracking */
|
|
15
|
+
dependencyState: DependencyState<ExtractState<TBloc>> | null;
|
|
10
16
|
/** Cached manual dependencies for comparison */
|
|
11
17
|
manualDepsCache: unknown[] | null;
|
|
12
|
-
/** Getter
|
|
13
|
-
|
|
18
|
+
/** Getter state for computed property tracking */
|
|
19
|
+
getterState: GetterState | null;
|
|
14
20
|
/** Proxied bloc instance for auto-tracking */
|
|
15
21
|
proxiedBloc: InstanceState<TBloc> | null;
|
|
16
22
|
}
|
|
17
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Initialize adapter state for auto-tracking mode.
|
|
26
|
+
* Creates getter tracker and proxied bloc instance.
|
|
27
|
+
* @param instance - The state container instance
|
|
28
|
+
* @returns Initialized adapter state
|
|
29
|
+
*/
|
|
30
|
+
export declare function autoTrackInit<TBloc extends StateContainerConstructor>(instance: InstanceState<TBloc>): AdapterState<TBloc>;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Create a snapshot function for auto-tracking mode.
|
|
34
|
+
* Returns a proxied state that tracks property access.
|
|
35
|
+
* @param instance - The state container instance
|
|
36
|
+
* @param adapterState - The adapter state for tracking
|
|
37
|
+
* @returns Snapshot function for use with useSyncExternalStore
|
|
38
|
+
*/
|
|
39
|
+
export declare function autoTrackSnapshot<TBloc extends StateContainerConstructor>(instance: InstanceReadonlyState<TBloc>, adapterState: AdapterState<TBloc>): SnapshotFunction<ExtractState<TBloc>>;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Create a subscribe function for auto-tracking mode.
|
|
43
|
+
* Only triggers callback when tracked properties change.
|
|
44
|
+
* @param instance - The state container instance
|
|
45
|
+
* @param adapterState - The adapter state for tracking
|
|
46
|
+
* @returns Subscribe function for use with useSyncExternalStore
|
|
47
|
+
*/
|
|
48
|
+
export declare function autoTrackSubscribe<TBloc extends StateContainerConstructor>(instance: InstanceReadonlyState<TBloc>, adapterState: AdapterState<TBloc>): SubscribeFunction;
|
|
49
|
+
|
|
18
50
|
/**
|
|
19
51
|
* Decorator to configure StateContainer classes.
|
|
20
52
|
*
|
|
@@ -191,32 +223,56 @@ export declare interface BlacPluginWithInit extends BlacPlugin {
|
|
|
191
223
|
onInstall(context: PluginContext): void;
|
|
192
224
|
}
|
|
193
225
|
|
|
226
|
+
declare const BLOC_REF_MARKER: unique symbol;
|
|
227
|
+
|
|
194
228
|
/**
|
|
195
229
|
* Constructor type for StateContainer classes with static registry methods.
|
|
196
230
|
* Used for type-safe hook parameters.
|
|
197
231
|
* @template TBloc - The StateContainer instance type
|
|
198
232
|
*/
|
|
199
233
|
export declare type BlocConstructor<S extends object = any, T extends new (...args: any[]) => StateContainer<S, any> = new (...args: any[]) => StateContainer<S, any>> = (new (...args: any[]) => InstanceType<T>) & {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
234
|
+
acquire(instanceKey?: string, ...args: any[]): InstanceType<T>;
|
|
235
|
+
borrow(instanceKey?: string, ...args: any[]): InstanceType<T> | null;
|
|
236
|
+
borrowSafe(instanceKey?: string, ...args: any[]): {
|
|
203
237
|
error: Error;
|
|
204
238
|
instance: null;
|
|
205
239
|
} | {
|
|
206
240
|
error: null;
|
|
207
241
|
instance: InstanceType<T>;
|
|
208
242
|
};
|
|
243
|
+
ensure(instanceKey?: string): InstanceType<T>;
|
|
209
244
|
release(instanceKey?: string): void;
|
|
210
245
|
isolated?: boolean;
|
|
211
246
|
keepAlive?: boolean;
|
|
212
247
|
};
|
|
213
248
|
|
|
249
|
+
declare type BlocInput = StateContainerConstructor | BlocRef<StateContainerConstructor>;
|
|
250
|
+
|
|
214
251
|
/**
|
|
215
252
|
* Extract instance type from an abstract class constructor
|
|
216
253
|
* @template T - The abstract class constructor type
|
|
217
254
|
*/
|
|
218
255
|
export declare type BlocInstanceType<T extends abstract new (...args: any) => any> = T extends abstract new (...args: any) => infer R ? R : any;
|
|
219
256
|
|
|
257
|
+
/**
|
|
258
|
+
* Reference to a specific bloc instance by class and instance ID.
|
|
259
|
+
*/
|
|
260
|
+
export declare interface BlocRef<T extends StateContainerConstructor> {
|
|
261
|
+
[BLOC_REF_MARKER]: true;
|
|
262
|
+
blocClass: T;
|
|
263
|
+
instanceId: string;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export declare function borrow<T extends StateContainerConstructor>(BlocClass: T, instanceKey?: string): InstanceType<T>;
|
|
267
|
+
|
|
268
|
+
export declare function borrowSafe<T extends StateContainerConstructor>(BlocClass: T, instanceKey?: string): {
|
|
269
|
+
error: Error;
|
|
270
|
+
instance: null;
|
|
271
|
+
} | {
|
|
272
|
+
error: null;
|
|
273
|
+
instance: InstanceType<T>;
|
|
274
|
+
};
|
|
275
|
+
|
|
220
276
|
/**
|
|
221
277
|
* Utility type for creating branded/nominal types.
|
|
222
278
|
* Prevents accidental type confusion between similar primitive types.
|
|
@@ -235,10 +291,14 @@ declare const brand: unique symbol;
|
|
|
235
291
|
*/
|
|
236
292
|
export declare type BrandedId<B> = Brand<string, B>;
|
|
237
293
|
|
|
238
|
-
/* Excluded from this release type:
|
|
294
|
+
/* Excluded from this release type: capturePaths */
|
|
295
|
+
|
|
296
|
+
export declare function clear<T extends StateContainerConstructor>(BlocClass: T): void;
|
|
239
297
|
|
|
240
298
|
/* Excluded from this release type: clearActiveTracker */
|
|
241
299
|
|
|
300
|
+
export declare function clearAll(): void;
|
|
301
|
+
|
|
242
302
|
/* Excluded from this release type: clearExternalDependencies */
|
|
243
303
|
|
|
244
304
|
/* Excluded from this release type: commitTrackedGetters */
|
|
@@ -277,27 +337,15 @@ export declare function configureLogger(opts: Partial<LogConfig>): void;
|
|
|
277
337
|
|
|
278
338
|
/* Excluded from this release type: createArrayProxy */
|
|
279
339
|
|
|
280
|
-
|
|
281
|
-
* Create a snapshot function for auto-tracking mode.
|
|
282
|
-
* Returns a proxied state that tracks property access.
|
|
283
|
-
* @param instance - The state container instance
|
|
284
|
-
* @param adapterState - The adapter state for tracking
|
|
285
|
-
* @returns Snapshot function for use with useSyncExternalStore
|
|
286
|
-
*/
|
|
287
|
-
export declare function createAutoTrackSnapshot<TBloc extends StateContainerConstructor>(instance: InstanceReadonlyState<TBloc>, adapterState: AdapterState<TBloc>): SnapshotFunction<ExtractState<TBloc>>;
|
|
340
|
+
/* Excluded from this release type: createBlocProxy */
|
|
288
341
|
|
|
289
|
-
|
|
290
|
-
* Create a subscribe function for auto-tracking mode.
|
|
291
|
-
* Only triggers callback when tracked properties change.
|
|
292
|
-
* @param instance - The state container instance
|
|
293
|
-
* @param adapterState - The adapter state for tracking
|
|
294
|
-
* @returns Subscribe function for use with useSyncExternalStore
|
|
295
|
-
*/
|
|
296
|
-
export declare function createAutoTrackSubscribe<TBloc extends StateContainerConstructor>(instance: InstanceReadonlyState<TBloc>, adapterState: AdapterState<TBloc>): SubscribeFunction;
|
|
342
|
+
/* Excluded from this release type: createDependencyProxy */
|
|
297
343
|
|
|
298
|
-
/* Excluded from this release type:
|
|
344
|
+
/* Excluded from this release type: createDependencyState */
|
|
345
|
+
|
|
346
|
+
/* Excluded from this release type: createForTarget */
|
|
299
347
|
|
|
300
|
-
/* Excluded from this release type:
|
|
348
|
+
/* Excluded from this release type: createGetterState */
|
|
301
349
|
|
|
302
350
|
/**
|
|
303
351
|
* Centralized ID Generation
|
|
@@ -324,6 +372,8 @@ export declare function createIdGenerator(prefix: string): {
|
|
|
324
372
|
reset: () => void;
|
|
325
373
|
};
|
|
326
374
|
|
|
375
|
+
/* Excluded from this release type: createInternal */
|
|
376
|
+
|
|
327
377
|
/**
|
|
328
378
|
* Creates a logger instance with given configuration
|
|
329
379
|
*
|
|
@@ -349,57 +399,29 @@ export declare function createLogger(config: LogConfig): {
|
|
|
349
399
|
};
|
|
350
400
|
|
|
351
401
|
/**
|
|
352
|
-
* Create a
|
|
353
|
-
*
|
|
354
|
-
* @
|
|
355
|
-
* @param adapterState - The adapter state for caching
|
|
356
|
-
* @param config - Configuration with dependencies function
|
|
357
|
-
* @returns Snapshot function for use with useSyncExternalStore
|
|
402
|
+
* Create a plugin manager instance
|
|
403
|
+
* @param registry - The StateContainerRegistry to monitor for lifecycle events
|
|
404
|
+
* @returns A new PluginManager instance
|
|
358
405
|
*/
|
|
359
|
-
export declare function
|
|
406
|
+
export declare function createPluginManager(registry: StateContainerRegistry): PluginManager;
|
|
360
407
|
|
|
361
|
-
|
|
362
|
-
* Create a subscribe function for manual dependency tracking mode.
|
|
363
|
-
* Only triggers callback when dependencies array changes.
|
|
364
|
-
* @param instance - The state container instance
|
|
365
|
-
* @param adapterState - The adapter state for caching
|
|
366
|
-
* @param config - Configuration with dependencies function
|
|
367
|
-
* @returns Subscribe function for use with useSyncExternalStore
|
|
368
|
-
*/
|
|
369
|
-
export declare function createManualDepsSubscribe<TBloc extends StateContainerConstructor>(instance: InstanceState<TBloc>, adapterState: AdapterState<TBloc>, config: ManualDepsConfig<TBloc>): SubscribeFunction;
|
|
408
|
+
/* Excluded from this release type: createProxyState */
|
|
370
409
|
|
|
371
410
|
/**
|
|
372
|
-
* Create a
|
|
373
|
-
* Returns the raw state directly.
|
|
374
|
-
* @param instance - The state container instance
|
|
375
|
-
* @returns Snapshot function for use with useSyncExternalStore
|
|
411
|
+
* Create a new tracked context for manual control over tracking.
|
|
376
412
|
*/
|
|
377
|
-
export declare function
|
|
413
|
+
export declare function createTrackedContext(): TrackedContext;
|
|
378
414
|
|
|
379
415
|
/**
|
|
380
|
-
* Create a
|
|
381
|
-
*
|
|
382
|
-
* @param instance - The state container instance
|
|
383
|
-
* @returns Subscribe function for use with useSyncExternalStore
|
|
416
|
+
* Create a tracking proxy for a bloc instance.
|
|
417
|
+
* Tracks both state property access and getter access.
|
|
384
418
|
*/
|
|
385
|
-
export declare function
|
|
419
|
+
export declare function createTrackingProxy<T extends StateContainerInstance>(bloc: T, tracker: TrackingProxyState): T;
|
|
386
420
|
|
|
387
421
|
/**
|
|
388
|
-
* Create a
|
|
389
|
-
* @param registry - The StateContainerRegistry to monitor for lifecycle events
|
|
390
|
-
* @returns A new PluginManager instance
|
|
422
|
+
* Create a new tracking proxy state.
|
|
391
423
|
*/
|
|
392
|
-
export declare function
|
|
393
|
-
|
|
394
|
-
/* Excluded from this release type: createProxy */
|
|
395
|
-
|
|
396
|
-
/* Excluded from this release type: createProxyForTarget */
|
|
397
|
-
|
|
398
|
-
/* Excluded from this release type: createProxyInternal */
|
|
399
|
-
|
|
400
|
-
/* Excluded from this release type: createProxyTrackerState */
|
|
401
|
-
|
|
402
|
-
/* Excluded from this release type: createTrackerState */
|
|
424
|
+
export declare function createTrackingProxyState(): TrackingProxyState;
|
|
403
425
|
|
|
404
426
|
/**
|
|
405
427
|
* Simple state container with direct state emission.
|
|
@@ -434,6 +456,45 @@ export declare abstract class Cubit<S extends object = any, P = undefined> exten
|
|
|
434
456
|
*/
|
|
435
457
|
export declare const debug: (context: string, message: string, data?: any) => void;
|
|
436
458
|
|
|
459
|
+
/**
|
|
460
|
+
* Manages subscriptions to state container dependencies.
|
|
461
|
+
* Provides efficient sync mechanism to add/remove subscriptions
|
|
462
|
+
* as dependencies change between callback invocations.
|
|
463
|
+
*/
|
|
464
|
+
export declare class DependencyManager {
|
|
465
|
+
private subscriptions;
|
|
466
|
+
private currentDeps;
|
|
467
|
+
/**
|
|
468
|
+
* Sync subscriptions with a new set of dependencies.
|
|
469
|
+
* Adds subscriptions for new deps, removes subscriptions for stale deps.
|
|
470
|
+
*
|
|
471
|
+
* @param newDeps - The new set of dependencies to subscribe to
|
|
472
|
+
* @param onChange - Callback to invoke when any dependency changes
|
|
473
|
+
* @param exclude - Optional instance to exclude from subscriptions (e.g., primary bloc)
|
|
474
|
+
* @returns true if the dependency set changed, false if unchanged
|
|
475
|
+
*/
|
|
476
|
+
sync(newDeps: Set<StateContainerInstance>, onChange: () => void, exclude?: StateContainerInstance): boolean;
|
|
477
|
+
/**
|
|
478
|
+
* Add a single dependency subscription.
|
|
479
|
+
*/
|
|
480
|
+
add(dep: StateContainerInstance, onChange: () => void): void;
|
|
481
|
+
/**
|
|
482
|
+
* Check if a dependency is currently subscribed.
|
|
483
|
+
*/
|
|
484
|
+
has(dep: StateContainerInstance): boolean;
|
|
485
|
+
/**
|
|
486
|
+
* Get the current set of dependencies.
|
|
487
|
+
*/
|
|
488
|
+
getDependencies(): Set<StateContainerInstance>;
|
|
489
|
+
/**
|
|
490
|
+
* Clean up all active subscriptions.
|
|
491
|
+
*/
|
|
492
|
+
cleanup(): void;
|
|
493
|
+
private areSetsEqual;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/* Excluded from this release type: DependencyState */
|
|
497
|
+
|
|
437
498
|
/**
|
|
438
499
|
* Disable getter tracking after render phase completes.
|
|
439
500
|
* Clears the active tracker to prevent tracking outside of render.
|
|
@@ -457,6 +518,12 @@ export declare interface DiscriminatedEvent {
|
|
|
457
518
|
readonly type: string;
|
|
458
519
|
}
|
|
459
520
|
|
|
521
|
+
/* Excluded from this release type: EmptyState */
|
|
522
|
+
|
|
523
|
+
/* Excluded from this release type: EmptyState_2 */
|
|
524
|
+
|
|
525
|
+
export declare function ensure<T extends StateContainerConstructor>(BlocClass: T, instanceKey?: string): InstanceType<T>;
|
|
526
|
+
|
|
460
527
|
/**
|
|
461
528
|
* Log an error message (tree-shakeable export)
|
|
462
529
|
* @param context - Context identifier (module or component name)
|
|
@@ -510,11 +577,12 @@ export declare type EventType<E extends DiscriminatedEvent> = E['type'];
|
|
|
510
577
|
* Manages subscriptions to external bloc dependencies for getter tracking.
|
|
511
578
|
* When a getter accesses another bloc's state, this manager ensures
|
|
512
579
|
* re-renders occur when those external dependencies change.
|
|
580
|
+
*
|
|
581
|
+
* @deprecated Use DependencyManager from tracking module instead.
|
|
582
|
+
* This class is kept for backward compatibility.
|
|
513
583
|
*/
|
|
514
|
-
export declare class
|
|
515
|
-
private
|
|
516
|
-
private previousDeps;
|
|
517
|
-
private areDependenciesEqual;
|
|
584
|
+
export declare class ExternalDepsManager {
|
|
585
|
+
private manager;
|
|
518
586
|
/**
|
|
519
587
|
* Update subscriptions to external bloc dependencies.
|
|
520
588
|
* Creates subscriptions to blocs accessed via getters.
|
|
@@ -523,7 +591,7 @@ export declare class ExternalDependencyManager {
|
|
|
523
591
|
* @param onGetterChange - Callback to invoke when external dependency changes
|
|
524
592
|
* @returns true if subscriptions were updated, false if unchanged
|
|
525
593
|
*/
|
|
526
|
-
updateSubscriptions(
|
|
594
|
+
updateSubscriptions(getterState: GetterState | null, rawInstance: StateContainerInstance, onGetterChange: () => void): boolean;
|
|
527
595
|
/**
|
|
528
596
|
* Clean up all active subscriptions
|
|
529
597
|
*/
|
|
@@ -552,6 +620,12 @@ export declare type ExtractEvent<E extends DiscriminatedEvent, T extends EventTy
|
|
|
552
620
|
type: T;
|
|
553
621
|
}>;
|
|
554
622
|
|
|
623
|
+
declare type ExtractInstance<T> = T extends BlocRef<infer C> ? InstanceType<C> : T extends StateContainerConstructor ? InstanceType<T> : never;
|
|
624
|
+
|
|
625
|
+
declare type ExtractInstances<T extends readonly BlocInput[]> = {
|
|
626
|
+
[K in keyof T]: ExtractInstance<T[K]>;
|
|
627
|
+
};
|
|
628
|
+
|
|
555
629
|
/**
|
|
556
630
|
* Extract the props type from a StateContainer
|
|
557
631
|
* @template T - The StateContainer type
|
|
@@ -564,8 +638,16 @@ export declare type ExtractProps<T> = T extends StateContainerConstructor<any, i
|
|
|
564
638
|
*/
|
|
565
639
|
export declare type ExtractState<T> = T extends StateContainerConstructor<infer S, any> ? Readonly<S> : never;
|
|
566
640
|
|
|
641
|
+
/**
|
|
642
|
+
* Constrain a type to extract state only from stateful containers.
|
|
643
|
+
* Returns `never` for stateless containers.
|
|
644
|
+
*/
|
|
645
|
+
export declare type ExtractStatefulState<T extends StateContainerConstructor> = IsStatelessContainer<T> extends true ? never : ExtractState<T>;
|
|
646
|
+
|
|
567
647
|
export declare type ExtractStateMutable<T> = T extends StateContainerConstructor<infer S, any> ? S : never;
|
|
568
648
|
|
|
649
|
+
export declare function forEach<T extends StateContainerConstructor>(BlocClass: T, callback: (instance: InstanceReadonlyState<T>) => void): void;
|
|
650
|
+
|
|
569
651
|
/**
|
|
570
652
|
* Generate ID with timestamp, counter, and random suffix (tree-shakeable)
|
|
571
653
|
*
|
|
@@ -609,6 +691,8 @@ export declare function generateSimpleId(prefix: string, affix?: string): string
|
|
|
609
691
|
|
|
610
692
|
/* Excluded from this release type: getActiveTracker */
|
|
611
693
|
|
|
694
|
+
export declare function getAll<T extends StateContainerConstructor>(BlocClass: T): InstanceReadonlyState<T>[];
|
|
695
|
+
|
|
612
696
|
/* Excluded from this release type: getBlacConfig */
|
|
613
697
|
|
|
614
698
|
/* Excluded from this release type: getDescriptor */
|
|
@@ -620,6 +704,10 @@ export declare function generateSimpleId(prefix: string, affix?: string): string
|
|
|
620
704
|
*/
|
|
621
705
|
export declare function getPluginManager(): any;
|
|
622
706
|
|
|
707
|
+
export declare function getRefCount<T extends StateContainerConstructor>(BlocClass: T, instanceKey?: string): number;
|
|
708
|
+
|
|
709
|
+
export declare function getRegistry(): StateContainerRegistry;
|
|
710
|
+
|
|
623
711
|
/**
|
|
624
712
|
* Get a static property from a class constructor
|
|
625
713
|
* Type-safe helper that avoids (Type as any) casts
|
|
@@ -631,14 +719,20 @@ export declare function getPluginManager(): any;
|
|
|
631
719
|
*/
|
|
632
720
|
export declare function getStaticProp<V, T extends StateContainerConstructor = StateContainerConstructor>(Type: T, propName: string, defaultValue?: V): V | undefined;
|
|
633
721
|
|
|
722
|
+
export declare function getStats(): {
|
|
723
|
+
registeredTypes: number;
|
|
724
|
+
totalInstances: number;
|
|
725
|
+
typeBreakdown: Record<string, number>;
|
|
726
|
+
};
|
|
727
|
+
|
|
634
728
|
declare interface GetterExecutionContext {
|
|
635
|
-
tracker:
|
|
729
|
+
tracker: GetterState | null;
|
|
636
730
|
currentBloc: StateContainerInstance | null;
|
|
637
731
|
depth: number;
|
|
638
732
|
visitedBlocs: Set<StateContainerInstance>;
|
|
639
733
|
}
|
|
640
734
|
|
|
641
|
-
/* Excluded from this release type:
|
|
735
|
+
/* Excluded from this release type: GetterState */
|
|
642
736
|
|
|
643
737
|
/* Excluded from this release type: getValueAtPath */
|
|
644
738
|
|
|
@@ -647,7 +741,7 @@ declare interface GetterExecutionContext {
|
|
|
647
741
|
*/
|
|
648
742
|
export declare const globalRegistry: StateContainerRegistry;
|
|
649
743
|
|
|
650
|
-
/* Excluded from this release type:
|
|
744
|
+
/* Excluded from this release type: hasDependencyChanges */
|
|
651
745
|
|
|
652
746
|
/* Excluded from this release type: hasGetterChanges */
|
|
653
747
|
|
|
@@ -658,8 +752,15 @@ export declare const globalRegistry: StateContainerRegistry;
|
|
|
658
752
|
*/
|
|
659
753
|
export declare function hasInitHook(plugin: BlacPlugin): plugin is BlacPluginWithInit;
|
|
660
754
|
|
|
755
|
+
export declare function hasInstance<T extends StateContainerConstructor>(BlocClass: T, instanceKey?: string): boolean;
|
|
756
|
+
|
|
661
757
|
/* Excluded from this release type: hasTrackedData */
|
|
662
758
|
|
|
759
|
+
/**
|
|
760
|
+
* Check if tracked state or getters have changed.
|
|
761
|
+
*/
|
|
762
|
+
export declare function hasTrackingProxyChanges(tracker: TrackingProxyState, bloc: StateContainerInstance): boolean;
|
|
763
|
+
|
|
663
764
|
/**
|
|
664
765
|
* Log an info message (tree-shakeable export)
|
|
665
766
|
* @param context - Context identifier (module or component name)
|
|
@@ -669,28 +770,16 @@ export declare function hasInitHook(plugin: BlacPlugin): plugin is BlacPluginWit
|
|
|
669
770
|
export declare const info: (context: string, message: string, data?: any) => void;
|
|
670
771
|
|
|
671
772
|
/**
|
|
672
|
-
*
|
|
673
|
-
*
|
|
674
|
-
* @
|
|
675
|
-
*
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
* Initialize adapter state for manual dependency tracking mode.
|
|
681
|
-
* No proxy is created; bloc is used directly.
|
|
682
|
-
* @param instance - The state container instance
|
|
683
|
-
* @returns Initialized adapter state
|
|
684
|
-
*/
|
|
685
|
-
export declare function initManualDepsState<TBloc extends StateContainerConstructor>(instance: InstanceState<TBloc>): AdapterState<TBloc>;
|
|
686
|
-
|
|
687
|
-
/**
|
|
688
|
-
* Initialize adapter state for no-tracking mode.
|
|
689
|
-
* No tracking or proxy is created.
|
|
690
|
-
* @param instance - The state container instance
|
|
691
|
-
* @returns Initialized adapter state
|
|
773
|
+
* Create a reference to a specific bloc instance.
|
|
774
|
+
*
|
|
775
|
+
* @example
|
|
776
|
+
* ```ts
|
|
777
|
+
* watch(instance(UserBloc, 'user-123'), (userBloc) => {
|
|
778
|
+
* console.log(userBloc.state.name);
|
|
779
|
+
* });
|
|
780
|
+
* ```
|
|
692
781
|
*/
|
|
693
|
-
export declare function
|
|
782
|
+
export declare function instance<T extends StateContainerConstructor>(BlocClass: T, instanceId: string): BlocRef<T>;
|
|
694
783
|
|
|
695
784
|
/**
|
|
696
785
|
* Entry in the instance registry, tracking the instance and its reference count
|
|
@@ -786,6 +875,22 @@ export declare function isKeepAliveClass<T extends StateContainerConstructor>(Ty
|
|
|
786
875
|
|
|
787
876
|
/* Excluded from this release type: isProxyable */
|
|
788
877
|
|
|
878
|
+
/**
|
|
879
|
+
* Check if a class is a stateless container (StatelessCubit or StatelessVertex).
|
|
880
|
+
* Stateless containers don't have state, emit, update, or subscribe methods.
|
|
881
|
+
* @param Type - The class constructor to check
|
|
882
|
+
* @returns true if the class is a stateless container
|
|
883
|
+
*/
|
|
884
|
+
export declare function isStatelessClass<T extends StateContainerConstructor>(Type: T): boolean;
|
|
885
|
+
|
|
886
|
+
/**
|
|
887
|
+
* Check if a StateContainer constructor is a stateless container.
|
|
888
|
+
* Returns true for StatelessCubit and StatelessVertex classes.
|
|
889
|
+
*/
|
|
890
|
+
export declare type IsStatelessContainer<T> = T extends {
|
|
891
|
+
readonly [STATELESS_MARKER]: true;
|
|
892
|
+
} ? true : false;
|
|
893
|
+
|
|
789
894
|
/**
|
|
790
895
|
* Lifecycle events emitted by the registry
|
|
791
896
|
*/
|
|
@@ -848,6 +953,58 @@ export declare interface ManualDepsConfig<TBloc extends StateContainerConstructo
|
|
|
848
953
|
dependencies: (state: ExtractState<TBloc>, bloc: InstanceState<TBloc>) => any[];
|
|
849
954
|
}
|
|
850
955
|
|
|
956
|
+
/**
|
|
957
|
+
* Initialize adapter state for manual dependency tracking mode.
|
|
958
|
+
* No proxy is created; bloc is used directly.
|
|
959
|
+
* @param instance - The state container instance
|
|
960
|
+
* @returns Initialized adapter state
|
|
961
|
+
*/
|
|
962
|
+
export declare function manualDepsInit<TBloc extends StateContainerConstructor>(instance: InstanceState<TBloc>): AdapterState<TBloc>;
|
|
963
|
+
|
|
964
|
+
/**
|
|
965
|
+
* Create a snapshot function for manual dependency tracking mode.
|
|
966
|
+
* Caches dependencies for comparison on next render.
|
|
967
|
+
* @param instance - The state container instance
|
|
968
|
+
* @param adapterState - The adapter state for caching
|
|
969
|
+
* @param config - Configuration with dependencies function
|
|
970
|
+
* @returns Snapshot function for use with useSyncExternalStore
|
|
971
|
+
*/
|
|
972
|
+
export declare function manualDepsSnapshot<TBloc extends StateContainerConstructor>(instance: InstanceState<TBloc>, adapterState: AdapterState<TBloc>, config: ManualDepsConfig<TBloc>): SnapshotFunction<ExtractState<TBloc>>;
|
|
973
|
+
|
|
974
|
+
/**
|
|
975
|
+
* Create a subscribe function for manual dependency tracking mode.
|
|
976
|
+
* Only triggers callback when dependencies array changes.
|
|
977
|
+
* @param instance - The state container instance
|
|
978
|
+
* @param adapterState - The adapter state for caching
|
|
979
|
+
* @param config - Configuration with dependencies function
|
|
980
|
+
* @returns Subscribe function for use with useSyncExternalStore
|
|
981
|
+
*/
|
|
982
|
+
export declare function manualDepsSubscribe<TBloc extends StateContainerConstructor>(instance: InstanceState<TBloc>, adapterState: AdapterState<TBloc>, config: ManualDepsConfig<TBloc>): SubscribeFunction;
|
|
983
|
+
|
|
984
|
+
/**
|
|
985
|
+
* Initialize adapter state for no-tracking mode.
|
|
986
|
+
* No tracking or proxy is created.
|
|
987
|
+
* @param instance - The state container instance
|
|
988
|
+
* @returns Initialized adapter state
|
|
989
|
+
*/
|
|
990
|
+
export declare function noTrackInit<TBloc extends StateContainerConstructor>(instance: InstanceState<TBloc>): AdapterState<TBloc>;
|
|
991
|
+
|
|
992
|
+
/**
|
|
993
|
+
* Create a snapshot function for no-tracking mode.
|
|
994
|
+
* Returns the raw state directly.
|
|
995
|
+
* @param instance - The state container instance
|
|
996
|
+
* @returns Snapshot function for use with useSyncExternalStore
|
|
997
|
+
*/
|
|
998
|
+
export declare function noTrackSnapshot<TBloc extends StateContainerConstructor>(instance: InstanceReadonlyState<TBloc>): SnapshotFunction<ExtractState<TBloc>>;
|
|
999
|
+
|
|
1000
|
+
/**
|
|
1001
|
+
* Create a subscribe function for no-tracking mode.
|
|
1002
|
+
* Triggers callback on every state change.
|
|
1003
|
+
* @param instance - The state container instance
|
|
1004
|
+
* @returns Subscribe function for use with useSyncExternalStore
|
|
1005
|
+
*/
|
|
1006
|
+
export declare function noTrackSubscribe<TBloc extends StateContainerInstance>(instance: TBloc): SubscribeFunction;
|
|
1007
|
+
|
|
851
1008
|
/* Excluded from this release type: parsePath */
|
|
852
1009
|
|
|
853
1010
|
/* Excluded from this release type: PathInfo */
|
|
@@ -966,14 +1123,20 @@ export declare class PluginManager {
|
|
|
966
1123
|
private getCurrentEnvironment;
|
|
967
1124
|
}
|
|
968
1125
|
|
|
969
|
-
/* Excluded from this release type:
|
|
1126
|
+
/* Excluded from this release type: ProxyState */
|
|
1127
|
+
|
|
1128
|
+
export declare function register<T extends StateContainerConstructor>(BlocClass: T, isolated?: boolean): void;
|
|
1129
|
+
|
|
1130
|
+
export declare function release<T extends StateContainerConstructor>(BlocClass: T, instanceKey?: string, forceDispose?: boolean): void;
|
|
970
1131
|
|
|
971
1132
|
/* Excluded from this release type: resetBlacConfig */
|
|
972
1133
|
|
|
973
|
-
/* Excluded from this release type:
|
|
1134
|
+
/* Excluded from this release type: resetGetterState */
|
|
974
1135
|
|
|
975
1136
|
/* Excluded from this release type: setActiveTracker */
|
|
976
1137
|
|
|
1138
|
+
export declare function setRegistry(registry: StateContainerRegistry): void;
|
|
1139
|
+
|
|
977
1140
|
/* Excluded from this release type: shallowEqual */
|
|
978
1141
|
|
|
979
1142
|
/**
|
|
@@ -982,9 +1145,14 @@ export declare class PluginManager {
|
|
|
982
1145
|
*/
|
|
983
1146
|
export declare type SnapshotFunction<TState> = () => TState;
|
|
984
1147
|
|
|
985
|
-
/* Excluded from this release type:
|
|
1148
|
+
/* Excluded from this release type: startDependency */
|
|
986
1149
|
|
|
987
|
-
/* Excluded from this release type:
|
|
1150
|
+
/* Excluded from this release type: startProxy */
|
|
1151
|
+
|
|
1152
|
+
/**
|
|
1153
|
+
* Start tracking on a tracking proxy.
|
|
1154
|
+
*/
|
|
1155
|
+
export declare function startTrackingProxy(tracker: TrackingProxyState): void;
|
|
988
1156
|
|
|
989
1157
|
/**
|
|
990
1158
|
* Abstract base class for all state containers in BlaC.
|
|
@@ -1007,117 +1175,8 @@ export declare type SnapshotFunction<TState> = () => TState;
|
|
|
1007
1175
|
* ```
|
|
1008
1176
|
*/
|
|
1009
1177
|
export declare abstract class StateContainer<S extends object = any, P = any> {
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
/**
|
|
1013
|
-
* Get the global StateContainerRegistry
|
|
1014
|
-
* @returns The registry managing all state container instances
|
|
1015
|
-
*/
|
|
1016
|
-
static getRegistry(): StateContainerRegistry;
|
|
1017
|
-
/**
|
|
1018
|
-
* Replace the global registry (clears existing instances)
|
|
1019
|
-
* @param registry - The new registry to use
|
|
1020
|
-
*/
|
|
1021
|
-
static setRegistry(registry: StateContainerRegistry): void;
|
|
1022
|
-
/**
|
|
1023
|
-
* Register this class with the global registry
|
|
1024
|
-
* @param isolated - Whether instances should be isolated (component-scoped)
|
|
1025
|
-
*/
|
|
1026
|
-
static register<T extends StateContainerConstructor>(this: T, isolated?: boolean): void;
|
|
1027
|
-
/**
|
|
1028
|
-
* Resolve an instance with ref counting (ownership semantics).
|
|
1029
|
-
* Creates a new instance if one doesn't exist, or returns existing and increments ref count.
|
|
1030
|
-
* @template S - Optional state type override for generic StateContainers
|
|
1031
|
-
* @template T - The StateContainer type (inferred from class)
|
|
1032
|
-
* @param instanceKey - Optional instance key (defaults to 'default')
|
|
1033
|
-
* @param options - Resolution options (canCreate, countRef, props, trackExecutionContext)
|
|
1034
|
-
* @returns The state container instance
|
|
1035
|
-
*/
|
|
1036
|
-
static resolve<T extends StateContainerConstructor = StateContainerConstructor>(this: T, instanceKey?: string, options?: {
|
|
1037
|
-
canCreate?: boolean;
|
|
1038
|
-
countRef?: boolean;
|
|
1039
|
-
props?: ExtractProps<T>;
|
|
1040
|
-
trackExecutionContext?: boolean;
|
|
1041
|
-
}): InstanceType<T>;
|
|
1042
|
-
/**
|
|
1043
|
-
* Get an existing instance without incrementing ref count (borrowing semantics).
|
|
1044
|
-
* @template S - Optional state type override for generic StateContainers
|
|
1045
|
-
* @template T - The StateContainer type (inferred from class)
|
|
1046
|
-
* @param instanceKey - Optional instance key (defaults to 'default')
|
|
1047
|
-
* @returns The state container instance
|
|
1048
|
-
* @throws Error if instance doesn't exist
|
|
1049
|
-
*/
|
|
1050
|
-
static get<T extends StateContainerConstructor<any> = StateContainerConstructor<any>>(this: T, instanceKey?: string): InstanceType<T>;
|
|
1051
|
-
/**
|
|
1052
|
-
* Safely get an existing instance with error handling.
|
|
1053
|
-
* @template S - Optional state type override for generic StateContainers
|
|
1054
|
-
* @template T - The StateContainer type (inferred from class)
|
|
1055
|
-
* @param instanceKey - Optional instance key (defaults to 'default')
|
|
1056
|
-
* @returns Discriminated union with either the instance or an error
|
|
1057
|
-
*/
|
|
1058
|
-
static getSafe<T extends StateContainerConstructor<any> = StateContainerConstructor<any>>(this: T, instanceKey?: string): {
|
|
1059
|
-
error: Error;
|
|
1060
|
-
instance: null;
|
|
1061
|
-
} | {
|
|
1062
|
-
error: null;
|
|
1063
|
-
instance: InstanceType<T>;
|
|
1064
|
-
};
|
|
1065
|
-
/**
|
|
1066
|
-
* Connect to an instance for bloc-to-bloc communication (borrowing semantics).
|
|
1067
|
-
* Gets or creates instance without incrementing ref count.
|
|
1068
|
-
* Tracks cross-bloc dependency for reactive updates.
|
|
1069
|
-
* @template S - Optional state type override for generic StateContainers
|
|
1070
|
-
* @template T - The StateContainer type (inferred from class)
|
|
1071
|
-
* @param instanceKey - Optional instance key (defaults to 'default')
|
|
1072
|
-
* @returns The state container instance
|
|
1073
|
-
*/
|
|
1074
|
-
static connect<T extends StateContainerConstructor<any> = StateContainerConstructor<any>>(this: T, instanceKey?: string): InstanceType<T>;
|
|
1075
|
-
/**
|
|
1076
|
-
* Release a reference to an instance.
|
|
1077
|
-
* Decrements ref count and disposes when it reaches 0 (unless keepAlive).
|
|
1078
|
-
* @param instanceKey - Optional instance key (defaults to 'default')
|
|
1079
|
-
* @param forceDispose - Force immediate disposal regardless of ref count
|
|
1080
|
-
*/
|
|
1081
|
-
static release<T extends StateContainerConstructor = StateContainerConstructor>(this: T, instanceKey?: string, forceDispose?: boolean): void;
|
|
1082
|
-
/**
|
|
1083
|
-
* Get all instances of this class
|
|
1084
|
-
* @returns Array of all instances
|
|
1085
|
-
*/
|
|
1086
|
-
static getAll<T extends StateContainerConstructor = StateContainerConstructor>(this: T): InstanceReadonlyState<T>[];
|
|
1087
|
-
/**
|
|
1088
|
-
* Iterate over all instances of this class
|
|
1089
|
-
* @param callback - Function to call for each instance
|
|
1090
|
-
*/
|
|
1091
|
-
static forEach<T extends StateContainerConstructor = StateContainerConstructor>(this: T, callback: (instance: InstanceReadonlyState<T>) => void): void;
|
|
1092
|
-
/**
|
|
1093
|
-
* Clear all instances of this class (disposes them)
|
|
1094
|
-
*/
|
|
1095
|
-
static clear<T extends StateContainerConstructor = StateContainerConstructor>(this: T): void;
|
|
1096
|
-
/**
|
|
1097
|
-
* Clear all instances from all registered types
|
|
1098
|
-
*/
|
|
1099
|
-
static clearAllInstances(): void;
|
|
1100
|
-
/**
|
|
1101
|
-
* Get registry statistics for debugging
|
|
1102
|
-
* @returns Object with registeredTypes, totalInstances, and typeBreakdown
|
|
1103
|
-
*/
|
|
1104
|
-
static getStats(): {
|
|
1105
|
-
registeredTypes: number;
|
|
1106
|
-
totalInstances: number;
|
|
1107
|
-
typeBreakdown: Record<string, number>;
|
|
1108
|
-
};
|
|
1109
|
-
/**
|
|
1110
|
-
* Get reference count for an instance
|
|
1111
|
-
* @param instanceKey - Optional instance key (defaults to 'default')
|
|
1112
|
-
* @returns Current ref count (0 if instance doesn't exist)
|
|
1113
|
-
*/
|
|
1114
|
-
static getRefCount<T extends StateContainerConstructor = StateContainerConstructor>(this: T, instanceKey?: string): number;
|
|
1115
|
-
/**
|
|
1116
|
-
* Check if an instance exists
|
|
1117
|
-
* @param instanceKey - Optional instance key (defaults to 'default')
|
|
1118
|
-
* @returns true if instance exists
|
|
1119
|
-
*/
|
|
1120
|
-
static hasInstance<T extends StateContainerConstructor = StateContainerConstructor>(this: T, instanceKey?: string): boolean;
|
|
1178
|
+
static __excludeFromDevTools: boolean;
|
|
1179
|
+
static enableStackTrace: boolean;
|
|
1121
1180
|
private _state;
|
|
1122
1181
|
private readonly listeners;
|
|
1123
1182
|
private _disposed;
|
|
@@ -1162,8 +1221,6 @@ export declare abstract class StateContainer<S extends object = any, P = any> {
|
|
|
1162
1221
|
* @protected
|
|
1163
1222
|
*/
|
|
1164
1223
|
protected emit(newState: S): void;
|
|
1165
|
-
/** Whether to capture stack traces on state changes (disabled in production) */
|
|
1166
|
-
static enableStackTrace: boolean;
|
|
1167
1224
|
private captureStackTrace;
|
|
1168
1225
|
private formatStackLine;
|
|
1169
1226
|
private cleanFilePath;
|
|
@@ -1222,7 +1279,8 @@ export declare type StateContainerInstance<S extends object = any, P = any> = Om
|
|
|
1222
1279
|
* @example
|
|
1223
1280
|
* ```ts
|
|
1224
1281
|
* const registry = new StateContainerRegistry();
|
|
1225
|
-
* const instance = registry.
|
|
1282
|
+
* const instance = registry.acquire(MyBloc); // ownership, must release
|
|
1283
|
+
* const other = registry.ensure(OtherBloc); // no ownership, bloc-to-bloc
|
|
1226
1284
|
* registry.on('stateChanged', (container, prev, next) => {
|
|
1227
1285
|
* console.log('State changed:', prev, '->', next);
|
|
1228
1286
|
* });
|
|
@@ -1252,40 +1310,41 @@ export declare class StateContainerRegistry {
|
|
|
1252
1310
|
getInstancesMap<T extends StateContainerConstructor>(Type: T): Map<string, InstanceEntry>;
|
|
1253
1311
|
private trackExecutionContext;
|
|
1254
1312
|
/**
|
|
1255
|
-
*
|
|
1313
|
+
* Acquire an instance with ref counting (ownership semantics).
|
|
1256
1314
|
* Creates a new instance if one doesn't exist, or returns existing and increments ref count.
|
|
1315
|
+
* You must call `release()` when done to decrement the ref count.
|
|
1257
1316
|
* @param Type - The StateContainer class constructor
|
|
1258
1317
|
* @param instanceKey - Instance key (defaults to 'default')
|
|
1259
|
-
* @param options -
|
|
1318
|
+
* @param options - Acquisition options
|
|
1260
1319
|
* @param options.canCreate - Whether to create new instance if not found (default: true)
|
|
1261
1320
|
* @param options.countRef - Whether to increment ref count (default: true)
|
|
1262
1321
|
* @param options.props - Props to pass to constructor if creating new instance
|
|
1263
1322
|
* @param options.trackExecutionContext - Whether to track cross-bloc dependency (default: false)
|
|
1264
1323
|
* @returns The state container instance
|
|
1265
1324
|
*/
|
|
1266
|
-
|
|
1325
|
+
acquire<T extends StateContainerConstructor = StateContainerConstructor>(Type: T, instanceKey?: string, options?: {
|
|
1267
1326
|
canCreate?: boolean;
|
|
1268
1327
|
countRef?: boolean;
|
|
1269
1328
|
props?: ExtractProps<T>;
|
|
1270
1329
|
trackExecutionContext?: boolean;
|
|
1271
1330
|
}): InstanceType<T>;
|
|
1272
1331
|
/**
|
|
1273
|
-
*
|
|
1332
|
+
* Borrow an existing instance without incrementing ref count (borrowing semantics).
|
|
1274
1333
|
* Tracks cross-bloc dependency for reactive updates.
|
|
1275
1334
|
* @param Type - The StateContainer class constructor
|
|
1276
1335
|
* @param instanceKey - Instance key (defaults to 'default')
|
|
1277
1336
|
* @returns The state container instance
|
|
1278
1337
|
* @throws Error if instance doesn't exist
|
|
1279
1338
|
*/
|
|
1280
|
-
|
|
1339
|
+
borrow<T extends StateContainerConstructor = StateContainerConstructor>(Type: T, instanceKey?: string): InstanceType<T>;
|
|
1281
1340
|
/**
|
|
1282
|
-
* Safely
|
|
1341
|
+
* Safely borrow an existing instance (borrowing semantics with error handling).
|
|
1283
1342
|
* Returns discriminated union for type-safe conditional access.
|
|
1284
1343
|
* @param Type - The StateContainer class constructor
|
|
1285
1344
|
* @param instanceKey - Instance key (defaults to 'default')
|
|
1286
1345
|
* @returns Discriminated union with either the instance or an error
|
|
1287
1346
|
*/
|
|
1288
|
-
|
|
1347
|
+
borrowSafe<T extends StateContainerConstructor = StateContainerConstructor>(Type: T, instanceKey?: string): {
|
|
1289
1348
|
error: Error;
|
|
1290
1349
|
instance: null;
|
|
1291
1350
|
} | {
|
|
@@ -1293,7 +1352,7 @@ export declare class StateContainerRegistry {
|
|
|
1293
1352
|
instance: InstanceType<T>;
|
|
1294
1353
|
};
|
|
1295
1354
|
/**
|
|
1296
|
-
*
|
|
1355
|
+
* Ensure an instance exists without taking ownership (for bloc-to-bloc communication).
|
|
1297
1356
|
* Gets existing instance OR creates it if it doesn't exist, without incrementing ref count.
|
|
1298
1357
|
* Tracks cross-bloc dependency for reactive updates.
|
|
1299
1358
|
*
|
|
@@ -1303,7 +1362,7 @@ export declare class StateContainerRegistry {
|
|
|
1303
1362
|
* @param instanceKey - Instance key (defaults to 'default')
|
|
1304
1363
|
* @returns The state container instance
|
|
1305
1364
|
*/
|
|
1306
|
-
|
|
1365
|
+
ensure<T extends StateContainerConstructor = StateContainerConstructor>(Type: T, instanceKey?: string): InstanceType<T>;
|
|
1307
1366
|
/**
|
|
1308
1367
|
* Release a reference to an instance.
|
|
1309
1368
|
* Decrements ref count and disposes when it reaches 0 (unless keepAlive).
|
|
@@ -1375,9 +1434,195 @@ export declare class StateContainerRegistry {
|
|
|
1375
1434
|
/* Excluded from this release type: emit */
|
|
1376
1435
|
}
|
|
1377
1436
|
|
|
1437
|
+
/**
|
|
1438
|
+
* Constrain a type to only accept stateful containers (not StatelessCubit/StatelessVertex).
|
|
1439
|
+
* Use this to reject stateless containers at the type level.
|
|
1440
|
+
*/
|
|
1441
|
+
export declare type StatefulContainerOnly<T extends StateContainerConstructor> = IsStatelessContainer<T> extends true ? never : T;
|
|
1442
|
+
|
|
1443
|
+
/**
|
|
1444
|
+
* Marker symbol to identify stateless containers at the type level.
|
|
1445
|
+
* Used by React hooks to prevent `useBloc` from accepting stateless containers.
|
|
1446
|
+
*/
|
|
1447
|
+
export declare const STATELESS_MARKER: unique symbol;
|
|
1448
|
+
|
|
1449
|
+
/**
|
|
1450
|
+
* A Cubit without state management capabilities.
|
|
1451
|
+
* Use this for action-only containers that don't need to manage or emit state.
|
|
1452
|
+
*
|
|
1453
|
+
* StatelessCubit:
|
|
1454
|
+
* - Has no `emit()`, `update()`, or `patch()` methods
|
|
1455
|
+
* - Has no accessible `state` property
|
|
1456
|
+
* - Cannot be subscribed to (throws error)
|
|
1457
|
+
* - Is rejected by `useBloc` hook (use `useBlocActions` instead)
|
|
1458
|
+
*
|
|
1459
|
+
* @template P - Props type (optional)
|
|
1460
|
+
*
|
|
1461
|
+
* @example
|
|
1462
|
+
* ```typescript
|
|
1463
|
+
* class AnalyticsService extends StatelessCubit {
|
|
1464
|
+
* trackPageView(page: string) {
|
|
1465
|
+
* analytics.track('page_view', { page });
|
|
1466
|
+
* }
|
|
1467
|
+
*
|
|
1468
|
+
* trackClick(element: string) {
|
|
1469
|
+
* analytics.track('click', { element });
|
|
1470
|
+
* }
|
|
1471
|
+
* }
|
|
1472
|
+
*
|
|
1473
|
+
* // In React component:
|
|
1474
|
+
* const analytics = useBlocActions(AnalyticsService);
|
|
1475
|
+
* analytics.trackPageView('/home');
|
|
1476
|
+
* ```
|
|
1477
|
+
*/
|
|
1478
|
+
export declare abstract class StatelessCubit<P = undefined> extends Cubit<EmptyState, P> {
|
|
1479
|
+
/* Excluded from this release type: [STATELESS_MARKER] */
|
|
1480
|
+
constructor();
|
|
1481
|
+
/**
|
|
1482
|
+
* State is not available on StatelessCubit.
|
|
1483
|
+
* @throws Always throws an error when accessed.
|
|
1484
|
+
*/
|
|
1485
|
+
get state(): never;
|
|
1486
|
+
/**
|
|
1487
|
+
* Subscriptions are not available on StatelessCubit.
|
|
1488
|
+
* @throws Always throws an error when called.
|
|
1489
|
+
*/
|
|
1490
|
+
subscribe(_listener: (state: EmptyState) => void): never;
|
|
1491
|
+
/**
|
|
1492
|
+
* emit() is not available on StatelessCubit.
|
|
1493
|
+
* TypeScript will show an error if you try to call this method.
|
|
1494
|
+
*/
|
|
1495
|
+
emit(_newState: never): never;
|
|
1496
|
+
/**
|
|
1497
|
+
* update() is not available on StatelessCubit.
|
|
1498
|
+
* TypeScript will show an error if you try to call this method.
|
|
1499
|
+
*/
|
|
1500
|
+
update(_updater: never): never;
|
|
1501
|
+
/**
|
|
1502
|
+
* patch() is not available on StatelessCubit.
|
|
1503
|
+
* @throws Error always - StatelessCubit does not support state changes
|
|
1504
|
+
*/
|
|
1505
|
+
patch: (_partial: Partial<EmptyState>) => void;
|
|
1506
|
+
}
|
|
1507
|
+
|
|
1508
|
+
/**
|
|
1509
|
+
* Event handler for StatelessVertex that receives only the event (no emit function).
|
|
1510
|
+
* Use for side-effect-only event processing.
|
|
1511
|
+
*/
|
|
1512
|
+
export declare type StatelessEventHandler<E extends DiscriminatedEvent> = (event: EventWithMetadata<E>) => void;
|
|
1513
|
+
|
|
1514
|
+
/**
|
|
1515
|
+
* Map of event types to their handlers for StatelessVertex.
|
|
1516
|
+
* Enforces exhaustive handling of all event types in the union.
|
|
1517
|
+
*/
|
|
1518
|
+
export declare type StatelessEventHandlerMap<E extends DiscriminatedEvent> = {
|
|
1519
|
+
[K in E['type']]: StatelessEventHandler<Extract<E, {
|
|
1520
|
+
type: K;
|
|
1521
|
+
}>>;
|
|
1522
|
+
};
|
|
1523
|
+
|
|
1524
|
+
/**
|
|
1525
|
+
* An event-driven container without state management capabilities.
|
|
1526
|
+
* Use this for event processing that only produces side effects (logging, analytics, etc).
|
|
1527
|
+
*
|
|
1528
|
+
* StatelessVertex:
|
|
1529
|
+
* - Processes events via `add()` method
|
|
1530
|
+
* - Handlers receive only the event (no `emit` function)
|
|
1531
|
+
* - Has no accessible `state` property
|
|
1532
|
+
* - Cannot be subscribed to (throws error)
|
|
1533
|
+
* - Is rejected by `useBloc` hook (use `useBlocActions` instead)
|
|
1534
|
+
*
|
|
1535
|
+
* @template E - Event union type (discriminated by 'type' property)
|
|
1536
|
+
* @template P - Props type (optional)
|
|
1537
|
+
*
|
|
1538
|
+
* @example
|
|
1539
|
+
* ```typescript
|
|
1540
|
+
* type LogEvent =
|
|
1541
|
+
* | { type: 'info'; message: string }
|
|
1542
|
+
* | { type: 'error'; message: string; error: Error }
|
|
1543
|
+
* | { type: 'warn'; message: string };
|
|
1544
|
+
*
|
|
1545
|
+
* class LoggingVertex extends StatelessVertex<LogEvent> {
|
|
1546
|
+
* constructor() {
|
|
1547
|
+
* super();
|
|
1548
|
+
* this.createHandlers({
|
|
1549
|
+
* info: (event) => console.log('[INFO]', event.message),
|
|
1550
|
+
* error: (event) => console.error('[ERROR]', event.message, event.error),
|
|
1551
|
+
* warn: (event) => console.warn('[WARN]', event.message),
|
|
1552
|
+
* });
|
|
1553
|
+
* }
|
|
1554
|
+
*
|
|
1555
|
+
* info = (message: string) => this.add({ type: 'info', message });
|
|
1556
|
+
* error = (message: string, error: Error) => this.add({ type: 'error', message, error });
|
|
1557
|
+
* warn = (message: string) => this.add({ type: 'warn', message });
|
|
1558
|
+
* }
|
|
1559
|
+
*
|
|
1560
|
+
* // In React component:
|
|
1561
|
+
* const logger = useBlocActions(LoggingVertex);
|
|
1562
|
+
* logger.info('Page loaded');
|
|
1563
|
+
* ```
|
|
1564
|
+
*/
|
|
1565
|
+
export declare abstract class StatelessVertex<E extends DiscriminatedEvent = DiscriminatedEvent, P = undefined> extends StateContainer<EmptyState_2, P> {
|
|
1566
|
+
/* Excluded from this release type: [STATELESS_MARKER] */
|
|
1567
|
+
/* Excluded from this release type: handlers */
|
|
1568
|
+
/* Excluded from this release type: isProcessing */
|
|
1569
|
+
/* Excluded from this release type: eventQueue */
|
|
1570
|
+
constructor();
|
|
1571
|
+
/**
|
|
1572
|
+
* State is not available on StatelessVertex.
|
|
1573
|
+
* @throws Always throws an error when accessed.
|
|
1574
|
+
*/
|
|
1575
|
+
get state(): never;
|
|
1576
|
+
/**
|
|
1577
|
+
* Subscriptions are not available on StatelessVertex.
|
|
1578
|
+
* @throws Always throws an error when called.
|
|
1579
|
+
*/
|
|
1580
|
+
subscribe(_listener: (state: EmptyState_2) => void): never;
|
|
1581
|
+
/**
|
|
1582
|
+
* Register all event handlers with exhaustive type checking.
|
|
1583
|
+
* TypeScript will error if any event type from the union is missing.
|
|
1584
|
+
*
|
|
1585
|
+
* Unlike regular Vertex, handlers do NOT receive an emit function
|
|
1586
|
+
* since StatelessVertex cannot emit state.
|
|
1587
|
+
*
|
|
1588
|
+
* @param handlers - Map of event type to handler function
|
|
1589
|
+
*/
|
|
1590
|
+
protected createHandlers(handlers: StatelessEventHandlerMap<E>): void;
|
|
1591
|
+
/**
|
|
1592
|
+
* Dispatch an event for processing.
|
|
1593
|
+
* Events are processed synchronously; if called during processing,
|
|
1594
|
+
* the event is queued and processed after the current event completes.
|
|
1595
|
+
*
|
|
1596
|
+
* @param event - The event to process (must match the event union type)
|
|
1597
|
+
*/
|
|
1598
|
+
add: (event: E) => void;
|
|
1599
|
+
/* Excluded from this release type: enrichEvent */
|
|
1600
|
+
/* Excluded from this release type: processEvent */
|
|
1601
|
+
/* Excluded from this release type: handleEvent */
|
|
1602
|
+
/**
|
|
1603
|
+
* Called when an error occurs during event processing.
|
|
1604
|
+
* Override to implement custom error handling.
|
|
1605
|
+
*
|
|
1606
|
+
* @param _event - The event that caused the error
|
|
1607
|
+
* @param _error - The error that occurred
|
|
1608
|
+
*/
|
|
1609
|
+
protected onEventError(_event: EventWithMetadata<E>, _error: Error): void;
|
|
1610
|
+
/* Excluded from this release type: emit */
|
|
1611
|
+
/* Excluded from this release type: update */
|
|
1612
|
+
}
|
|
1613
|
+
|
|
1378
1614
|
/* Excluded from this release type: StateListener */
|
|
1379
1615
|
|
|
1380
|
-
|
|
1616
|
+
declare const STOP: unique symbol;
|
|
1617
|
+
|
|
1618
|
+
/* Excluded from this release type: stopProxy */
|
|
1619
|
+
|
|
1620
|
+
declare type StopSymbol = typeof STOP;
|
|
1621
|
+
|
|
1622
|
+
/**
|
|
1623
|
+
* Stop tracking and collect all dependencies.
|
|
1624
|
+
*/
|
|
1625
|
+
export declare function stopTrackingProxy(tracker: TrackingProxyState, bloc: StateContainerInstance): Set<StateContainerInstance>;
|
|
1381
1626
|
|
|
1382
1627
|
/**
|
|
1383
1628
|
* Function that subscribes to state changes and returns an unsubscribe function
|
|
@@ -1416,7 +1661,82 @@ export declare interface SystemEventPayloads<S, P> {
|
|
|
1416
1661
|
dispose: void;
|
|
1417
1662
|
}
|
|
1418
1663
|
|
|
1419
|
-
|
|
1664
|
+
/**
|
|
1665
|
+
* Run a callback while tracking all bloc dependencies accessed.
|
|
1666
|
+
* Returns both the result and the set of discovered dependencies.
|
|
1667
|
+
*
|
|
1668
|
+
* @example
|
|
1669
|
+
* ```ts
|
|
1670
|
+
* const { result, dependencies } = tracked(() => {
|
|
1671
|
+
* const user = ensure(UserBloc);
|
|
1672
|
+
* return user.fullName; // getter that may access other blocs
|
|
1673
|
+
* });
|
|
1674
|
+
* // dependencies contains UserBloc + any blocs accessed in fullName getter
|
|
1675
|
+
* ```
|
|
1676
|
+
*/
|
|
1677
|
+
export declare function tracked<T>(callback: () => T, options?: TrackedOptions): TrackedResult<T>;
|
|
1678
|
+
|
|
1679
|
+
/**
|
|
1680
|
+
* Context for running tracked callbacks with bloc proxies.
|
|
1681
|
+
* Provides methods to create proxies and check for changes.
|
|
1682
|
+
*/
|
|
1683
|
+
export declare class TrackedContext {
|
|
1684
|
+
private tracker;
|
|
1685
|
+
private proxiedBlocs;
|
|
1686
|
+
private primaryBlocs;
|
|
1687
|
+
constructor();
|
|
1688
|
+
/**
|
|
1689
|
+
* Get a tracking proxy for a bloc instance.
|
|
1690
|
+
* The proxy will track state and getter accesses.
|
|
1691
|
+
*/
|
|
1692
|
+
proxy<T extends StateContainerInstance>(bloc: T): T;
|
|
1693
|
+
/**
|
|
1694
|
+
* Start tracking for a new callback execution.
|
|
1695
|
+
*/
|
|
1696
|
+
start(): void;
|
|
1697
|
+
/**
|
|
1698
|
+
* Stop tracking and get discovered dependencies.
|
|
1699
|
+
* Excludes primary blocs (those explicitly proxied via proxy()).
|
|
1700
|
+
*/
|
|
1701
|
+
stop(): Set<StateContainerInstance>;
|
|
1702
|
+
/**
|
|
1703
|
+
* Check if any tracked state or getters have changed.
|
|
1704
|
+
*/
|
|
1705
|
+
changed(): boolean;
|
|
1706
|
+
/**
|
|
1707
|
+
* Get all primary blocs (those explicitly proxied).
|
|
1708
|
+
*/
|
|
1709
|
+
getPrimaryBlocs(): Set<StateContainerInstance>;
|
|
1710
|
+
/**
|
|
1711
|
+
* Reset the context for reuse.
|
|
1712
|
+
*/
|
|
1713
|
+
reset(): void;
|
|
1714
|
+
}
|
|
1715
|
+
|
|
1716
|
+
/**
|
|
1717
|
+
* Options for the tracked() function.
|
|
1718
|
+
*/
|
|
1719
|
+
export declare interface TrackedOptions {
|
|
1720
|
+
exclude?: StateContainerInstance;
|
|
1721
|
+
}
|
|
1722
|
+
|
|
1723
|
+
/**
|
|
1724
|
+
* Result of running a tracked callback.
|
|
1725
|
+
*/
|
|
1726
|
+
export declare interface TrackedResult<T> {
|
|
1727
|
+
result: T;
|
|
1728
|
+
dependencies: Set<StateContainerInstance>;
|
|
1729
|
+
}
|
|
1730
|
+
|
|
1731
|
+
/**
|
|
1732
|
+
* State for tracking both state property access and getter access.
|
|
1733
|
+
*/
|
|
1734
|
+
export declare interface TrackingProxyState {
|
|
1735
|
+
dependencyState: DependencyState<any>;
|
|
1736
|
+
getterState: GetterState;
|
|
1737
|
+
dependencies: Set<StateContainerInstance>;
|
|
1738
|
+
isTracking: boolean;
|
|
1739
|
+
}
|
|
1420
1740
|
|
|
1421
1741
|
/**
|
|
1422
1742
|
* Event-driven state container using discriminated union events.
|
|
@@ -1489,6 +1809,64 @@ export declare abstract class Vertex<S extends object = object, E extends Discri
|
|
|
1489
1809
|
|
|
1490
1810
|
/* Excluded from this release type: VertexEventHandler */
|
|
1491
1811
|
|
|
1812
|
+
/**
|
|
1813
|
+
* Wait until a condition is met on a bloc instance.
|
|
1814
|
+
* Returns the bloc instance when the predicate returns true.
|
|
1815
|
+
* Automatically tracks dependencies accessed in the predicate.
|
|
1816
|
+
*
|
|
1817
|
+
* @example
|
|
1818
|
+
* ```ts
|
|
1819
|
+
* // Wait for bloc state to be ready
|
|
1820
|
+
* const userBloc = await waitUntil(UserBloc, (bloc) => bloc.state.isAuthenticated);
|
|
1821
|
+
*
|
|
1822
|
+
* // Wait using a getter
|
|
1823
|
+
* const userBloc = await waitUntil(UserBloc, (bloc) => bloc.isReady);
|
|
1824
|
+
* ```
|
|
1825
|
+
*/
|
|
1826
|
+
export declare function waitUntil<T extends StateContainerConstructor>(BlocClass: T, predicate: (bloc: InstanceType<T>) => boolean, options?: WaitUntilOptions): Promise<InstanceType<T>>;
|
|
1827
|
+
|
|
1828
|
+
/**
|
|
1829
|
+
* Wait until a condition is met on a selected value from a bloc.
|
|
1830
|
+
* Returns the selected value when the predicate returns true.
|
|
1831
|
+
* Automatically tracks dependencies accessed in selector and predicate.
|
|
1832
|
+
*
|
|
1833
|
+
* @example
|
|
1834
|
+
* ```ts
|
|
1835
|
+
* // Wait for layout to be set and get it directly
|
|
1836
|
+
* const layout = await waitUntil(
|
|
1837
|
+
* LayoutBloc,
|
|
1838
|
+
* (bloc) => bloc.state.currentLayout,
|
|
1839
|
+
* (layout) => layout !== null
|
|
1840
|
+
* );
|
|
1841
|
+
*
|
|
1842
|
+
* // Using a getter as selector
|
|
1843
|
+
* const user = await waitUntil(
|
|
1844
|
+
* UserBloc,
|
|
1845
|
+
* (bloc) => bloc.currentUser,
|
|
1846
|
+
* (user) => user !== null
|
|
1847
|
+
* );
|
|
1848
|
+
* ```
|
|
1849
|
+
*/
|
|
1850
|
+
export declare function waitUntil<T extends StateContainerConstructor, TSelected>(BlocClass: T, selector: (bloc: InstanceType<T>) => TSelected, predicate: (selected: TSelected) => boolean, options?: WaitUntilOptions): Promise<TSelected>;
|
|
1851
|
+
|
|
1852
|
+
export declare class WaitUntilAbortedError extends Error {
|
|
1853
|
+
constructor();
|
|
1854
|
+
}
|
|
1855
|
+
|
|
1856
|
+
export declare class WaitUntilDisposedError extends Error {
|
|
1857
|
+
constructor(blocName: string);
|
|
1858
|
+
}
|
|
1859
|
+
|
|
1860
|
+
export declare interface WaitUntilOptions {
|
|
1861
|
+
instanceId?: string;
|
|
1862
|
+
timeout?: number;
|
|
1863
|
+
signal?: AbortSignal;
|
|
1864
|
+
}
|
|
1865
|
+
|
|
1866
|
+
export declare class WaitUntilTimeoutError extends Error {
|
|
1867
|
+
constructor(timeout: number);
|
|
1868
|
+
}
|
|
1869
|
+
|
|
1492
1870
|
/**
|
|
1493
1871
|
* Log a warning message (tree-shakeable export)
|
|
1494
1872
|
* @param context - Context identifier (module or component name)
|
|
@@ -1497,4 +1875,21 @@ export declare abstract class Vertex<S extends object = object, E extends Discri
|
|
|
1497
1875
|
*/
|
|
1498
1876
|
export declare const warn: (context: string, message: string, data?: any) => void;
|
|
1499
1877
|
|
|
1878
|
+
export declare const watch: WatchFn;
|
|
1879
|
+
|
|
1880
|
+
/**
|
|
1881
|
+
* Combined watch function type.
|
|
1882
|
+
*/
|
|
1883
|
+
export declare interface WatchFn extends WatchSingleFn {
|
|
1884
|
+
<T extends readonly BlocInput[]>(blocs: T, callback: (blocs: ExtractInstances<T>) => void | StopSymbol): () => void;
|
|
1885
|
+
}
|
|
1886
|
+
|
|
1887
|
+
/**
|
|
1888
|
+
* Watch function signature for single bloc.
|
|
1889
|
+
*/
|
|
1890
|
+
declare interface WatchSingleFn {
|
|
1891
|
+
<T extends StateContainerConstructor>(bloc: T | BlocRef<T>, callback: (bloc: InstanceType<T>) => void | StopSymbol): () => void;
|
|
1892
|
+
STOP: StopSymbol;
|
|
1893
|
+
}
|
|
1894
|
+
|
|
1500
1895
|
export { }
|