@blac/react 2.0.0-rc.4 → 2.0.0-rc.6

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.d.cts CHANGED
@@ -1,222 +1,8 @@
1
+ import { AnyObject, BlocConstructor, ExtractState, StateContainer } from "@blac/core";
1
2
  import { RefObject } from "react";
2
3
 
3
- //#region ../blac/src/core/StateContainerRegistry.d.ts
4
-
5
- /**
6
- * Registry for managing StateContainer instances
7
- */
8
- declare class StateContainerRegistry {
9
- private readonly instances;
10
- private readonly types;
11
- /**
12
- * Register a type with isolation mode
13
- */
14
- register<T extends StateContainer<any>>(constructor: new (...args: any[]) => T, isolated?: boolean): void;
15
- /**
16
- * Get or create a StateContainer instance
17
- * For isolated: always creates new
18
- * For shared: singleton per key
19
- */
20
- getOrCreate<T extends StateContainer<any>>(constructor: new (...args: any[]) => T, key?: string, ...args: any[]): T;
21
- /**
22
- * Release a reference to an instance
23
- * Disposes when ref count reaches zero (unless static keepAlive is true)
24
- */
25
- release<T extends StateContainer<any>>(constructor: new (...args: any[]) => T, key?: string, forceDispose?: boolean): void;
26
- /**
27
- * Get all instances of a type (shared only, isolated aren't tracked)
28
- */
29
- getAll<T extends StateContainer<any>>(constructor: new (...args: any[]) => T): T[];
30
- /**
31
- * Clear all instances of a type
32
- */
33
- clear<T extends StateContainer<any>>(constructor: new (...args: any[]) => T): void;
34
- /**
35
- * Clear all instances from all types (for testing)
36
- */
37
- clearAll(): void;
38
- /**
39
- * Get registry statistics (for debugging)
40
- */
41
- getStats(): {
42
- registeredTypes: number;
43
- totalInstances: number;
44
- typeBreakdown: Record<string, number>;
45
- };
46
- /**
47
- * Get reference count for an instance
48
- */
49
- getRefCount<T extends StateContainer<any>>(constructor: new (...args: any[]) => T, key?: string): number;
50
- /**
51
- * Check if an instance exists
52
- */
53
- hasInstance<T extends StateContainer<any>>(constructor: new (...args: any[]) => T, key?: string): boolean;
54
- }
55
- //#endregion
56
- //#region ../blac/src/core/StateContainer.d.ts
57
- /**
58
- * Configuration options for StateContainer
59
- */
60
- interface StateContainerConfig {
61
- /** Container name for debugging */
62
- name?: string;
63
- /** Enable debug logging */
64
- debug?: boolean;
65
- /** Custom instance identifier */
66
- instanceId?: string;
67
- }
68
- /**
69
- * Listener function for state changes
70
- */
71
- type StateListener<S$1> = (state: S$1) => void;
72
- /**
73
- * Base abstract class for all state containers
74
- */
75
- declare abstract class StateContainer<S$1> {
76
- private static _registry;
77
- /**
78
- * Set a custom registry (mainly for testing)
79
- */
80
- static setRegistry(registry: StateContainerRegistry): void;
81
- /**
82
- * Register a type as isolated or shared
83
- */
84
- static register<T extends StateContainer<any>>(this: new (...args: any[]) => T, isolated?: boolean): void;
85
- /**
86
- * Get or create an instance
87
- * @param key - Optional instance key for shared instances
88
- * @param args - Constructor arguments
89
- */
90
- static getOrCreate<T extends StateContainer<any>>(this: new (...args: any[]) => T, key?: string, ...args: any[]): T;
91
- /**
92
- * Release a reference to an instance
93
- * @param key - Optional instance key
94
- * @param forceDispose - Force dispose regardless of ref count or keepAlive
95
- */
96
- static release<T extends StateContainer<any>>(this: new (...args: any[]) => T, key?: string, forceDispose?: boolean): void;
97
- /**
98
- * Get all instances of this type
99
- */
100
- static getAll<T extends StateContainer<any>>(this: new (...args: any[]) => T): T[];
101
- /**
102
- * Clear all instances of this type
103
- */
104
- static clear<T extends StateContainer<any>>(this: new (...args: any[]) => T): void;
105
- /**
106
- * Clear all instances from all types (for testing)
107
- */
108
- static clearAllInstances(): void;
109
- /**
110
- * Get registry statistics (for debugging)
111
- */
112
- static getStats(): {
113
- registeredTypes: number;
114
- totalInstances: number;
115
- typeBreakdown: Record<string, number>;
116
- };
117
- /**
118
- * Get reference count for an instance
119
- * @param key - Optional instance key
120
- */
121
- static getRefCount<T extends StateContainer<any>>(this: new (...args: any[]) => T, key?: string): number;
122
- /**
123
- * Check if an instance exists
124
- * @param key - Optional instance key
125
- */
126
- static hasInstance<T extends StateContainer<any>>(this: new (...args: any[]) => T, key?: string): boolean;
127
- private _state;
128
- private readonly listeners;
129
- private _disposed;
130
- private readonly config;
131
- readonly name: string;
132
- readonly debug: boolean;
133
- readonly instanceId: string;
134
- /**
135
- * Create a new StateContainer
136
- */
137
- constructor(initialState: S$1, config?: StateContainerConfig);
138
- /**
139
- * Get the current state
140
- */
141
- get state(): S$1;
142
- /**
143
- * Check if disposed
144
- */
145
- get isDisposed(): boolean;
146
- /**
147
- * Subscribe to state changes
148
- * @returns Unsubscribe function
149
- */
150
- subscribe(listener: StateListener<S$1>): () => void;
151
- /**
152
- * Dispose the container
153
- */
154
- dispose(): void;
155
- /**
156
- * Emit a new state (with change detection)
157
- */
158
- protected emit(newState: S$1): void;
159
- /**
160
- * Update state using a function
161
- */
162
- protected update(updater: (current: S$1) => S$1): void;
163
- /**
164
- * Optional disposal hook for subclasses
165
- */
166
- protected onDispose?(): void;
167
- /**
168
- * Optional state change hook for subclasses
169
- */
170
- protected onStateChange?(newState: S$1, previousState: S$1): void;
171
- }
172
- //#endregion
173
- //#region ../blac/src/types/branded.d.ts
174
- /**
175
- * Branded types for type-safe IDs
176
- * These types ensure that IDs can't be accidentally mixed up
177
- */
178
- /**
179
- * Helper type for cases where any object type is acceptable
180
- * Used sparingly only where type cannot be more specific
181
- * eslint-disable-next-line @typescript-eslint/no-explicit-any
182
- */
183
- type AnyObject = any;
184
- //#endregion
185
- //#region ../blac/src/types/utilities.d.ts
186
- /**
187
- * Extract state type from StateContainer
188
- *
189
- * @example
190
- * ```ts
191
- * class CounterBloc extends Cubit<number> { ... }
192
- * type State = ExtractState<CounterBloc>; // number
193
- * ```
194
- */
195
- type ExtractState<T$1> = T$1 extends StateContainer<infer S> ? S : never;
196
- /**
197
- * Bloc constructor type - represents a class constructor for StateContainer subclasses
198
- * Includes static methods from StateContainer for instance management
199
- *
200
- * Note: Uses `any` for state type to support variance - the actual Bloc instance
201
- * will have the correct specific types inferred at usage sites.
202
- *
203
- * @example
204
- * ```ts
205
- * function createBloc<TBloc extends StateContainer<any>>(
206
- * BlocClass: BlocConstructor<TBloc>
207
- * ): TBloc {
208
- * return BlocClass.getOrCreate();
209
- * }
210
- * ```
211
- */
212
- type BlocConstructor<TBloc extends StateContainer<any>> = (new (...args: any[]) => TBloc) & {
213
- getOrCreate?(instanceKey?: string, ...args: any[]): TBloc;
214
- release?(instanceKey?: string): void;
215
- isolated?: boolean;
216
- keepAlive?: boolean;
217
- };
218
- //#endregion
219
4
  //#region src/types.d.ts
