@blac/react 2.0.0-rc.5 → 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,307 +1,8 @@
1
+ import { AnyObject, BlocConstructor, ExtractState, StateContainer } from "@blac/core";
1
2
  import { RefObject } from "react";
2
3
 
3
- //#region ../blac/src/types/events.d.ts
4
-
5
- /**
6
- * Base event interface for type-safe event system
7
- */
8
- /**
9
- * Base event interface
10
- * Used by Vertex for event-driven state management
11
- */
12
- interface BaseEvent {
13
- readonly type: string;
14
- readonly timestamp: number;
15
- readonly source?: string;
16
- }
17
- //#endregion
18
- //#region ../blac/src/core/Vertex.d.ts
19
-
20
- /**
21
- * Event handler signature (synchronous only)
22
- */
23
- type EventHandler<E$1 extends BaseEvent, S$1> = (event: E$1, emit: (state: S$1) => void) => void;
24
- /**
25
- * Type-safe event constructor
26
- */
27
- type EventConstructor<T$1 extends BaseEvent = BaseEvent> = new (...args: never[]) => T$1;
28
- /**
29
- * Vertex is an event-driven state container (Bloc pattern)
30
- *
31
- * Includes its own simple event system since events are only needed
32
- * for the Vertex pattern, not for the base StateContainer.
33
- */
34
- declare abstract class Vertex<S$1, E$1 extends BaseEvent = BaseEvent> extends StateContainer<S$1> {
35
- private eventHandlers;
36
- private isProcessing;
37
- private eventQueue;
38
- /**
39
- * Create a new Vertex
40
- * @param initialState Initial state value
41
- * @param config Configuration options
42
- */
43
- constructor(initialState: S$1, config?: StateContainerConfig);
44
- /**
45
- * Register an event handler
46
- * Arrow function to maintain correct 'this' binding
47
- */
48
- protected on: <T extends E$1>(EventClass: EventConstructor<T>, handler: EventHandler<T, S$1>) => void;
49
- /**
50
- * Add an event to be processed
51
- * Arrow function to maintain correct 'this' binding in React
52
- */
53
- add: (event: E$1) => void;
54
- /**
55
- * Process an event (synchronously)
56
- */
57
- private processEvent;
58
- /**
59
- * Handle a single event (synchronously)
60
- */
61
- private handleEvent;
62
- /**
63
- * Hook for handling event processing errors
64
- */
65
- protected onEventError(event: E$1, error: Error): void;
66
- }
67
- //#endregion
68
- //#region ../blac/src/core/StateContainerRegistry.d.ts
69
- /**
70
- * Lifecycle events that can be observed
71
- */
72
- type LifecycleEvent = 'created' | 'stateChanged' | 'eventAdded' | 'disposed';
73
- /**
74
- * Listener function types for each lifecycle event
75
- */
76
- type LifecycleListener<E$1 extends LifecycleEvent> = E$1 extends 'created' ? (container: StateContainer<any>) => void : E$1 extends 'stateChanged' ? (container: StateContainer<any>, previousState: any, currentState: any) => void : E$1 extends 'eventAdded' ? (container: Vertex<any, any>, event: any) => void : E$1 extends 'disposed' ? (container: StateContainer<any>) => void : never;
77
- /**
78
- * Registry for managing StateContainer instances
79
- */
80
- declare class StateContainerRegistry {
81
- private readonly instances;
82
- private readonly types;
83
- private readonly listeners;
84
- /**
85
- * Register a type with isolation mode
86
- */
87
- register<T extends StateContainer<any>>(constructor: new (...args: any[]) => T, isolated?: boolean): void;
88
- /**
89
- * Get or create a StateContainer instance
90
- * For isolated: always creates new
91
- * For shared: singleton per key
92
- */
93
- getOrCreate<T extends StateContainer<any>>(constructor: new (...args: any[]) => T, key?: string, ...args: any[]): T;
94
- /**
95
- * Release a reference to an instance
96
- * Disposes when ref count reaches zero (unless static keepAlive is true)
97
- */
98
- release<T extends StateContainer<any>>(constructor: new (...args: any[]) => T, key?: string, forceDispose?: boolean): void;
99
- /**
100
- * Get all instances of a type (shared only, isolated aren't tracked)
101
- */
102
- getAll<T extends StateContainer<any>>(constructor: new (...args: any[]) => T): T[];
103
- /**
104
- * Clear all instances of a type
105
- */
106
- clear<T extends StateContainer<any>>(constructor: new (...args: any[]) => T): void;
107
- /**
108
- * Clear all instances from all types (for testing)
109
- */
110
- clearAll(): void;
111
- /**
112
- * Get registry statistics (for debugging)
113
- */
114
- getStats(): {
115
- registeredTypes: number;
116
- totalInstances: number;
117
- typeBreakdown: Record<string, number>;
118
- };
119
- /**
120
- * Get reference count for an instance
121
- */
122
- getRefCount<T extends StateContainer<any>>(constructor: new (...args: any[]) => T, key?: string): number;
123
- /**
124
- * Check if an instance exists
125
- */
126
- hasInstance<T extends StateContainer<any>>(constructor: new (...args: any[]) => T, key?: string): boolean;
127
- /**
128
- * Subscribe to lifecycle events
129
- * @param event - The lifecycle event to listen for
130
- * @param listener - The listener function to call when the event occurs
131
- * @returns Unsubscribe function
132
- */
133
- on<E extends LifecycleEvent>(event: E, listener: LifecycleListener<E>): () => void;
134
- /**
135
- * Emit lifecycle event to all listeners
136
- * @internal - Called by StateContainer/Vertex lifecycle methods
137
- */
138
- emit(event: LifecycleEvent, ...args: any[]): void;
139
- }
140
- //#endregion
141
- //#region ../blac/src/core/StateContainer.d.ts
142
- /**
143
- * Configuration options for StateContainer
144
- */
145
- interface StateContainerConfig {
146
- /** Container name for debugging */
147
- name?: string;
148
- /** Enable debug logging */
149
- debug?: boolean;
150
- /** Custom instance identifier */
151
- instanceId?: string;
152
- }
153
- /**
154
- * Listener function for state changes
155
- */
156
- type StateListener<S$1> = (state: S$1) => void;
157
- /**
158
- * Base abstract class for all state containers
159
- */
160
- declare abstract class StateContainer<S$1> {
161
- protected static _registry: StateContainerRegistry;
162
- /**
163
- * Set a custom registry (mainly for testing)
164
- */
165
- static setRegistry(registry: StateContainerRegistry): void;
166
- /**
167
- * Register a type as isolated or shared
168
- */
169
- static register<T extends StateContainer<any>>(this: new (...args: any[]) => T, isolated?: boolean): void;
170
- /**
171
- * Get or create an instance
172
- * @param key - Optional instance key for shared instances
173
- * @param args - Constructor arguments
174
- */
175
- static getOrCreate<T extends StateContainer<any>>(this: new (...args: any[]) => T, key?: string, ...args: any[]): T;
176
- /**
177
- * Release a reference to an instance
178
- * @param key - Optional instance key
179
- * @param forceDispose - Force dispose regardless of ref count or keepAlive
180
- */
181
- static release<T extends StateContainer<any>>(this: new (...args: any[]) => T, key?: string, forceDispose?: boolean): void;
182
- /**
183
- * Get all instances of this type
184
- */
185
- static getAll<T extends StateContainer<any>>(this: new (...args: any[]) => T): T[];
186
- /**
187
- * Clear all instances of this type
188
- */
189
- static clear<T extends StateContainer<any>>(this: new (...args: any[]) => T): void;
190
- /**
191
- * Clear all instances from all types (for testing)
192
- */
193
- static clearAllInstances(): void;
194
- /**
195
- * Get registry statistics (for debugging)
196
- */
197
- static getStats(): {
198
- registeredTypes: number;
199
- totalInstances: number;
200
- typeBreakdown: Record<string, number>;
201
- };
202
- /**
203
- * Get reference count for an instance
204
- * @param key - Optional instance key
205
- */
206
- static getRefCount<T extends StateContainer<any>>(this: new (...args: any[]) => T, key?: string): number;
207
- /**
208
- * Check if an instance exists
209
- * @param key - Optional instance key
210
- */
211
- static hasInstance<T extends StateContainer<any>>(this: new (...args: any[]) => T, key?: string): boolean;
212
- private _state;
213
- private readonly listeners;
214
- private _disposed;
215
- private readonly config;
216
- readonly name: string;
217
- readonly debug: boolean;
218
- readonly instanceId: string;
219
- /**
220
- * Create a new StateContainer
221
- */
222
- constructor(initialState: S$1, config?: StateContainerConfig);
223
- /**
224
- * Get the current state
225
- */
226
- get state(): S$1;
227
- /**
228
- * Check if disposed
229
- */
230
- get isDisposed(): boolean;
231
- /**
232
- * Subscribe to state changes
233
- * @returns Unsubscribe function
234
- */
235
- subscribe(listener: StateListener<S$1>): () => void;
236
- /**
237
- * Dispose the container
238
- */
239
- dispose(): void;
240
- /**
241
- * Emit a new state (with change detection)
242
- */
243
- protected emit(newState: S$1): void;
244
- /**
245
- * Update state using a function
246
- */
247
- protected update(updater: (current: S$1) => S$1): void;
248
- /**
249
- * Optional disposal hook for subclasses
250
- */
251
- protected onDispose?(): void;
252
- /**
253
- * Optional state change hook for subclasses
254
- */
255
- protected onStateChange?(newState: S$1, previousState: S$1): void;
256
- }
257
- //#endregion
258
- //#region ../blac/src/types/branded.d.ts
259
- /**
260
- * Branded types for type-safe IDs
261
- * These types ensure that IDs can't be accidentally mixed up
262
- */
263
- /**
264
- * Helper type for cases where any object type is acceptable
265
- * Used sparingly only where type cannot be more specific
266
- * eslint-disable-next-line @typescript-eslint/no-explicit-any
267
- */
268
- type AnyObject = any;
269
- //#endregion
270
- //#region ../blac/src/types/utilities.d.ts
271
- /**
272
- * Extract state type from StateContainer
273
- *
274
- * @example
275
- * ```ts
276
- * class CounterBloc extends Cubit<number> { ... }
277
- * type State = ExtractState<CounterBloc>; // number
278
- * ```
279
- */
280
- type ExtractState<T$1> = T$1 extends StateContainer<infer S> ? S : never;
281
- /**
282
- * Bloc constructor type - represents a class constructor for StateContainer subclasses
283
- * Includes static methods from StateContainer for instance management
284
- *
285
- * Note: Uses `any` for state type to support variance - the actual Bloc instance
286
- * will have the correct specific types inferred at usage sites.
287
- *
288
- * @example
289
- * ```ts
290
- * function createBloc<TBloc extends StateContainer<any>>(
291
- * BlocClass: BlocConstructor<TBloc>
292
- * ): TBloc {
293
- * return BlocClass.getOrCreate();
294
- * }
295
- * ```
296
- */
297
- type BlocConstructor<TBloc extends StateContainer<any>> = (new (...args: any[]) => TBloc) & {
298
- getOrCreate?(instanceKey?: string, ...args: any[]): TBloc;
299
- release?(instanceKey?: string): void;
300
- isolated?: boolean;
301
- keepAlive?: boolean;
302
- };
303
- //#endregion
304
4
  //#region src/types.d.ts
