@blac/core 2.0.0-rc.13 → 2.0.0-rc.15
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 +111 -73
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +168 -112
- package/dist/index.d.ts +168 -112
- package/dist/index.js +111 -73
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Internal state for framework adapters, holding tracking and caching data.
|
|
5
5
|
* @template TBloc - The state container type
|
|
6
6
|
*/
|
|
7
|
-
export declare interface AdapterState<TBloc extends
|
|
7
|
+
export declare interface AdapterState<TBloc extends StateContainerConstructor> {
|
|
8
8
|
/** Proxy tracker for state property access tracking */
|
|
9
9
|
tracker: TrackerState<ExtractState<TBloc>> | null;
|
|
10
10
|
/** Cached manual dependencies for comparison */
|
|
@@ -12,7 +12,7 @@ export declare interface AdapterState<TBloc extends StateContainer<any, any>> {
|
|
|
12
12
|
/** Getter tracker for computed property tracking */
|
|
13
13
|
getterTracker: GetterTrackerState | null;
|
|
14
14
|
/** Proxied bloc instance for auto-tracking */
|
|
15
|
-
proxiedBloc: TBloc | null;
|
|
15
|
+
proxiedBloc: InstanceState<TBloc> | null;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
/**
|
|
@@ -173,7 +173,7 @@ export declare interface BlacPlugin {
|
|
|
173
173
|
/**
|
|
174
174
|
* Called when state changes in a container instance
|
|
175
175
|
*/
|
|
176
|
-
onStateChanged?<S>(instance: StateContainer<S>, previousState: S, currentState: S, callstack: string | undefined, context: PluginContext): void;
|
|
176
|
+
onStateChanged?<S extends object = any>(instance: StateContainer<S>, previousState: S, currentState: S, callstack: string | undefined, context: PluginContext): void;
|
|
177
177
|
/**
|
|
178
178
|
* Called when an event is added to a Vertex instance
|
|
179
179
|
*/
|
|
@@ -199,21 +199,27 @@ export declare interface BlacPluginWithInit extends BlacPlugin {
|
|
|
199
199
|
* Used for type-safe hook parameters.
|
|
200
200
|
* @template TBloc - The StateContainer instance type
|
|
201
201
|
*/
|
|
202
|
-
export declare type BlocConstructor<
|
|
203
|
-
resolve
|
|
204
|
-
get
|
|
205
|
-
getSafe
|
|
202
|
+
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>) & {
|
|
203
|
+
resolve(instanceKey?: string, ...args: any[]): InstanceType<T>;
|
|
204
|
+
get(instanceKey?: string, ...args: any[]): InstanceType<T> | null;
|
|
205
|
+
getSafe(instanceKey?: string, ...args: any[]): {
|
|
206
206
|
error: Error;
|
|
207
207
|
instance: null;
|
|
208
208
|
} | {
|
|
209
209
|
error: null;
|
|
210
|
-
instance:
|
|
210
|
+
instance: InstanceType<T>;
|
|
211
211
|
};
|
|
212
212
|
release(instanceKey?: string): void;
|
|
213
213
|
isolated?: boolean;
|
|
214
214
|
keepAlive?: boolean;
|
|
215
215
|
};
|
|
216
216
|
|
|
217
|
+
/**
|
|
218
|
+
* Extract instance type from an abstract class constructor
|
|
219
|
+
* @template T - The abstract class constructor type
|
|
220
|
+
*/
|
|
221
|
+
export declare type BlocInstanceType<T extends abstract new (...args: any) => any> = T extends abstract new (...args: any) => infer R ? R : any;
|
|
222
|
+
|
|
217
223
|
/**
|
|
218
224
|
* Utility type for creating branded/nominal types.
|
|
219
225
|
* Prevents accidental type confusion between similar primitive types.
|
|
@@ -261,7 +267,7 @@ export declare function configureLogger(opts: Partial<LogConfig>): void;
|
|
|
261
267
|
* @param adapterState - The adapter state for tracking
|
|
262
268
|
* @returns Snapshot function for use with useSyncExternalStore
|
|
263
269
|
*/
|
|
264
|
-
export declare function createAutoTrackSnapshot<TBloc extends
|
|
270
|
+
export declare function createAutoTrackSnapshot<TBloc extends StateContainerConstructor>(instance: InstanceReadonlyState<TBloc>, adapterState: AdapterState<TBloc>): SnapshotFunction<ExtractState<TBloc>>;
|
|
265
271
|
|
|
266
272
|
/**
|
|
267
273
|
* Create a subscribe function for auto-tracking mode.
|
|
@@ -270,7 +276,7 @@ export declare function createAutoTrackSnapshot<TBloc extends StateContainer<any
|
|
|
270
276
|
* @param adapterState - The adapter state for tracking
|
|
271
277
|
* @returns Subscribe function for use with useSyncExternalStore
|
|
272
278
|
*/
|
|
273
|
-
export declare function createAutoTrackSubscribe<TBloc extends
|
|
279
|
+
export declare function createAutoTrackSubscribe<TBloc extends StateContainerConstructor>(instance: InstanceReadonlyState<TBloc>, adapterState: AdapterState<TBloc>): SubscribeFunction;
|
|
274
280
|
|
|
275
281
|
/* Excluded from this release type: createBlocProxy */
|
|
276
282
|
|
|
@@ -333,7 +339,7 @@ export declare function createLogger(config: LogConfig): {
|
|
|
333
339
|
* @param config - Configuration with dependencies function
|
|
334
340
|
* @returns Snapshot function for use with useSyncExternalStore
|
|
335
341
|
*/
|
|
336
|
-
export declare function createManualDepsSnapshot<TBloc extends
|
|
342
|
+
export declare function createManualDepsSnapshot<TBloc extends StateContainerConstructor>(instance: InstanceState<TBloc>, adapterState: AdapterState<TBloc>, config: ManualDepsConfig<TBloc>): SnapshotFunction<ExtractState<TBloc>>;
|
|
337
343
|
|
|
338
344
|
/**
|
|
339
345
|
* Create a subscribe function for manual dependency tracking mode.
|
|
@@ -343,7 +349,7 @@ export declare function createManualDepsSnapshot<TBloc extends StateContainer<an
|
|
|
343
349
|
* @param config - Configuration with dependencies function
|
|
344
350
|
* @returns Subscribe function for use with useSyncExternalStore
|
|
345
351
|
*/
|
|
346
|
-
export declare function createManualDepsSubscribe<TBloc extends
|
|
352
|
+
export declare function createManualDepsSubscribe<TBloc extends StateContainerConstructor>(instance: InstanceState<TBloc>, adapterState: AdapterState<TBloc>, config: ManualDepsConfig<TBloc>): SubscribeFunction;
|
|
347
353
|
|
|
348
354
|
/**
|
|
349
355
|
* Create a snapshot function for no-tracking mode.
|
|
@@ -351,7 +357,7 @@ export declare function createManualDepsSubscribe<TBloc extends StateContainer<a
|
|
|
351
357
|
* @param instance - The state container instance
|
|
352
358
|
* @returns Snapshot function for use with useSyncExternalStore
|
|
353
359
|
*/
|
|
354
|
-
export declare function createNoTrackSnapshot<TBloc extends
|
|
360
|
+
export declare function createNoTrackSnapshot<TBloc extends StateContainerConstructor>(instance: InstanceReadonlyState<TBloc>): SnapshotFunction<ExtractState<TBloc>>;
|
|
355
361
|
|
|
356
362
|
/**
|
|
357
363
|
* Create a subscribe function for no-tracking mode.
|
|
@@ -359,10 +365,12 @@ export declare function createNoTrackSnapshot<TBloc extends StateContainer<any,
|
|
|
359
365
|
* @param instance - The state container instance
|
|
360
366
|
* @returns Subscribe function for use with useSyncExternalStore
|
|
361
367
|
*/
|
|
362
|
-
export declare function createNoTrackSubscribe<TBloc extends
|
|
368
|
+
export declare function createNoTrackSubscribe<TBloc extends StateContainerInstance>(instance: TBloc): SubscribeFunction;
|
|
363
369
|
|
|
364
370
|
/**
|
|
365
371
|
* Create a plugin manager instance
|
|
372
|
+
* @param registry - The StateContainerRegistry to monitor for lifecycle events
|
|
373
|
+
* @returns A new PluginManager instance
|
|
366
374
|
*/
|
|
367
375
|
export declare function createPluginManager(registry: StateContainerRegistry): PluginManager;
|
|
368
376
|
|
|
@@ -383,7 +391,7 @@ export declare function createPluginManager(registry: StateContainerRegistry): P
|
|
|
383
391
|
* @template S - State type
|
|
384
392
|
* @template P - Props type (optional)
|
|
385
393
|
*/
|
|
386
|
-
export declare abstract class Cubit<S, P = undefined> extends StateContainer<S, P> {
|
|
394
|
+
export declare abstract class Cubit<S extends object = any, P = undefined> extends StateContainer<S, P> {
|
|
387
395
|
constructor(initialState: S);
|
|
388
396
|
/**
|
|
389
397
|
* Replace state with a new value and notify all listeners
|
|
@@ -415,7 +423,7 @@ export declare const debug: (context: string, message: string, data?: any) => vo
|
|
|
415
423
|
* @param adapterState - The adapter state
|
|
416
424
|
* @param rawInstance - The raw bloc instance
|
|
417
425
|
*/
|
|
418
|
-
export declare function disableGetterTracking<TBloc extends
|
|
426
|
+
export declare function disableGetterTracking<TBloc extends StateContainerConstructor>(adapterState: AdapterState<TBloc>, rawInstance: InstanceState<TBloc>): void;
|
|
419
427
|
|
|
420
428
|
/**
|
|
421
429
|
* Log an error message (tree-shakeable export)
|
|
@@ -457,7 +465,7 @@ export declare class ExternalDependencyManager {
|
|
|
457
465
|
* @param onGetterChange - Callback to invoke when external dependency changes
|
|
458
466
|
* @returns true if subscriptions were updated, false if unchanged
|
|
459
467
|
*/
|
|
460
|
-
updateSubscriptions(getterTracker: GetterTrackerState | null, rawInstance:
|
|
468
|
+
updateSubscriptions(getterTracker: GetterTrackerState | null, rawInstance: StateContainerInstance, onGetterChange: () => void): boolean;
|
|
461
469
|
/**
|
|
462
470
|
* Clean up all active subscriptions
|
|
463
471
|
*/
|
|
@@ -474,13 +482,15 @@ export declare type ExtractConstructorArgs<T> = T extends new (...args: infer P)
|
|
|
474
482
|
* Extract the props type from a StateContainer
|
|
475
483
|
* @template T - The StateContainer type
|
|
476
484
|
*/
|
|
477
|
-
export declare type ExtractProps<T> = T extends
|
|
485
|
+
export declare type ExtractProps<T> = T extends StateContainerConstructor<any, infer P> ? P : undefined;
|
|
478
486
|
|
|
479
487
|
/**
|
|
480
488
|
* Extract the state type from a StateContainer
|
|
481
489
|
* @template T - The StateContainer type
|
|
482
490
|
*/
|
|
483
|
-
export declare type ExtractState<T> = T extends
|
|
491
|
+
export declare type ExtractState<T> = T extends StateContainerConstructor<infer S, any> ? Readonly<S> : never;
|
|
492
|
+
|
|
493
|
+
export declare type ExtractStateMutable<T> = T extends StateContainerConstructor<infer S, any> ? S : never;
|
|
484
494
|
|
|
485
495
|
/**
|
|
486
496
|
* Generate ID with timestamp, counter, and random suffix (tree-shakeable)
|
|
@@ -534,9 +544,6 @@ export declare function generateSimpleId(prefix: string, affix?: string): string
|
|
|
534
544
|
*/
|
|
535
545
|
export declare function getPluginManager(): any;
|
|
536
546
|
|
|
537
|
-
/**
|
|
538
|
-
* Utility functions for accessing static properties on StateContainer classes
|
|
539
|
-
*/
|
|
540
547
|
/**
|
|
541
548
|
* Get a static property from a class constructor
|
|
542
549
|
* Type-safe helper that avoids (Type as any) casts
|
|
@@ -546,13 +553,13 @@ export declare function getPluginManager(): any;
|
|
|
546
553
|
* @param defaultValue - Optional default value if property is undefined
|
|
547
554
|
* @returns The property value or default
|
|
548
555
|
*/
|
|
549
|
-
export declare function getStaticProp<T>(Type:
|
|
556
|
+
export declare function getStaticProp<V, T extends StateContainerConstructor = StateContainerConstructor>(Type: T, propName: string, defaultValue?: V): V | undefined;
|
|
550
557
|
|
|
551
558
|
declare interface GetterExecutionContext {
|
|
552
559
|
tracker: GetterTrackerState | null;
|
|
553
|
-
currentBloc:
|
|
560
|
+
currentBloc: StateContainerInstance | null;
|
|
554
561
|
depth: number;
|
|
555
|
-
visitedBlocs: Set<
|
|
562
|
+
visitedBlocs: Set<StateContainerInstance>;
|
|
556
563
|
}
|
|
557
564
|
|
|
558
565
|
/* Excluded from this release type: GetterTrackerState */
|
|
@@ -591,7 +598,7 @@ export declare const info: (context: string, message: string, data?: any) => voi
|
|
|
591
598
|
* @param instance - The state container instance
|
|
592
599
|
* @returns Initialized adapter state
|
|
593
600
|
*/
|
|
594
|
-
export declare function initAutoTrackState<TBloc extends
|
|
601
|
+
export declare function initAutoTrackState<TBloc extends StateContainerConstructor>(instance: InstanceState<TBloc>): AdapterState<TBloc>;
|
|
595
602
|
|
|
596
603
|
/**
|
|
597
604
|
* Initialize adapter state for manual dependency tracking mode.
|
|
@@ -599,7 +606,7 @@ export declare function initAutoTrackState<TBloc extends StateContainer<any, any
|
|
|
599
606
|
* @param instance - The state container instance
|
|
600
607
|
* @returns Initialized adapter state
|
|
601
608
|
*/
|
|
602
|
-
export declare function initManualDepsState<TBloc extends
|
|
609
|
+
export declare function initManualDepsState<TBloc extends StateContainerConstructor>(instance: InstanceState<TBloc>): AdapterState<TBloc>;
|
|
603
610
|
|
|
604
611
|
/**
|
|
605
612
|
* Initialize adapter state for no-tracking mode.
|
|
@@ -607,7 +614,7 @@ export declare function initManualDepsState<TBloc extends StateContainer<any, an
|
|
|
607
614
|
* @param instance - The state container instance
|
|
608
615
|
* @returns Initialized adapter state
|
|
609
616
|
*/
|
|
610
|
-
export declare function initNoTrackState<TBloc extends
|
|
617
|
+
export declare function initNoTrackState<TBloc extends StateContainerConstructor>(instance: InstanceState<TBloc>): AdapterState<TBloc>;
|
|
611
618
|
|
|
612
619
|
/**
|
|
613
620
|
* Entry in the instance registry, tracking the instance and its reference count
|
|
@@ -653,21 +660,33 @@ export declare interface InstanceMetadata {
|
|
|
653
660
|
currentState?: any;
|
|
654
661
|
}
|
|
655
662
|
|
|
663
|
+
export declare type InstanceReadonlyState<T extends StateContainerConstructor = any> = Omit<InstanceType<T>, 'state'> & {
|
|
664
|
+
state: ExtractState<T>;
|
|
665
|
+
};
|
|
666
|
+
|
|
667
|
+
export declare type InstanceState<T extends StateContainerConstructor = any> = Omit<InstanceType<T>, 'state'> & {
|
|
668
|
+
state: ExtractStateMutable<T>;
|
|
669
|
+
};
|
|
670
|
+
|
|
656
671
|
/* Excluded from this release type: invalidateRenderCache */
|
|
657
672
|
|
|
658
673
|
/**
|
|
659
|
-
* Check if a class should be excluded from DevTools
|
|
660
|
-
* Used to prevent infinite loops when DevTools tracks itself
|
|
674
|
+
* Check if a class should be excluded from DevTools.
|
|
675
|
+
* Used to prevent infinite loops when DevTools tracks itself.
|
|
676
|
+
* @param Type - The class constructor to check
|
|
677
|
+
* @returns true if the class has `static __excludeFromDevTools = true`
|
|
661
678
|
*/
|
|
662
|
-
export declare function isExcludedFromDevTools
|
|
679
|
+
export declare function isExcludedFromDevTools<T extends StateContainerConstructor>(Type: T): boolean;
|
|
663
680
|
|
|
664
681
|
/* Excluded from this release type: isGetter */
|
|
665
682
|
|
|
666
683
|
/**
|
|
667
|
-
* Check if a class is marked as isolated
|
|
668
|
-
* Isolated classes create separate instances per component
|
|
684
|
+
* Check if a class is marked as isolated.
|
|
685
|
+
* Isolated classes create separate instances per component.
|
|
686
|
+
* @param Type - The class constructor to check
|
|
687
|
+
* @returns true if the class has `static isolated = true`
|
|
669
688
|
*/
|
|
670
|
-
export declare function isIsolatedClass
|
|
689
|
+
export declare function isIsolatedClass<T extends StateContainerConstructor>(Type: T): boolean;
|
|
671
690
|
|
|
672
691
|
/**
|
|
673
692
|
* Check if a key is an isolated instance key
|
|
@@ -677,10 +696,12 @@ export declare function isIsolatedClass(Type: new (...args: any[]) => any): bool
|
|
|
677
696
|
export declare function isIsolatedKey(key: string): boolean;
|
|
678
697
|
|
|
679
698
|
/**
|
|
680
|
-
* Check if a class is marked as keepAlive
|
|
681
|
-
* KeepAlive classes are never auto-disposed when ref count reaches 0
|
|
699
|
+
* Check if a class is marked as keepAlive.
|
|
700
|
+
* KeepAlive classes are never auto-disposed when ref count reaches 0.
|
|
701
|
+
* @param Type - The class constructor to check
|
|
702
|
+
* @returns true if the class has `static keepAlive = true`
|
|
682
703
|
*/
|
|
683
|
-
export declare function isKeepAliveClass
|
|
704
|
+
export declare function isKeepAliveClass<T extends StateContainerConstructor>(Type: T): boolean;
|
|
684
705
|
|
|
685
706
|
/* Excluded from this release type: isProxyable */
|
|
686
707
|
|
|
@@ -741,9 +762,9 @@ export declare enum LogLevel {
|
|
|
741
762
|
* Configuration for manual dependency tracking mode
|
|
742
763
|
* @template TBloc - The state container type
|
|
743
764
|
*/
|
|
744
|
-
export declare interface ManualDepsConfig<TBloc extends
|
|
765
|
+
export declare interface ManualDepsConfig<TBloc extends StateContainerConstructor> {
|
|
745
766
|
/** Function that returns dependency array from state and bloc */
|
|
746
|
-
dependencies: (state:
|
|
767
|
+
dependencies: (state: ExtractState<TBloc>, bloc: InstanceState<TBloc>) => any[];
|
|
747
768
|
}
|
|
748
769
|
|
|
749
770
|
/* Excluded from this release type: parsePath */
|
|
@@ -771,7 +792,7 @@ export declare interface PluginContext {
|
|
|
771
792
|
/**
|
|
772
793
|
* Get current state from a container
|
|
773
794
|
*/
|
|
774
|
-
getState<S>(instance: StateContainer<S>): S;
|
|
795
|
+
getState<S extends object = any>(instance: StateContainer<S>): S;
|
|
775
796
|
/**
|
|
776
797
|
* Get all instances of a specific type
|
|
777
798
|
*/
|
|
@@ -892,17 +913,17 @@ export declare type SnapshotFunction<TState> = () => TState;
|
|
|
892
913
|
*
|
|
893
914
|
* @example
|
|
894
915
|
* ```ts
|
|
895
|
-
* class CounterBloc extends StateContainer<number> {
|
|
916
|
+
* class CounterBloc extends StateContainer<{ count: number }> {
|
|
896
917
|
* constructor() {
|
|
897
|
-
* super(0);
|
|
918
|
+
* super({ count: 0 });
|
|
898
919
|
* }
|
|
899
920
|
* increment() {
|
|
900
|
-
* this.emit(this.state + 1);
|
|
921
|
+
* this.emit({ count: this.state.count + 1 });
|
|
901
922
|
* }
|
|
902
923
|
* }
|
|
903
924
|
* ```
|
|
904
925
|
*/
|
|
905
|
-
export declare abstract class StateContainer<S, P =
|
|
926
|
+
export declare abstract class StateContainer<S extends object = any, P = any> {
|
|
906
927
|
/* Excluded from this release type: __excludeFromDevTools */
|
|
907
928
|
/* Excluded from this release type: _registry */
|
|
908
929
|
/**
|
|
@@ -919,17 +940,22 @@ export declare abstract class StateContainer<S, P = undefined> {
|
|
|
919
940
|
* Register this class with the global registry
|
|
920
941
|
* @param isolated - Whether instances should be isolated (component-scoped)
|
|
921
942
|
*/
|
|
922
|
-
static register<T extends
|
|
943
|
+
static register<T extends StateContainerConstructor>(this: T, isolated?: boolean): void;
|
|
923
944
|
/**
|
|
924
945
|
* Resolve an instance with ref counting (ownership semantics).
|
|
925
946
|
* Creates a new instance if one doesn't exist, or returns existing and increments ref count.
|
|
926
947
|
* @template S - Optional state type override for generic StateContainers
|
|
927
948
|
* @template T - The StateContainer type (inferred from class)
|
|
928
949
|
* @param instanceKey - Optional instance key (defaults to 'default')
|
|
929
|
-
* @param
|
|
950
|
+
* @param options - Resolution options (canCreate, countRef, props, trackExecutionContext)
|
|
930
951
|
* @returns The state container instance
|
|
931
952
|
*/
|
|
932
|
-
static resolve<
|
|
953
|
+
static resolve<T extends StateContainerConstructor = StateContainerConstructor>(this: T, instanceKey?: string, options?: {
|
|
954
|
+
canCreate?: boolean;
|
|
955
|
+
countRef?: boolean;
|
|
956
|
+
props?: ExtractProps<T>;
|
|
957
|
+
trackExecutionContext?: boolean;
|
|
958
|
+
}): InstanceType<T>;
|
|
933
959
|
/**
|
|
934
960
|
* Get an existing instance without incrementing ref count (borrowing semantics).
|
|
935
961
|
* @template S - Optional state type override for generic StateContainers
|
|
@@ -938,7 +964,7 @@ export declare abstract class StateContainer<S, P = undefined> {
|
|
|
938
964
|
* @returns The state container instance
|
|
939
965
|
* @throws Error if instance doesn't exist
|
|
940
966
|
*/
|
|
941
|
-
static get<
|
|
967
|
+
static get<T extends StateContainerConstructor<any> = StateContainerConstructor<any>>(this: T, instanceKey?: string): InstanceType<T>;
|
|
942
968
|
/**
|
|
943
969
|
* Safely get an existing instance with error handling.
|
|
944
970
|
* @template S - Optional state type override for generic StateContainers
|
|
@@ -946,44 +972,44 @@ export declare abstract class StateContainer<S, P = undefined> {
|
|
|
946
972
|
* @param instanceKey - Optional instance key (defaults to 'default')
|
|
947
973
|
* @returns Discriminated union with either the instance or an error
|
|
948
974
|
*/
|
|
949
|
-
static getSafe<
|
|
975
|
+
static getSafe<T extends StateContainerConstructor<any> = StateContainerConstructor<any>>(this: T, instanceKey?: string): {
|
|
950
976
|
error: Error;
|
|
951
977
|
instance: null;
|
|
952
978
|
} | {
|
|
953
979
|
error: null;
|
|
954
|
-
instance:
|
|
980
|
+
instance: InstanceType<T>;
|
|
955
981
|
};
|
|
956
982
|
/**
|
|
957
983
|
* Connect to an instance for bloc-to-bloc communication (borrowing semantics).
|
|
958
984
|
* Gets or creates instance without incrementing ref count.
|
|
985
|
+
* Tracks cross-bloc dependency for reactive updates.
|
|
959
986
|
* @template S - Optional state type override for generic StateContainers
|
|
960
987
|
* @template T - The StateContainer type (inferred from class)
|
|
961
988
|
* @param instanceKey - Optional instance key (defaults to 'default')
|
|
962
|
-
* @param constructorArgs - Arguments to pass to constructor if creating new instance
|
|
963
989
|
* @returns The state container instance
|
|
964
990
|
*/
|
|
965
|
-
static connect<
|
|
991
|
+
static connect<T extends StateContainerConstructor<any> = StateContainerConstructor<any>>(this: T, instanceKey?: string): InstanceType<T>;
|
|
966
992
|
/**
|
|
967
993
|
* Release a reference to an instance.
|
|
968
994
|
* Decrements ref count and disposes when it reaches 0 (unless keepAlive).
|
|
969
995
|
* @param instanceKey - Optional instance key (defaults to 'default')
|
|
970
996
|
* @param forceDispose - Force immediate disposal regardless of ref count
|
|
971
997
|
*/
|
|
972
|
-
static release<T extends
|
|
998
|
+
static release<T extends StateContainerConstructor = StateContainerConstructor>(this: T, instanceKey?: string, forceDispose?: boolean): void;
|
|
973
999
|
/**
|
|
974
1000
|
* Get all instances of this class
|
|
975
1001
|
* @returns Array of all instances
|
|
976
1002
|
*/
|
|
977
|
-
static getAll<T extends
|
|
1003
|
+
static getAll<T extends StateContainerConstructor = StateContainerConstructor>(this: T): InstanceReadonlyState<T>[];
|
|
978
1004
|
/**
|
|
979
1005
|
* Iterate over all instances of this class
|
|
980
1006
|
* @param callback - Function to call for each instance
|
|
981
1007
|
*/
|
|
982
|
-
static forEach<T extends
|
|
1008
|
+
static forEach<T extends StateContainerConstructor = StateContainerConstructor>(this: T, callback: (instance: InstanceReadonlyState<T>) => void): void;
|
|
983
1009
|
/**
|
|
984
1010
|
* Clear all instances of this class (disposes them)
|
|
985
1011
|
*/
|
|
986
|
-
static clear<T extends
|
|
1012
|
+
static clear<T extends StateContainerConstructor = StateContainerConstructor>(this: T): void;
|
|
987
1013
|
/**
|
|
988
1014
|
* Clear all instances from all registered types
|
|
989
1015
|
*/
|
|
@@ -1002,13 +1028,13 @@ export declare abstract class StateContainer<S, P = undefined> {
|
|
|
1002
1028
|
* @param instanceKey - Optional instance key (defaults to 'default')
|
|
1003
1029
|
* @returns Current ref count (0 if instance doesn't exist)
|
|
1004
1030
|
*/
|
|
1005
|
-
static getRefCount<T extends
|
|
1031
|
+
static getRefCount<T extends StateContainerConstructor = StateContainerConstructor>(this: T, instanceKey?: string): number;
|
|
1006
1032
|
/**
|
|
1007
1033
|
* Check if an instance exists
|
|
1008
1034
|
* @param instanceKey - Optional instance key (defaults to 'default')
|
|
1009
1035
|
* @returns true if instance exists
|
|
1010
1036
|
*/
|
|
1011
|
-
static hasInstance<T extends
|
|
1037
|
+
static hasInstance<T extends StateContainerConstructor = StateContainerConstructor>(this: T, instanceKey?: string): boolean;
|
|
1012
1038
|
private _state;
|
|
1013
1039
|
private readonly listeners;
|
|
1014
1040
|
private _disposed;
|
|
@@ -1033,7 +1059,7 @@ export declare abstract class StateContainer<S, P = undefined> {
|
|
|
1033
1059
|
*/
|
|
1034
1060
|
initConfig(config: StateContainerConfig): void;
|
|
1035
1061
|
/** Current state value */
|
|
1036
|
-
get state(): S
|
|
1062
|
+
get state(): Readonly<S>;
|
|
1037
1063
|
/** Whether this instance has been disposed */
|
|
1038
1064
|
get isDisposed(): boolean;
|
|
1039
1065
|
/**
|
|
@@ -1095,6 +1121,17 @@ export declare interface StateContainerConfig {
|
|
|
1095
1121
|
instanceId?: string;
|
|
1096
1122
|
}
|
|
1097
1123
|
|
|
1124
|
+
/**
|
|
1125
|
+
* Constructor type for StateContainer classes
|
|
1126
|
+
* @template S - State type managed by the container
|
|
1127
|
+
* @template P - Props type passed to the container
|
|
1128
|
+
*/
|
|
1129
|
+
export declare type StateContainerConstructor<S extends object = any, P = any> = new (...args: any[]) => StateContainer<S, P>;
|
|
1130
|
+
|
|
1131
|
+
export declare type StateContainerInstance<S extends object = any, P = any> = Omit<StateContainer<S, P>, 'state'> & {
|
|
1132
|
+
state: Readonly<S>;
|
|
1133
|
+
};
|
|
1134
|
+
|
|
1098
1135
|
/**
|
|
1099
1136
|
* Central registry for managing StateContainer instances.
|
|
1100
1137
|
* Handles instance lifecycle, ref counting, and lifecycle event emission.
|
|
@@ -1117,77 +1154,113 @@ export declare class StateContainerRegistry {
|
|
|
1117
1154
|
* Register a type for lifecycle event tracking
|
|
1118
1155
|
* @param constructor - The StateContainer class constructor
|
|
1119
1156
|
*/
|
|
1120
|
-
registerType<T extends
|
|
1157
|
+
registerType<T extends StateContainerConstructor>(constructor: T): void;
|
|
1121
1158
|
/**
|
|
1122
1159
|
* Register a StateContainer class with configuration
|
|
1123
1160
|
* @param constructor - The StateContainer class constructor
|
|
1124
1161
|
* @param isolated - Whether instances should be isolated (component-scoped)
|
|
1125
1162
|
* @throws Error if type is already registered
|
|
1126
1163
|
*/
|
|
1127
|
-
register<T extends
|
|
1164
|
+
register<T extends StateContainerConstructor>(constructor: T, isolated?: boolean): void;
|
|
1128
1165
|
private ensureInstancesMap;
|
|
1129
1166
|
/**
|
|
1130
1167
|
* Get the instances Map for a specific class (public API for stats/debugging)
|
|
1131
1168
|
*/
|
|
1132
|
-
getInstancesMap<T extends
|
|
1169
|
+
getInstancesMap<T extends StateContainerConstructor>(Type: T): Map<string, InstanceEntry>;
|
|
1170
|
+
private trackExecutionContext;
|
|
1133
1171
|
/**
|
|
1134
|
-
* Resolve an instance with ref counting (ownership semantics)
|
|
1172
|
+
* Resolve an instance with ref counting (ownership semantics).
|
|
1173
|
+
* Creates a new instance if one doesn't exist, or returns existing and increments ref count.
|
|
1174
|
+
* @param Type - The StateContainer class constructor
|
|
1175
|
+
* @param instanceKey - Instance key (defaults to 'default')
|
|
1176
|
+
* @param options - Resolution options
|
|
1177
|
+
* @param options.canCreate - Whether to create new instance if not found (default: true)
|
|
1178
|
+
* @param options.countRef - Whether to increment ref count (default: true)
|
|
1179
|
+
* @param options.props - Props to pass to constructor if creating new instance
|
|
1180
|
+
* @param options.trackExecutionContext - Whether to track cross-bloc dependency (default: false)
|
|
1181
|
+
* @returns The state container instance
|
|
1135
1182
|
*/
|
|
1136
|
-
resolve<T extends
|
|
1183
|
+
resolve<T extends StateContainerConstructor = StateContainerConstructor>(Type: T, instanceKey?: string, options?: {
|
|
1184
|
+
canCreate?: boolean;
|
|
1185
|
+
countRef?: boolean;
|
|
1186
|
+
props?: ExtractProps<T>;
|
|
1187
|
+
trackExecutionContext?: boolean;
|
|
1188
|
+
}): InstanceType<T>;
|
|
1137
1189
|
/**
|
|
1138
|
-
* Get an existing instance without ref
|
|
1190
|
+
* Get an existing instance without incrementing ref count (borrowing semantics).
|
|
1191
|
+
* Tracks cross-bloc dependency for reactive updates.
|
|
1192
|
+
* @param Type - The StateContainer class constructor
|
|
1193
|
+
* @param instanceKey - Instance key (defaults to 'default')
|
|
1194
|
+
* @returns The state container instance
|
|
1139
1195
|
* @throws Error if instance doesn't exist
|
|
1140
1196
|
*/
|
|
1141
|
-
get<T extends
|
|
1197
|
+
get<T extends StateContainerConstructor = StateContainerConstructor>(Type: T, instanceKey?: string): InstanceType<T>;
|
|
1142
1198
|
/**
|
|
1143
|
-
* Safely get an existing instance (borrowing semantics with error handling)
|
|
1144
|
-
* Returns discriminated union for type-safe conditional access
|
|
1199
|
+
* Safely get an existing instance (borrowing semantics with error handling).
|
|
1200
|
+
* Returns discriminated union for type-safe conditional access.
|
|
1201
|
+
* @param Type - The StateContainer class constructor
|
|
1202
|
+
* @param instanceKey - Instance key (defaults to 'default')
|
|
1203
|
+
* @returns Discriminated union with either the instance or an error
|
|
1145
1204
|
*/
|
|
1146
|
-
getSafe<T extends
|
|
1205
|
+
getSafe<T extends StateContainerConstructor = StateContainerConstructor>(Type: T, instanceKey?: string): {
|
|
1147
1206
|
error: Error;
|
|
1148
1207
|
instance: null;
|
|
1149
1208
|
} | {
|
|
1150
1209
|
error: null;
|
|
1151
|
-
instance: T
|
|
1210
|
+
instance: InstanceType<T>;
|
|
1152
1211
|
};
|
|
1153
1212
|
/**
|
|
1154
|
-
* Connect to an instance with borrowing semantics (for B2B communication)
|
|
1213
|
+
* Connect to an instance with borrowing semantics (for B2B communication).
|
|
1155
1214
|
* Gets existing instance OR creates it if it doesn't exist, without incrementing ref count.
|
|
1156
1215
|
* Tracks cross-bloc dependency for reactive updates.
|
|
1157
1216
|
*
|
|
1158
1217
|
* Use this in bloc-to-bloc communication when you need to ensure an instance exists
|
|
1159
1218
|
* but don't want to claim ownership (no ref count increment).
|
|
1160
|
-
*
|
|
1161
|
-
* @param
|
|
1162
|
-
* @
|
|
1163
|
-
* @param constructorArgs - Constructor arguments (only used if creating new instance)
|
|
1164
|
-
* @returns The bloc instance
|
|
1219
|
+
* @param Type - The StateContainer class constructor
|
|
1220
|
+
* @param instanceKey - Instance key (defaults to 'default')
|
|
1221
|
+
* @returns The state container instance
|
|
1165
1222
|
*/
|
|
1166
|
-
connect<T extends
|
|
1223
|
+
connect<T extends StateContainerConstructor = StateContainerConstructor>(Type: T, instanceKey?: string): InstanceType<T>;
|
|
1167
1224
|
/**
|
|
1168
|
-
* Release a reference to an instance
|
|
1225
|
+
* Release a reference to an instance.
|
|
1226
|
+
* Decrements ref count and disposes when it reaches 0 (unless keepAlive).
|
|
1227
|
+
* @param Type - The StateContainer class constructor
|
|
1228
|
+
* @param instanceKey - Instance key (defaults to 'default')
|
|
1229
|
+
* @param forceDispose - Force immediate disposal regardless of ref count
|
|
1169
1230
|
*/
|
|
1170
|
-
release<T extends
|
|
1231
|
+
release<T extends StateContainerConstructor>(Type: T, instanceKey?: string, forceDispose?: boolean): void;
|
|
1171
1232
|
/**
|
|
1172
|
-
* Get all instances of a specific type
|
|
1233
|
+
* Get all instances of a specific type.
|
|
1234
|
+
* @param Type - The StateContainer class constructor
|
|
1235
|
+
* @returns Array of all instances
|
|
1173
1236
|
*/
|
|
1174
|
-
getAll<T extends
|
|
1237
|
+
getAll<T extends StateContainerConstructor>(Type: T): InstanceReadonlyState<T>[];
|
|
1175
1238
|
/**
|
|
1176
|
-
* Safely iterate over all instances of a type
|
|
1239
|
+
* Safely iterate over all instances of a type.
|
|
1240
|
+
* Skips disposed instances and catches callback errors.
|
|
1241
|
+
* @param Type - The StateContainer class constructor
|
|
1242
|
+
* @param callback - Function to call for each instance
|
|
1177
1243
|
*/
|
|
1178
|
-
forEach<T extends
|
|
1244
|
+
forEach<T extends StateContainerConstructor>(Type: T, callback: (instance: InstanceReadonlyState<T>) => void): void;
|
|
1179
1245
|
/**
|
|
1180
|
-
* Clear all instances of a specific type
|
|
1246
|
+
* Clear all instances of a specific type (disposes them).
|
|
1247
|
+
* @param Type - The StateContainer class constructor
|
|
1181
1248
|
*/
|
|
1182
|
-
clear<T extends
|
|
1249
|
+
clear<T extends StateContainerConstructor>(Type: T): void;
|
|
1183
1250
|
/**
|
|
1184
|
-
* Get reference count for an instance
|
|
1251
|
+
* Get reference count for an instance.
|
|
1252
|
+
* @param Type - The StateContainer class constructor
|
|
1253
|
+
* @param instanceKey - Instance key (defaults to 'default')
|
|
1254
|
+
* @returns Current ref count (0 if instance doesn't exist)
|
|
1185
1255
|
*/
|
|
1186
|
-
getRefCount<T extends
|
|
1256
|
+
getRefCount<T extends StateContainerConstructor>(Type: T, instanceKey?: string): number;
|
|
1187
1257
|
/**
|
|
1188
|
-
* Check if an instance exists
|
|
1258
|
+
* Check if an instance exists.
|
|
1259
|
+
* @param Type - The StateContainer class constructor
|
|
1260
|
+
* @param instanceKey - Instance key (defaults to 'default')
|
|
1261
|
+
* @returns true if instance exists
|
|
1189
1262
|
*/
|
|
1190
|
-
hasInstance<T extends
|
|
1263
|
+
hasInstance<T extends StateContainerConstructor>(Type: T, instanceKey?: string): boolean;
|
|
1191
1264
|
/**
|
|
1192
1265
|
* Clear all instances from all types (for testing)
|
|
1193
1266
|
*
|
|
@@ -1196,7 +1269,8 @@ export declare class StateContainerRegistry {
|
|
|
1196
1269
|
*/
|
|
1197
1270
|
clearAll(): void;
|
|
1198
1271
|
/**
|
|
1199
|
-
* Get registry statistics
|
|
1272
|
+
* Get registry statistics for debugging.
|
|
1273
|
+
* @returns Object with registeredTypes, totalInstances, and typeBreakdown
|
|
1200
1274
|
*/
|
|
1201
1275
|
getStats(): {
|
|
1202
1276
|
registeredTypes: number;
|
|
@@ -1204,9 +1278,10 @@ export declare class StateContainerRegistry {
|
|
|
1204
1278
|
typeBreakdown: Record<string, number>;
|
|
1205
1279
|
};
|
|
1206
1280
|
/**
|
|
1207
|
-
* Get all registered types (for plugin system)
|
|
1281
|
+
* Get all registered types (for plugin system).
|
|
1282
|
+
* @returns Array of all registered StateContainer class constructors
|
|
1208
1283
|
*/
|
|
1209
|
-
getTypes():
|
|
1284
|
+
getTypes(): StateContainerConstructor[];
|
|
1210
1285
|
/**
|
|
1211
1286
|
* Subscribe to lifecycle events
|
|
1212
1287
|
* @param event - The lifecycle event to listen for
|
|
@@ -1219,25 +1294,6 @@ export declare class StateContainerRegistry {
|
|
|
1219
1294
|
|
|
1220
1295
|
/* Excluded from this release type: StateListener */
|
|
1221
1296
|
|
|
1222
|
-
/**
|
|
1223
|
-
* Conditionally override the state type of a StateContainer.
|
|
1224
|
-
* When S is `never`, returns T unchanged (inferred state type).
|
|
1225
|
-
* When S is provided, replaces the state type while preserving all other properties.
|
|
1226
|
-
*
|
|
1227
|
-
* @template T - The StateContainer type
|
|
1228
|
-
* @template S - The state type override (defaults to never)
|
|
1229
|
-
*
|
|
1230
|
-
* @example
|
|
1231
|
-
* // Without override - returns original type
|
|
1232
|
-
* type Result1 = StateOverride<MyBloc>; // MyBloc
|
|
1233
|
-
*
|
|
1234
|
-
* // With override - replaces state type
|
|
1235
|
-
* type Result2 = StateOverride<MyBloc, CustomState>; // Omit<MyBloc, 'state'> & { readonly state: CustomState }
|
|
1236
|
-
*/
|
|
1237
|
-
export declare type StateOverride<T extends StateContainer<any, any>, S = never> = [S] extends [never] ? T : Omit<T, 'state'> & {
|
|
1238
|
-
readonly state: S;
|
|
1239
|
-
};
|
|
1240
|
-
|
|
1241
1297
|
/* Excluded from this release type: stopProxyTracking */
|
|
1242
1298
|
|
|
1243
1299
|
/**
|
|
@@ -1287,7 +1343,7 @@ export declare interface SystemEventPayloads<S, P> {
|
|
|
1287
1343
|
* @template E - Event type (extends BaseEvent)
|
|
1288
1344
|
* @template P - Props type (optional)
|
|
1289
1345
|
*/
|
|
1290
|
-
export declare abstract class Vertex<S, E extends BaseEvent = BaseEvent, P = undefined> extends StateContainer<S, P> {
|
|
1346
|
+
export declare abstract class Vertex<S extends object = any, E extends BaseEvent = BaseEvent, P = undefined> extends StateContainer<S, P> {
|
|
1291
1347
|
private eventHandlers;
|
|
1292
1348
|
private isProcessing;
|
|
1293
1349
|
private eventQueue;
|