5
+
220
6
  /**
221
7
  * Configuration options for the useBloc hook
222
8
  *
package/dist/index.d.ts CHANGED
@@ -1,222 +1,8 @@
1
1
  import { RefObject } from "react";
2
+ import { AnyObject, BlocConstructor, ExtractState, StateContainer } from "@blac/core";
2
3
 
3
- //#region ../blac/src/core/StateContainerRegistry.d.ts
4
-
5
- /**
6
- * Registry for managing StateContainer instances
7
- */
8
- declare class StateContainerRegistry {
9
- private readonly instances;
10
- private readonly types;
11
- /**
12
- * Register a type with isolation mode
13
- */
14
- register<T extends StateContainer<any>>(constructor: new (...args: any[]) => T, isolated?: boolean): void;
15
- /**
16
- * Get or create a StateContainer instance
17
- * For isolated: always creates new
18
- * For shared: singleton per key
19
- */
20
- getOrCreate<T extends StateContainer<any>>(constructor: new (...args: any[]) => T, key?: string, ...args: any[]): T;
21
- /**
22
- * Release a reference to an instance
23
- * Disposes when ref count reaches zero (unless static keepAlive is true)
24
- */
25
- release<T extends StateContainer<any>>(constructor: new (...args: any[]) => T, key?: string, forceDispose?: boolean): void;
26
- /**
27
- * Get all instances of a type (shared only, isolated aren't tracked)
28
- */
29
- getAll<T extends StateContainer<any>>(constructor: new (...args: any[]) => T): T[];
30
- /**
31
- * Clear all instances of a type
32
- */
33
- clear<T extends StateContainer<any>>(constructor: new (...args: any[]) => T): void;
34
- /**
35
- * Clear all instances from all types (for testing)
36
- */
37
- clearAll(): void;
38
- /**
39
- * Get registry statistics (for debugging)
40
- */
41
- getStats(): {
42
- registeredTypes: number;
43
- totalInstances: number;
44
- typeBreakdown: Record<string, number>;
45
- };
46
- /**
47
- * Get reference count for an instance
48
- */
49
- getRefCount<T extends StateContainer<any>>(constructor: new (...args: any[]) => T, key?: string): number;
50
- /**
51
- * Check if an instance exists
52
- */
53
- hasInstance<T extends StateContainer<any>>(constructor: new (...args: any[]) => T, key?: string): boolean;
54
- }
55
- //#endregion
56
- //#region ../blac/src/core/StateContainer.d.ts
57
- /**
58
- * Configuration options for StateContainer
59
- */
60
- interface StateContainerConfig {
61
- /** Container name for debugging */
62
- name?: string;
63
- /** Enable debug logging */
64
- debug?: boolean;
65
- /** Custom instance identifier */
66
- instanceId?: string;
67
- }
68
- /**
69
- * Listener function for state changes
70
- */
71
- type StateListener<S$1> = (state: S$1) => void;
72
- /**
73
- * Base abstract class for all state containers
74
- */
75
- declare abstract class StateContainer<S$1> {
76
- private static _registry;
77
- /**
78
- * Set a custom registry (mainly for testing)
79
- */
80
- static setRegistry(registry: StateContainerRegistry): void;
81
- /**
82
- * Register a type as isolated or shared
83
- */
84
- static register<T extends StateContainer<any>>(this: new (...args: any[]) => T, isolated?: boolean): void;
85
- /**
86
- * Get or create an instance
87
- * @param key - Optional instance key for shared instances
88
- * @param args - Constructor arguments
89
- */
90
- static getOrCreate<T extends StateContainer<any>>(this: new (...args: any[]) => T, key?: string, ...args: any[]): T;
91
- /**
92
- * Release a reference to an instance
93
- * @param key - Optional instance key
94
- * @param forceDispose - Force dispose regardless of ref count or keepAlive
95
- */
96
- static release<T extends StateContainer<any>>(this: new (...args: any[]) => T, key?: string, forceDispose?: boolean): void;
97
- /**
98
- * Get all instances of this type
99
- */
100
- static getAll<T extends StateContainer<any>>(this: new (...args: any[]) => T): T[];
101
- /**
102
- * Clear all instances of this type
103
- */
104
- static clear<T extends StateContainer<any>>(this: new (...args: any[]) => T): void;
105
- /**
106
- * Clear all instances from all types (for testing)
107
- */
108
- static clearAllInstances(): void;
109
- /**
110
- * Get registry statistics (for debugging)
111
- */
112
- static getStats(): {
113
- registeredTypes: number;
114
- totalInstances: number;
115
- typeBreakdown: Record<string, number>;
116
- };
117
- /**
118
- * Get reference count for an instance
119
- * @param key - Optional instance key
120
- */
121
- static getRefCount<T extends StateContainer<any>>(this: new (...args: any[]) => T, key?: string): number;
122
- /**
123
- * Check if an instance exists
124
- * @param key - Optional instance key
125
- */
126
- static hasInstance<T extends StateContainer<any>>(this: new (...args: any[]) => T, key?: string): boolean;
127
- private _state;
128
- private readonly listeners;
129
- private _disposed;
130
- private readonly config;
131
- readonly name: string;
132
- readonly debug: boolean;
133
- readonly instanceId: string;
134
- /**
135
- * Create a new StateContainer
136
- */
137
- constructor(initialState: S$1, config?: StateContainerConfig);
138
- /**
139
- * Get the current state
140
- */
141
- get state(): S$1;
142
- /**
143
- * Check if disposed
144
- */
145
- get isDisposed(): boolean;
146
- /**
147
- * Subscribe to state changes
148
- * @returns Unsubscribe function
149
- */
150
- subscribe(listener: StateListener<S$1>): () => void;
151
- /**
152
- * Dispose the container
153
- */
154
- dispose(): void;
155
- /**
156
- * Emit a new state (with change detection)
157
- */
158
- protected emit(newState: S$1): void;
159
- /**
160
- * Update state using a function
161
- */
162
- protected update(updater: (current: S$1) => S$1): void;
163
- /**
164
- * Optional disposal hook for subclasses
165
- */
166
- protected onDispose?(): void;
167
- /**
168
- * Optional state change hook for subclasses
169
- */
170
- protected onStateChange?(newState: S$1, previousState: S$1): void;
171
- }
172
- //#endregion
173
- //#region ../blac/src/types/branded.d.ts
174
- /**
175
- * Branded types for type-safe IDs
176
- * These types ensure that IDs can't be accidentally mixed up
177
- */
178
- /**
179
- * Helper type for cases where any object type is acceptable
180
- * Used sparingly only where type cannot be more specific
181
- * eslint-disable-next-line @typescript-eslint/no-explicit-any
182
- */
183
- type AnyObject = any;
184
- //#endregion
185
- //#region ../blac/src/types/utilities.d.ts
186
- /**
187
- * Extract state type from StateContainer
188
- *
189
- * @example
190
- * ```ts
191
- * class CounterBloc extends Cubit<number> { ... }
192
- * type State = ExtractState<CounterBloc>; // number
193
- * ```
194
- */
195
- type ExtractState<T$1> = T$1 extends StateContainer<infer S> ? S : never;
196
- /**
197
- * Bloc constructor type - represents a class constructor for StateContainer subclasses
198
- * Includes static methods from StateContainer for instance management
199
- *
200
- * Note: Uses `any` for state type to support variance - the actual Bloc instance
201
- * will have the correct specific types inferred at usage sites.
202
- *
203
- * @example
204
- * ```ts
205
- * function createBloc<TBloc extends StateContainer<any>>(
206
- * BlocClass: BlocConstructor<TBloc>
207
- * ): TBloc {
208
- * return BlocClass.getOrCreate();
209
- * }
210
- * ```
211
- */
212
- type BlocConstructor<TBloc extends StateContainer<any>> = (new (...args: any[]) => TBloc) & {
213
- getOrCreate?(instanceKey?: string, ...args: any[]): TBloc;
214
- release?(instanceKey?: string): void;
215
- isolated?: boolean;
216
- keepAlive?: boolean;
217
- };
218
- //#endregion
219
4
  //#region src/types.d.ts
5
+
220
6
  /**
221
7
  * Configuration options for the useBloc hook
222
8
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blac/react",
3
- "version": "2.0.0-rc.4",
3
+ "version": "2.0.0-rc.6",
4
4
  "license": "MIT",
5
5
  "author": "Brendan Mullins <jsnanigans@gmail.com>",
6
6
  "main": "./dist/index.js",
@@ -36,7 +36,7 @@
36
36
  "peerDependencies": {
37
37
  "@types/react": "^18.0.0 || ^19.0.0",
38
38
  "react": "^18.0.0 || ^19.0.0",
39
- "@blac/core": "2.0.0-rc.4"
39
+ "@blac/core": "2.0.0-rc.6"
40
40
  },
41
41
  "peerDependenciesMeta": {
42
42
  "@types/react": {
@@ -65,7 +65,7 @@
65
65
  "tsdown": "^0.15.7",
66
66
  "typescript": "^5.9.2",
67
67
  "vitest": "^3.2.4",
68
- "@blac/core": "2.0.0-rc.4"
68
+ "@blac/core": "2.0.0-rc.6"
69
69
  },
70
70
  "scripts": {
71
71
  "dev": "tsdown --watch",