5
+
305
6
  /**
306
7
  * Configuration options for the useBloc hook
307
8
  *
package/dist/index.d.ts CHANGED
@@ -1,307 +1,8 @@
1
1
  import { RefObject } from "react";
2
+ import { AnyObject, BlocConstructor, ExtractState, StateContainer } from "@blac/core";
2
3
 
3
- //#region ../blac/src/types/events.d.ts
4
-
5
- /**
6
- * Base event interface for type-safe event system
7
- */
8
- /**
9
- * Base event interface
10
- * Used by Vertex for event-driven state management
11
- */
12
- interface BaseEvent {
13
- readonly type: string;
14
- readonly timestamp: number;
15
- readonly source?: string;
16
- }
17
- //#endregion
18
- //#region ../blac/src/core/Vertex.d.ts
19
-
20
- /**
21
- * Event handler signature (synchronous only)
22
- */
23
- type EventHandler<E$1 extends BaseEvent, S$1> = (event: E$1, emit: (state: S$1) => void) => void;
24
- /**
25
- * Type-safe event constructor
26
- */
27
- type EventConstructor<T$1 extends BaseEvent = BaseEvent> = new (...args: never[]) => T$1;
28
- /**
29
- * Vertex is an event-driven state container (Bloc pattern)
30
- *
31
- * Includes its own simple event system since events are only needed
32
- * for the Vertex pattern, not for the base StateContainer.
33
- */
34
- declare abstract class Vertex<S$1, E$1 extends BaseEvent = BaseEvent> extends StateContainer<S$1> {
35
- private eventHandlers;
36
- private isProcessing;
37
- private eventQueue;
38
- /**
39
- * Create a new Vertex
40
- * @param initialState Initial state value
41
- * @param config Configuration options
42
- */
43
- constructor(initialState: S$1, config?: StateContainerConfig);
44
- /**
45
- * Register an event handler
46
- * Arrow function to maintain correct 'this' binding
47
- */
48
- protected on: <T extends E$1>(EventClass: EventConstructor<T>, handler: EventHandler<T, S$1>) => void;
49
- /**
50
- * Add an event to be processed
51
- * Arrow function to maintain correct 'this' binding in React
52
- */
53
- add: (event: E$1) => void;
54
- /**
55
- * Process an event (synchronously)
56
- */
57
- private processEvent;
58
- /**
59
- * Handle a single event (synchronously)
60
- */
61
- private handleEvent;
62
- /**
63
- * Hook for handling event processing errors
64
- */
65
- protected onEventError(event: E$1, error: Error): void;
66
- }
67
- //#endregion
68
- //#region ../blac/src/core/StateContainerRegistry.d.ts
69
- /**
70
- * Lifecycle events that can be observed
71
- */
72
- type LifecycleEvent = 'created' | 'stateChanged' | 'eventAdded' | 'disposed';
73
- /**
74
- * Listener function types for each lifecycle event
75
- */
76
- type LifecycleListener<E$1 extends LifecycleEvent> = E$1 extends 'created' ? (container: StateContainer<any>) => void : E$1 extends 'stateChanged' ? (container: StateContainer<any>, previousState: any, currentState: any) => void : E$1 extends 'eventAdded' ? (container: Vertex<any, any>, event: any) => void : E$1 extends 'disposed' ? (container: StateContainer<any>) => void : never;
77
- /**
78
- * Registry for managing StateContainer instances
79
- */
80
- declare class StateContainerRegistry {
81
- private readonly instances;
82
- private readonly types;
83
- private readonly listeners;
84
- /**
85
- * Register a type with isolation mode
86
- */
87
- register<T extends StateContainer<any>>(constructor: new (...args: any[]) => T, isolated?: boolean): void;
88
- /**
89
- * Get or create a StateContainer instance
90
- * For isolated: always creates new
91
- * For shared: singleton per key
92
- */
93
- getOrCreate<T extends StateContainer<any>>(constructor: new (...args: any[]) => T, key?: string, ...args: any[]): T;
94
- /**
95
- * Release a reference to an instance
96
- * Disposes when ref count reaches zero (unless static keepAlive is true)
97
- */
98
- release<T extends StateContainer<any>>(constructor: new (...args: any[]) => T, key?: string, forceDispose?: boolean): void;
99
- /**
100
- * Get all instances of a type (shared only, isolated aren't tracked)
101
- */
102
- getAll<T extends StateContainer<any>>(constructor: new (...args: any[]) => T): T[];
103
- /**
104
- * Clear all instances of a type
105
- */
106
- clear<T extends StateContainer<any>>(constructor: new (...args: any[]) => T): void;
107
- /**
108
- * Clear all instances from all types (for testing)
109
- */
110
- clearAll(): void;
111
- /**
112
- * Get registry statistics (for debugging)
113
- */
114
- getStats(): {
115
- registeredTypes: number;
116
- totalInstances: number;
117
- typeBreakdown: Record<string, number>;
118
- };
119
- /**
120
- * Get reference count for an instance
121
- */
122
- getRefCount<T extends StateContainer<any>>(constructor: new (...args: any[]) => T, key?: string): number;
123
- /**
124
- * Check if an instance exists
125
- */
126
- hasInstance<T extends StateContainer<any>>(constructor: new (...args: any[]) => T, key?: string): boolean;
127
- /**
128
- * Subscribe to lifecycle events
129
- * @param event - The lifecycle event to listen for
130
- * @param listener - The listener function to call when the event occurs
131
- * @returns Unsubscribe function
132
- */
133
- on<E extends LifecycleEvent>(event: E, listener: LifecycleListener<E>): () => void;
134
- /**
135
- * Emit lifecycle event to all listeners
136
- * @internal - Called by StateContainer/Vertex lifecycle methods
137
- */
138
- emit(event: LifecycleEvent, ...args: any[]): void;
139
- }
140
- //#endregion
141
- //#region ../blac/src/core/StateContainer.d.ts
142
- /**
143
- * Configuration options for StateContainer
144
- */
145
- interface StateContainerConfig {
146
- /** Container name for debugging */
147
- name?: string;
148
- /** Enable debug logging */
149
- debug?: boolean;
150
- /** Custom instance identifier */
151
- instanceId?: string;
152
- }
153
- /**
154
- * Listener function for state changes
155
- */
156
- type StateListener<S$1> = (state: S$1) => void;
157
- /**
158
- * Base abstract class for all state containers
159
- */
160
- declare abstract class StateContainer<S$1> {
161
- protected static _registry: StateContainerRegistry;
162
- /**
163
- * Set a custom registry (mainly for testing)
164
- */
165
- static setRegistry(registry: StateContainerRegistry): void;
166
- /**
167
- * Register a type as isolated or shared
168
- */
169
- static register<T extends StateContainer<any>>(this: new (...args: any[]) => T, isolated?: boolean): void;
170
- /**
171
- * Get or create an instance
172
- * @param key - Optional instance key for shared instances
173
- * @param args - Constructor arguments
174
- */
175
- static getOrCreate<T extends StateContainer<any>>(this: new (...args: any[]) => T, key?: string, ...args: any[]): T;
176
- /**
177
- * Release a reference to an instance
178
- * @param key - Optional instance key
179
- * @param forceDispose - Force dispose regardless of ref count or keepAlive
180
- */
181
- static release<T extends StateContainer<any>>(this: new (...args: any[]) => T, key?: string, forceDispose?: boolean): void;
182
- /**
183
- * Get all instances of this type
184
- */
185
- static getAll<T extends StateContainer<any>>(this: new (...args: any[]) => T): T[];
186
- /**
187
- * Clear all instances of this type
188
- */
189
- static clear<T extends StateContainer<any>>(this: new (...args: any[]) => T): void;
190
- /**
191
- * Clear all instances from all types (for testing)
192
- */
193
- static clearAllInstances(): void;
194
- /**
195
- * Get registry statistics (for debugging)
196
- */
197
- static getStats(): {
198
- registeredTypes: number;
199
- totalInstances: number;
200
- typeBreakdown: Record<string, number>;
201
- };
202
- /**
203
- * Get reference count for an instance
204
- * @param key - Optional instance key
205
- */
206
- static getRefCount<T extends StateContainer<any>>(this: new (...args: any[]) => T, key?: string): number;
207
- /**
208
- * Check if an instance exists
209
- * @param key - Optional instance key
210
- */
211
- static hasInstance<T extends StateContainer<any>>(this: new (...args: any[]) => T, key?: string): boolean;
212
- private _state;
213
- private readonly listeners;
214
- private _disposed;
215
- private readonly config;
216
- readonly name: string;
217
- readonly debug: boolean;
218
- readonly instanceId: string;
219
- /**
220
- * Create a new StateContainer
221
- */
222
- constructor(initialState: S$1, config?: StateContainerConfig);
223
- /**
224
- * Get the current state
225
- */
226
- get state(): S$1;
227
- /**
228
- * Check if disposed
229
- */
230
- get isDisposed(): boolean;
231
- /**
232
- * Subscribe to state changes
233
- * @returns Unsubscribe function
234
- */
235
- subscribe(listener: StateListener<S$1>): () => void;
236
- /**
237
- * Dispose the container
238
- */
239
- dispose(): void;
240
- /**
241
- * Emit a new state (with change detection)
242
- */
243
- protected emit(newState: S$1): void;
244
- /**
245
- * Update state using a function
246
- */
247
- protected update(updater: (current: S$1) => S$1): void;
248
- /**
249
- * Optional disposal hook for subclasses
250
- */
251
- protected onDispose?(): void;
252
- /**
253
- * Optional state change hook for subclasses
254
- */
255
- protected onStateChange?(newState: S$1, previousState: S$1): void;
256
- }
257
- //#endregion
258
- //#region ../blac/src/types/branded.d.ts
259
- /**
260
- * Branded types for type-safe IDs
261
- * These types ensure that IDs can't be accidentally mixed up
262
- */
263
- /**
264
- * Helper type for cases where any object type is acceptable
265
- * Used sparingly only where type cannot be more specific
266
- * eslint-disable-next-line @typescript-eslint/no-explicit-any
267
- */
268
- type AnyObject = any;
269
- //#endregion
270
- //#region ../blac/src/types/utilities.d.ts
271
- /**
272
- * Extract state type from StateContainer
273
- *
274
- * @example
275
- * ```ts
276
- * class CounterBloc extends Cubit<number> { ... }
277
- * type State = ExtractState<CounterBloc>; // number
278
- * ```
279
- */
280
- type ExtractState<T$1> = T$1 extends StateContainer<infer S> ? S : never;
281
- /**
282
- * Bloc constructor type - represents a class constructor for StateContainer subclasses
283
- * Includes static methods from StateContainer for instance management
284
- *
285
- * Note: Uses `any` for state type to support variance - the actual Bloc instance
286
- * will have the correct specific types inferred at usage sites.
287
- *
288
- * @example
289
- * ```ts
290
- * function createBloc<TBloc extends StateContainer<any>>(
291
- * BlocClass: BlocConstructor<TBloc>
292
- * ): TBloc {
293
- * return BlocClass.getOrCreate();
294
- * }
295
- * ```
296
- */
297
- type BlocConstructor<TBloc extends StateContainer<any>> = (new (...args: any[]) => TBloc) & {
298
- getOrCreate?(instanceKey?: string, ...args: any[]): TBloc;
299
- release?(instanceKey?: string): void;
300
- isolated?: boolean;
301
- keepAlive?: boolean;
302
- };
303
- //#endregion
304
4
  //#region src/types.d.ts
5
+
305
6
  /**
306
7
  * Configuration options for the useBloc hook
307
8
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blac/react",
3
- "version": "2.0.0-rc.5",
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.5"
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.5"
68
+ "@blac/core": "2.0.0-rc.6"
69
69
  },
70
70
  "scripts": {
71
71
  "dev": "tsdown --watch",