@blac/core 2.0.0-rc.14 → 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 +6 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +47 -33
- package/dist/index.d.ts +47 -33
- package/dist/index.js +6 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
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>> {
|
|
|
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,7 +199,7 @@ 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<S = any, T extends new (...args: any[]) => StateContainer<S, any> = new (...args: any[]) => StateContainer<S, any>> = (new (...args: any[]) => InstanceType<T>) & {
|
|
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
203
|
resolve(instanceKey?: string, ...args: any[]): InstanceType<T>;
|
|
204
204
|
get(instanceKey?: string, ...args: any[]): InstanceType<T> | null;
|
|
205
205
|
getSafe(instanceKey?: string, ...args: any[]): {
|
|
@@ -267,7 +267,7 @@ export declare function configureLogger(opts: Partial<LogConfig>): void;
|
|
|
267
267
|
* @param adapterState - The adapter state for tracking
|
|
268
268
|
* @returns Snapshot function for use with useSyncExternalStore
|
|
269
269
|
*/
|
|
270
|
-
export declare function createAutoTrackSnapshot<TBloc extends
|
|
270
|
+
export declare function createAutoTrackSnapshot<TBloc extends StateContainerConstructor>(instance: InstanceReadonlyState<TBloc>, adapterState: AdapterState<TBloc>): SnapshotFunction<ExtractState<TBloc>>;
|
|
271
271
|
|
|
272
272
|
/**
|
|
273
273
|
* Create a subscribe function for auto-tracking mode.
|
|
@@ -276,7 +276,7 @@ export declare function createAutoTrackSnapshot<TBloc extends StateContainer<any
|
|
|
276
276
|
* @param adapterState - The adapter state for tracking
|
|
277
277
|
* @returns Subscribe function for use with useSyncExternalStore
|
|
278
278
|
*/
|
|
279
|
-
export declare function createAutoTrackSubscribe<TBloc extends
|
|
279
|
+
export declare function createAutoTrackSubscribe<TBloc extends StateContainerConstructor>(instance: InstanceReadonlyState<TBloc>, adapterState: AdapterState<TBloc>): SubscribeFunction;
|
|
280
280
|
|
|
281
281
|
/* Excluded from this release type: createBlocProxy */
|
|
282
282
|
|
|
@@ -339,7 +339,7 @@ export declare function createLogger(config: LogConfig): {
|
|
|
339
339
|
* @param config - Configuration with dependencies function
|
|
340
340
|
* @returns Snapshot function for use with useSyncExternalStore
|
|
341
341
|
*/
|
|
342
|
-
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>>;
|
|
343
343
|
|
|
344
344
|
/**
|
|
345
345
|
* Create a subscribe function for manual dependency tracking mode.
|
|
@@ -349,7 +349,7 @@ export declare function createManualDepsSnapshot<TBloc extends StateContainer<an
|
|
|
349
349
|
* @param config - Configuration with dependencies function
|
|
350
350
|
* @returns Subscribe function for use with useSyncExternalStore
|
|
351
351
|
*/
|
|
352
|
-
export declare function createManualDepsSubscribe<TBloc extends
|
|
352
|
+
export declare function createManualDepsSubscribe<TBloc extends StateContainerConstructor>(instance: InstanceState<TBloc>, adapterState: AdapterState<TBloc>, config: ManualDepsConfig<TBloc>): SubscribeFunction;
|
|
353
353
|
|
|
354
354
|
/**
|
|
355
355
|
* Create a snapshot function for no-tracking mode.
|
|
@@ -357,7 +357,7 @@ export declare function createManualDepsSubscribe<TBloc extends StateContainer<a
|
|
|
357
357
|
* @param instance - The state container instance
|
|
358
358
|
* @returns Snapshot function for use with useSyncExternalStore
|
|
359
359
|
*/
|
|
360
|
-
export declare function createNoTrackSnapshot<TBloc extends
|
|
360
|
+
export declare function createNoTrackSnapshot<TBloc extends StateContainerConstructor>(instance: InstanceReadonlyState<TBloc>): SnapshotFunction<ExtractState<TBloc>>;
|
|
361
361
|
|
|
362
362
|
/**
|
|
363
363
|
* Create a subscribe function for no-tracking mode.
|
|
@@ -365,7 +365,7 @@ export declare function createNoTrackSnapshot<TBloc extends StateContainer<any,
|
|
|
365
365
|
* @param instance - The state container instance
|
|
366
366
|
* @returns Subscribe function for use with useSyncExternalStore
|
|
367
367
|
*/
|
|
368
|
-
export declare function createNoTrackSubscribe<TBloc extends
|
|
368
|
+
export declare function createNoTrackSubscribe<TBloc extends StateContainerInstance>(instance: TBloc): SubscribeFunction;
|
|
369
369
|
|
|
370
370
|
/**
|
|
371
371
|
* Create a plugin manager instance
|
|
@@ -391,7 +391,7 @@ export declare function createPluginManager(registry: StateContainerRegistry): P
|
|
|
391
391
|
* @template S - State type
|
|
392
392
|
* @template P - Props type (optional)
|
|
393
393
|
*/
|
|
394
|
-
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> {
|
|
395
395
|
constructor(initialState: S);
|
|
396
396
|
/**
|
|
397
397
|
* Replace state with a new value and notify all listeners
|
|
@@ -423,7 +423,7 @@ export declare const debug: (context: string, message: string, data?: any) => vo
|
|
|
423
423
|
* @param adapterState - The adapter state
|
|
424
424
|
* @param rawInstance - The raw bloc instance
|
|
425
425
|
*/
|
|
426
|
-
export declare function disableGetterTracking<TBloc extends
|
|
426
|
+
export declare function disableGetterTracking<TBloc extends StateContainerConstructor>(adapterState: AdapterState<TBloc>, rawInstance: InstanceState<TBloc>): void;
|
|
427
427
|
|
|
428
428
|
/**
|
|
429
429
|
* Log an error message (tree-shakeable export)
|
|
@@ -465,7 +465,7 @@ export declare class ExternalDependencyManager {
|
|
|
465
465
|
* @param onGetterChange - Callback to invoke when external dependency changes
|
|
466
466
|
* @returns true if subscriptions were updated, false if unchanged
|
|
467
467
|
*/
|
|
468
|
-
updateSubscriptions(getterTracker: GetterTrackerState | null, rawInstance:
|
|
468
|
+
updateSubscriptions(getterTracker: GetterTrackerState | null, rawInstance: StateContainerInstance, onGetterChange: () => void): boolean;
|
|
469
469
|
/**
|
|
470
470
|
* Clean up all active subscriptions
|
|
471
471
|
*/
|
|
@@ -488,7 +488,9 @@ export declare type ExtractProps<T> = T extends StateContainerConstructor<any, i
|
|
|
488
488
|
* Extract the state type from a StateContainer
|
|
489
489
|
* @template T - The StateContainer type
|
|
490
490
|
*/
|
|
491
|
-
export declare type ExtractState<T> = T extends StateContainerConstructor<infer S, any> ? S : never;
|
|
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;
|
|
492
494
|
|
|
493
495
|
/**
|
|
494
496
|
* Generate ID with timestamp, counter, and random suffix (tree-shakeable)
|
|
@@ -555,9 +557,9 @@ export declare function getStaticProp<V, T extends StateContainerConstructor = S
|
|
|
555
557
|
|
|
556
558
|
declare interface GetterExecutionContext {
|
|
557
559
|
tracker: GetterTrackerState | null;
|
|
558
|
-
currentBloc:
|
|
560
|
+
currentBloc: StateContainerInstance | null;
|
|
559
561
|
depth: number;
|
|
560
|
-
visitedBlocs: Set<
|
|
562
|
+
visitedBlocs: Set<StateContainerInstance>;
|
|
561
563
|
}
|
|
562
564
|
|
|
563
565
|
/* Excluded from this release type: GetterTrackerState */
|
|
@@ -596,7 +598,7 @@ export declare const info: (context: string, message: string, data?: any) => voi
|
|
|
596
598
|
* @param instance - The state container instance
|
|
597
599
|
* @returns Initialized adapter state
|
|
598
600
|
*/
|
|
599
|
-
export declare function initAutoTrackState<TBloc extends
|
|
601
|
+
export declare function initAutoTrackState<TBloc extends StateContainerConstructor>(instance: InstanceState<TBloc>): AdapterState<TBloc>;
|
|
600
602
|
|
|
601
603
|
/**
|
|
602
604
|
* Initialize adapter state for manual dependency tracking mode.
|
|
@@ -604,7 +606,7 @@ export declare function initAutoTrackState<TBloc extends StateContainer<any, any
|
|
|
604
606
|
* @param instance - The state container instance
|
|
605
607
|
* @returns Initialized adapter state
|
|
606
608
|
*/
|
|
607
|
-
export declare function initManualDepsState<TBloc extends
|
|
609
|
+
export declare function initManualDepsState<TBloc extends StateContainerConstructor>(instance: InstanceState<TBloc>): AdapterState<TBloc>;
|
|
608
610
|
|
|
609
611
|
/**
|
|
610
612
|
* Initialize adapter state for no-tracking mode.
|
|
@@ -612,7 +614,7 @@ export declare function initManualDepsState<TBloc extends StateContainer<any, an
|
|
|
612
614
|
* @param instance - The state container instance
|
|
613
615
|
* @returns Initialized adapter state
|
|
614
616
|
*/
|
|
615
|
-
export declare function initNoTrackState<TBloc extends
|
|
617
|
+
export declare function initNoTrackState<TBloc extends StateContainerConstructor>(instance: InstanceState<TBloc>): AdapterState<TBloc>;
|
|
616
618
|
|
|
617
619
|
/**
|
|
618
620
|
* Entry in the instance registry, tracking the instance and its reference count
|
|
@@ -658,6 +660,14 @@ export declare interface InstanceMetadata {
|
|
|
658
660
|
currentState?: any;
|
|
659
661
|
}
|
|
660
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
|
+
|
|
661
671
|
/* Excluded from this release type: invalidateRenderCache */
|
|
662
672
|
|
|
663
673
|
/**
|
|
@@ -752,9 +762,9 @@ export declare enum LogLevel {
|
|
|
752
762
|
* Configuration for manual dependency tracking mode
|
|
753
763
|
* @template TBloc - The state container type
|
|
754
764
|
*/
|
|
755
|
-
export declare interface ManualDepsConfig<TBloc extends
|
|
765
|
+
export declare interface ManualDepsConfig<TBloc extends StateContainerConstructor> {
|
|
756
766
|
/** Function that returns dependency array from state and bloc */
|
|
757
|
-
dependencies: (state:
|
|
767
|
+
dependencies: (state: ExtractState<TBloc>, bloc: InstanceState<TBloc>) => any[];
|
|
758
768
|
}
|
|
759
769
|
|
|
760
770
|
/* Excluded from this release type: parsePath */
|
|
@@ -782,7 +792,7 @@ export declare interface PluginContext {
|
|
|
782
792
|
/**
|
|
783
793
|
* Get current state from a container
|
|
784
794
|
*/
|
|
785
|
-
getState<S>(instance: StateContainer<S>): S;
|
|
795
|
+
getState<S extends object = any>(instance: StateContainer<S>): S;
|
|
786
796
|
/**
|
|
787
797
|
* Get all instances of a specific type
|
|
788
798
|
*/
|
|
@@ -903,17 +913,17 @@ export declare type SnapshotFunction<TState> = () => TState;
|
|
|
903
913
|
*
|
|
904
914
|
* @example
|
|
905
915
|
* ```ts
|
|
906
|
-
* class CounterBloc extends StateContainer<number> {
|
|
916
|
+
* class CounterBloc extends StateContainer<{ count: number }> {
|
|
907
917
|
* constructor() {
|
|
908
|
-
* super(0);
|
|
918
|
+
* super({ count: 0 });
|
|
909
919
|
* }
|
|
910
920
|
* increment() {
|
|
911
|
-
* this.emit(this.state + 1);
|
|
921
|
+
* this.emit({ count: this.state.count + 1 });
|
|
912
922
|
* }
|
|
913
923
|
* }
|
|
914
924
|
* ```
|
|
915
925
|
*/
|
|
916
|
-
export declare abstract class StateContainer<S = any, P = any> {
|
|
926
|
+
export declare abstract class StateContainer<S extends object = any, P = any> {
|
|
917
927
|
/* Excluded from this release type: __excludeFromDevTools */
|
|
918
928
|
/* Excluded from this release type: _registry */
|
|
919
929
|
/**
|
|
@@ -990,12 +1000,12 @@ export declare abstract class StateContainer<S = any, P = any> {
|
|
|
990
1000
|
* Get all instances of this class
|
|
991
1001
|
* @returns Array of all instances
|
|
992
1002
|
*/
|
|
993
|
-
static getAll<T extends StateContainerConstructor = StateContainerConstructor>(this: T):
|
|
1003
|
+
static getAll<T extends StateContainerConstructor = StateContainerConstructor>(this: T): InstanceReadonlyState<T>[];
|
|
994
1004
|
/**
|
|
995
1005
|
* Iterate over all instances of this class
|
|
996
1006
|
* @param callback - Function to call for each instance
|
|
997
1007
|
*/
|
|
998
|
-
static forEach<T extends StateContainerConstructor = StateContainerConstructor>(this: T, callback: (instance:
|
|
1008
|
+
static forEach<T extends StateContainerConstructor = StateContainerConstructor>(this: T, callback: (instance: InstanceReadonlyState<T>) => void): void;
|
|
999
1009
|
/**
|
|
1000
1010
|
* Clear all instances of this class (disposes them)
|
|
1001
1011
|
*/
|
|
@@ -1049,7 +1059,7 @@ export declare abstract class StateContainer<S = any, P = any> {
|
|
|
1049
1059
|
*/
|
|
1050
1060
|
initConfig(config: StateContainerConfig): void;
|
|
1051
1061
|
/** Current state value */
|
|
1052
|
-
get state(): S
|
|
1062
|
+
get state(): Readonly<S>;
|
|
1053
1063
|
/** Whether this instance has been disposed */
|
|
1054
1064
|
get isDisposed(): boolean;
|
|
1055
1065
|
/**
|
|
@@ -1116,7 +1126,11 @@ export declare interface StateContainerConfig {
|
|
|
1116
1126
|
* @template S - State type managed by the container
|
|
1117
1127
|
* @template P - Props type passed to the container
|
|
1118
1128
|
*/
|
|
1119
|
-
export declare type StateContainerConstructor<S = any, P = any> = new (...args: any[]) => StateContainer<S, P>;
|
|
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
|
+
};
|
|
1120
1134
|
|
|
1121
1135
|
/**
|
|
1122
1136
|
* Central registry for managing StateContainer instances.
|
|
@@ -1220,14 +1234,14 @@ export declare class StateContainerRegistry {
|
|
|
1220
1234
|
* @param Type - The StateContainer class constructor
|
|
1221
1235
|
* @returns Array of all instances
|
|
1222
1236
|
*/
|
|
1223
|
-
getAll<T extends StateContainerConstructor>(Type: T):
|
|
1237
|
+
getAll<T extends StateContainerConstructor>(Type: T): InstanceReadonlyState<T>[];
|
|
1224
1238
|
/**
|
|
1225
1239
|
* Safely iterate over all instances of a type.
|
|
1226
1240
|
* Skips disposed instances and catches callback errors.
|
|
1227
1241
|
* @param Type - The StateContainer class constructor
|
|
1228
1242
|
* @param callback - Function to call for each instance
|
|
1229
1243
|
*/
|
|
1230
|
-
forEach<T extends StateContainerConstructor>(Type: T, callback: (instance:
|
|
1244
|
+
forEach<T extends StateContainerConstructor>(Type: T, callback: (instance: InstanceReadonlyState<T>) => void): void;
|
|
1231
1245
|
/**
|
|
1232
1246
|
* Clear all instances of a specific type (disposes them).
|
|
1233
1247
|
* @param Type - The StateContainer class constructor
|
|
@@ -1329,7 +1343,7 @@ export declare interface SystemEventPayloads<S, P> {
|
|
|
1329
1343
|
* @template E - Event type (extends BaseEvent)
|
|
1330
1344
|
* @template P - Props type (optional)
|
|
1331
1345
|
*/
|
|
1332
|
-
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> {
|
|
1333
1347
|
private eventHandlers;
|
|
1334
1348
|
private isProcessing;
|
|
1335
1349
|
private eventQueue;
|
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>> {
|
|
|
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,7 +199,7 @@ 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<S = any, T extends new (...args: any[]) => StateContainer<S, any> = new (...args: any[]) => StateContainer<S, any>> = (new (...args: any[]) => InstanceType<T>) & {
|
|
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
203
|
resolve(instanceKey?: string, ...args: any[]): InstanceType<T>;
|
|
204
204
|
get(instanceKey?: string, ...args: any[]): InstanceType<T> | null;
|
|
205
205
|
getSafe(instanceKey?: string, ...args: any[]): {
|
|
@@ -267,7 +267,7 @@ export declare function configureLogger(opts: Partial<LogConfig>): void;
|
|
|
267
267
|
* @param adapterState - The adapter state for tracking
|
|
268
268
|
* @returns Snapshot function for use with useSyncExternalStore
|
|
269
269
|
*/
|
|
270
|
-
export declare function createAutoTrackSnapshot<TBloc extends
|
|
270
|
+
export declare function createAutoTrackSnapshot<TBloc extends StateContainerConstructor>(instance: InstanceReadonlyState<TBloc>, adapterState: AdapterState<TBloc>): SnapshotFunction<ExtractState<TBloc>>;
|
|
271
271
|
|
|
272
272
|
/**
|
|
273
273
|
* Create a subscribe function for auto-tracking mode.
|
|
@@ -276,7 +276,7 @@ export declare function createAutoTrackSnapshot<TBloc extends StateContainer<any
|
|
|
276
276
|
* @param adapterState - The adapter state for tracking
|
|
277
277
|
* @returns Subscribe function for use with useSyncExternalStore
|
|
278
278
|
*/
|
|
279
|
-
export declare function createAutoTrackSubscribe<TBloc extends
|
|
279
|
+
export declare function createAutoTrackSubscribe<TBloc extends StateContainerConstructor>(instance: InstanceReadonlyState<TBloc>, adapterState: AdapterState<TBloc>): SubscribeFunction;
|
|
280
280
|
|
|
281
281
|
/* Excluded from this release type: createBlocProxy */
|
|
282
282
|
|
|
@@ -339,7 +339,7 @@ export declare function createLogger(config: LogConfig): {
|
|
|
339
339
|
* @param config - Configuration with dependencies function
|
|
340
340
|
* @returns Snapshot function for use with useSyncExternalStore
|
|
341
341
|
*/
|
|
342
|
-
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>>;
|
|
343
343
|
|
|
344
344
|
/**
|
|
345
345
|
* Create a subscribe function for manual dependency tracking mode.
|
|
@@ -349,7 +349,7 @@ export declare function createManualDepsSnapshot<TBloc extends StateContainer<an
|
|
|
349
349
|
* @param config - Configuration with dependencies function
|
|
350
350
|
* @returns Subscribe function for use with useSyncExternalStore
|
|
351
351
|
*/
|
|
352
|
-
export declare function createManualDepsSubscribe<TBloc extends
|
|
352
|
+
export declare function createManualDepsSubscribe<TBloc extends StateContainerConstructor>(instance: InstanceState<TBloc>, adapterState: AdapterState<TBloc>, config: ManualDepsConfig<TBloc>): SubscribeFunction;
|
|
353
353
|
|
|
354
354
|
/**
|
|
355
355
|
* Create a snapshot function for no-tracking mode.
|
|
@@ -357,7 +357,7 @@ export declare function createManualDepsSubscribe<TBloc extends StateContainer<a
|
|
|
357
357
|
* @param instance - The state container instance
|
|
358
358
|
* @returns Snapshot function for use with useSyncExternalStore
|
|
359
359
|
*/
|
|
360
|
-
export declare function createNoTrackSnapshot<TBloc extends
|
|
360
|
+
export declare function createNoTrackSnapshot<TBloc extends StateContainerConstructor>(instance: InstanceReadonlyState<TBloc>): SnapshotFunction<ExtractState<TBloc>>;
|
|
361
361
|
|
|
362
362
|
/**
|
|
363
363
|
* Create a subscribe function for no-tracking mode.
|
|
@@ -365,7 +365,7 @@ export declare function createNoTrackSnapshot<TBloc extends StateContainer<any,
|
|
|
365
365
|
* @param instance - The state container instance
|
|
366
366
|
* @returns Subscribe function for use with useSyncExternalStore
|
|
367
367
|
*/
|
|
368
|
-
export declare function createNoTrackSubscribe<TBloc extends
|
|
368
|
+
export declare function createNoTrackSubscribe<TBloc extends StateContainerInstance>(instance: TBloc): SubscribeFunction;
|
|
369
369
|
|
|
370
370
|
/**
|
|
371
371
|
* Create a plugin manager instance
|
|
@@ -391,7 +391,7 @@ export declare function createPluginManager(registry: StateContainerRegistry): P
|
|
|
391
391
|
* @template S - State type
|
|
392
392
|
* @template P - Props type (optional)
|
|
393
393
|
*/
|
|
394
|
-
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> {
|
|
395
395
|
constructor(initialState: S);
|
|
396
396
|
/**
|
|
397
397
|
* Replace state with a new value and notify all listeners
|
|
@@ -423,7 +423,7 @@ export declare const debug: (context: string, message: string, data?: any) => vo
|
|
|
423
423
|
* @param adapterState - The adapter state
|
|
424
424
|
* @param rawInstance - The raw bloc instance
|
|
425
425
|
*/
|
|
426
|
-
export declare function disableGetterTracking<TBloc extends
|
|
426
|
+
export declare function disableGetterTracking<TBloc extends StateContainerConstructor>(adapterState: AdapterState<TBloc>, rawInstance: InstanceState<TBloc>): void;
|
|
427
427
|
|
|
428
428
|
/**
|
|
429
429
|
* Log an error message (tree-shakeable export)
|
|
@@ -465,7 +465,7 @@ export declare class ExternalDependencyManager {
|
|
|
465
465
|
* @param onGetterChange - Callback to invoke when external dependency changes
|
|
466
466
|
* @returns true if subscriptions were updated, false if unchanged
|
|
467
467
|
*/
|
|
468
|
-
updateSubscriptions(getterTracker: GetterTrackerState | null, rawInstance:
|
|
468
|
+
updateSubscriptions(getterTracker: GetterTrackerState | null, rawInstance: StateContainerInstance, onGetterChange: () => void): boolean;
|
|
469
469
|
/**
|
|
470
470
|
* Clean up all active subscriptions
|
|
471
471
|
*/
|
|
@@ -488,7 +488,9 @@ export declare type ExtractProps<T> = T extends StateContainerConstructor<any, i
|
|
|
488
488
|
* Extract the state type from a StateContainer
|
|
489
489
|
* @template T - The StateContainer type
|
|
490
490
|
*/
|
|
491
|
-
export declare type ExtractState<T> = T extends StateContainerConstructor<infer S, any> ? S : never;
|
|
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;
|
|
492
494
|
|
|
493
495
|
/**
|
|
494
496
|
* Generate ID with timestamp, counter, and random suffix (tree-shakeable)
|
|
@@ -555,9 +557,9 @@ export declare function getStaticProp<V, T extends StateContainerConstructor = S
|
|
|
555
557
|
|
|
556
558
|
declare interface GetterExecutionContext {
|
|
557
559
|
tracker: GetterTrackerState | null;
|
|
558
|
-
currentBloc:
|
|
560
|
+
currentBloc: StateContainerInstance | null;
|
|
559
561
|
depth: number;
|
|
560
|
-
visitedBlocs: Set<
|
|
562
|
+
visitedBlocs: Set<StateContainerInstance>;
|
|
561
563
|
}
|
|
562
564
|
|
|
563
565
|
/* Excluded from this release type: GetterTrackerState */
|
|
@@ -596,7 +598,7 @@ export declare const info: (context: string, message: string, data?: any) => voi
|
|
|
596
598
|
* @param instance - The state container instance
|
|
597
599
|
* @returns Initialized adapter state
|
|
598
600
|
*/
|
|
599
|
-
export declare function initAutoTrackState<TBloc extends
|
|
601
|
+
export declare function initAutoTrackState<TBloc extends StateContainerConstructor>(instance: InstanceState<TBloc>): AdapterState<TBloc>;
|
|
600
602
|
|
|
601
603
|
/**
|
|
602
604
|
* Initialize adapter state for manual dependency tracking mode.
|
|
@@ -604,7 +606,7 @@ export declare function initAutoTrackState<TBloc extends StateContainer<any, any
|
|
|
604
606
|
* @param instance - The state container instance
|
|
605
607
|
* @returns Initialized adapter state
|
|
606
608
|
*/
|
|
607
|
-
export declare function initManualDepsState<TBloc extends
|
|
609
|
+
export declare function initManualDepsState<TBloc extends StateContainerConstructor>(instance: InstanceState<TBloc>): AdapterState<TBloc>;
|
|
608
610
|
|
|
609
611
|
/**
|
|
610
612
|
* Initialize adapter state for no-tracking mode.
|
|
@@ -612,7 +614,7 @@ export declare function initManualDepsState<TBloc extends StateContainer<any, an
|
|
|
612
614
|
* @param instance - The state container instance
|
|
613
615
|
* @returns Initialized adapter state
|
|
614
616
|
*/
|
|
615
|
-
export declare function initNoTrackState<TBloc extends
|
|
617
|
+
export declare function initNoTrackState<TBloc extends StateContainerConstructor>(instance: InstanceState<TBloc>): AdapterState<TBloc>;
|
|
616
618
|
|
|
617
619
|
/**
|
|
618
620
|
* Entry in the instance registry, tracking the instance and its reference count
|
|
@@ -658,6 +660,14 @@ export declare interface InstanceMetadata {
|
|
|
658
660
|
currentState?: any;
|
|
659
661
|
}
|
|
660
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
|
+
|
|
661
671
|
/* Excluded from this release type: invalidateRenderCache */
|
|
662
672
|
|
|
663
673
|
/**
|
|
@@ -752,9 +762,9 @@ export declare enum LogLevel {
|
|
|
752
762
|
* Configuration for manual dependency tracking mode
|
|
753
763
|
* @template TBloc - The state container type
|
|
754
764
|
*/
|
|
755
|
-
export declare interface ManualDepsConfig<TBloc extends
|
|
765
|
+
export declare interface ManualDepsConfig<TBloc extends StateContainerConstructor> {
|
|
756
766
|
/** Function that returns dependency array from state and bloc */
|
|
757
|
-
dependencies: (state:
|
|
767
|
+
dependencies: (state: ExtractState<TBloc>, bloc: InstanceState<TBloc>) => any[];
|
|
758
768
|
}
|
|
759
769
|
|
|
760
770
|
/* Excluded from this release type: parsePath */
|
|
@@ -782,7 +792,7 @@ export declare interface PluginContext {
|
|
|
782
792
|
/**
|
|
783
793
|
* Get current state from a container
|
|
784
794
|
*/
|
|
785
|
-
getState<S>(instance: StateContainer<S>): S;
|
|
795
|
+
getState<S extends object = any>(instance: StateContainer<S>): S;
|
|
786
796
|
/**
|
|
787
797
|
* Get all instances of a specific type
|
|
788
798
|
*/
|
|
@@ -903,17 +913,17 @@ export declare type SnapshotFunction<TState> = () => TState;
|
|
|
903
913
|
*
|
|
904
914
|
* @example
|
|
905
915
|
* ```ts
|
|
906
|
-
* class CounterBloc extends StateContainer<number> {
|
|
916
|
+
* class CounterBloc extends StateContainer<{ count: number }> {
|
|
907
917
|
* constructor() {
|
|
908
|
-
* super(0);
|
|
918
|
+
* super({ count: 0 });
|
|
909
919
|
* }
|
|
910
920
|
* increment() {
|
|
911
|
-
* this.emit(this.state + 1);
|
|
921
|
+
* this.emit({ count: this.state.count + 1 });
|
|
912
922
|
* }
|
|
913
923
|
* }
|
|
914
924
|
* ```
|
|
915
925
|
*/
|
|
916
|
-
export declare abstract class StateContainer<S = any, P = any> {
|
|
926
|
+
export declare abstract class StateContainer<S extends object = any, P = any> {
|
|
917
927
|
/* Excluded from this release type: __excludeFromDevTools */
|
|
918
928
|
/* Excluded from this release type: _registry */
|
|
919
929
|
/**
|
|
@@ -990,12 +1000,12 @@ export declare abstract class StateContainer<S = any, P = any> {
|
|
|
990
1000
|
* Get all instances of this class
|
|
991
1001
|
* @returns Array of all instances
|
|
992
1002
|
*/
|
|
993
|
-
static getAll<T extends StateContainerConstructor = StateContainerConstructor>(this: T):
|
|
1003
|
+
static getAll<T extends StateContainerConstructor = StateContainerConstructor>(this: T): InstanceReadonlyState<T>[];
|
|
994
1004
|
/**
|
|
995
1005
|
* Iterate over all instances of this class
|
|
996
1006
|
* @param callback - Function to call for each instance
|
|
997
1007
|
*/
|
|
998
|
-
static forEach<T extends StateContainerConstructor = StateContainerConstructor>(this: T, callback: (instance:
|
|
1008
|
+
static forEach<T extends StateContainerConstructor = StateContainerConstructor>(this: T, callback: (instance: InstanceReadonlyState<T>) => void): void;
|
|
999
1009
|
/**
|
|
1000
1010
|
* Clear all instances of this class (disposes them)
|
|
1001
1011
|
*/
|
|
@@ -1049,7 +1059,7 @@ export declare abstract class StateContainer<S = any, P = any> {
|
|
|
1049
1059
|
*/
|
|
1050
1060
|
initConfig(config: StateContainerConfig): void;
|
|
1051
1061
|
/** Current state value */
|
|
1052
|
-
get state(): S
|
|
1062
|
+
get state(): Readonly<S>;
|
|
1053
1063
|
/** Whether this instance has been disposed */
|
|
1054
1064
|
get isDisposed(): boolean;
|
|
1055
1065
|
/**
|
|
@@ -1116,7 +1126,11 @@ export declare interface StateContainerConfig {
|
|
|
1116
1126
|
* @template S - State type managed by the container
|
|
1117
1127
|
* @template P - Props type passed to the container
|
|
1118
1128
|
*/
|
|
1119
|
-
export declare type StateContainerConstructor<S = any, P = any> = new (...args: any[]) => StateContainer<S, P>;
|
|
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
|
+
};
|
|
1120
1134
|
|
|
1121
1135
|
/**
|
|
1122
1136
|
* Central registry for managing StateContainer instances.
|
|
@@ -1220,14 +1234,14 @@ export declare class StateContainerRegistry {
|
|
|
1220
1234
|
* @param Type - The StateContainer class constructor
|
|
1221
1235
|
* @returns Array of all instances
|
|
1222
1236
|
*/
|
|
1223
|
-
getAll<T extends StateContainerConstructor>(Type: T):
|
|
1237
|
+
getAll<T extends StateContainerConstructor>(Type: T): InstanceReadonlyState<T>[];
|
|
1224
1238
|
/**
|
|
1225
1239
|
* Safely iterate over all instances of a type.
|
|
1226
1240
|
* Skips disposed instances and catches callback errors.
|
|
1227
1241
|
* @param Type - The StateContainer class constructor
|
|
1228
1242
|
* @param callback - Function to call for each instance
|
|
1229
1243
|
*/
|
|
1230
|
-
forEach<T extends StateContainerConstructor>(Type: T, callback: (instance:
|
|
1244
|
+
forEach<T extends StateContainerConstructor>(Type: T, callback: (instance: InstanceReadonlyState<T>) => void): void;
|
|
1231
1245
|
/**
|
|
1232
1246
|
* Clear all instances of a specific type (disposes them).
|
|
1233
1247
|
* @param Type - The StateContainer class constructor
|
|
@@ -1329,7 +1343,7 @@ export declare interface SystemEventPayloads<S, P> {
|
|
|
1329
1343
|
* @template E - Event type (extends BaseEvent)
|
|
1330
1344
|
* @template P - Props type (optional)
|
|
1331
1345
|
*/
|
|
1332
|
-
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> {
|
|
1333
1347
|
private eventHandlers;
|
|
1334
1348
|
private isProcessing;
|
|
1335
1349
|
private eventQueue;
|
package/dist/index.js
CHANGED
|
@@ -833,7 +833,9 @@ var StateContainerRegistry = class {
|
|
|
833
833
|
*/
|
|
834
834
|
on(event, listener) {
|
|
835
835
|
if (!this.listeners.has(event)) this.listeners.set(event, /* @__PURE__ */ new Set());
|
|
836
|
-
this.listeners.get(event)
|
|
836
|
+
const instance = this.listeners.get(event);
|
|
837
|
+
if (!instance) throw new Error(`${BLAC_ERROR_PREFIX} Failed to register listener for event '${event}'`);
|
|
838
|
+
instance.add(listener);
|
|
837
839
|
return () => {
|
|
838
840
|
this.listeners.get(event)?.delete(listener);
|
|
839
841
|
};
|
|
@@ -880,12 +882,12 @@ function getPluginManager() {
|
|
|
880
882
|
*
|
|
881
883
|
* @example
|
|
882
884
|
* ```ts
|
|
883
|
-
* class CounterBloc extends StateContainer<number> {
|
|
885
|
+
* class CounterBloc extends StateContainer<{ count: number }> {
|
|
884
886
|
* constructor() {
|
|
885
|
-
* super(0);
|
|
887
|
+
* super({ count: 0 });
|
|
886
888
|
* }
|
|
887
889
|
* increment() {
|
|
888
|
-
* this.emit(this.state + 1);
|
|
890
|
+
* this.emit({ count: this.state.count + 1 });
|
|
889
891
|
* }
|
|
890
892
|
* }
|
|
891
893
|
* ```
|