@blac/core 2.0.0-rc.3 → 2.0.0-rc.5
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 +36 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +147 -130
- package/dist/index.d.ts +147 -130
- package/dist/index.js +36 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,11 +1,141 @@
|
|
|
1
|
-
//#region src/
|
|
1
|
+
//#region src/types/events.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Base event interface for type-safe event system
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Base event interface
|
|
7
|
+
* Used by Vertex for event-driven state management
|
|
8
|
+
*/
|
|
9
|
+
interface BaseEvent {
|
|
10
|
+
readonly type: string;
|
|
11
|
+
readonly timestamp: number;
|
|
12
|
+
readonly source?: string;
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/core/Vertex.d.ts
|
|
2
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Event handler signature (synchronous only)
|
|
19
|
+
*/
|
|
20
|
+
type EventHandler<E$1 extends BaseEvent, S$1> = (event: E$1, emit: (state: S$1) => void) => void;
|
|
21
|
+
/**
|
|
22
|
+
* Type-safe event constructor
|
|
23
|
+
*/
|
|
24
|
+
type EventConstructor<T$1 extends BaseEvent = BaseEvent> = new (...args: never[]) => T$1;
|
|
25
|
+
/**
|
|
26
|
+
* Vertex is an event-driven state container (Bloc pattern)
|
|
27
|
+
*
|
|
28
|
+
* Includes its own simple event system since events are only needed
|
|
29
|
+
* for the Vertex pattern, not for the base StateContainer.
|
|
30
|
+
*/
|
|
31
|
+
declare abstract class Vertex<S$1, E$1 extends BaseEvent = BaseEvent> extends StateContainer<S$1> {
|
|
32
|
+
private eventHandlers;
|
|
33
|
+
private isProcessing;
|
|
34
|
+
private eventQueue;
|
|
35
|
+
/**
|
|
36
|
+
* Create a new Vertex
|
|
37
|
+
* @param initialState Initial state value
|
|
38
|
+
* @param config Configuration options
|
|
39
|
+
*/
|
|
40
|
+
constructor(initialState: S$1, config?: StateContainerConfig);
|
|
41
|
+
/**
|
|
42
|
+
* Register an event handler
|
|
43
|
+
* Arrow function to maintain correct 'this' binding
|
|
44
|
+
*/
|
|
45
|
+
protected on: <T extends E$1>(EventClass: EventConstructor<T>, handler: EventHandler<T, S$1>) => void;
|
|
46
|
+
/**
|
|
47
|
+
* Add an event to be processed
|
|
48
|
+
* Arrow function to maintain correct 'this' binding in React
|
|
49
|
+
*/
|
|
50
|
+
add: (event: E$1) => void;
|
|
51
|
+
/**
|
|
52
|
+
* Process an event (synchronously)
|
|
53
|
+
*/
|
|
54
|
+
private processEvent;
|
|
55
|
+
/**
|
|
56
|
+
* Handle a single event (synchronously)
|
|
57
|
+
*/
|
|
58
|
+
private handleEvent;
|
|
59
|
+
/**
|
|
60
|
+
* Hook for handling event processing errors
|
|
61
|
+
*/
|
|
62
|
+
protected onEventError(event: E$1, error: Error): void;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Example: Counter Events
|
|
66
|
+
*/
|
|
67
|
+
declare class IncrementEvent implements BaseEvent {
|
|
68
|
+
readonly amount: number;
|
|
69
|
+
readonly type = "increment";
|
|
70
|
+
readonly timestamp: number;
|
|
71
|
+
constructor(amount?: number);
|
|
72
|
+
}
|
|
73
|
+
declare class DecrementEvent implements BaseEvent {
|
|
74
|
+
readonly amount: number;
|
|
75
|
+
readonly type = "decrement";
|
|
76
|
+
readonly timestamp: number;
|
|
77
|
+
constructor(amount?: number);
|
|
78
|
+
}
|
|
79
|
+
declare class ResetEvent implements BaseEvent {
|
|
80
|
+
readonly type = "reset";
|
|
81
|
+
readonly timestamp: number;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Example: Counter Vertex
|
|
85
|
+
* Demonstrates proper typing and event handling
|
|
86
|
+
*/
|
|
87
|
+
declare class CounterVertex extends Vertex<number> {
|
|
88
|
+
constructor();
|
|
89
|
+
increment: (amount?: number) => void;
|
|
90
|
+
decrement: (amount?: number) => void;
|
|
91
|
+
reset: () => void;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Auth State and Events for testing async handlers
|
|
95
|
+
*/
|
|
96
|
+
interface AuthState {
|
|
97
|
+
isAuthenticated: boolean;
|
|
98
|
+
isLoading: boolean;
|
|
99
|
+
user: {
|
|
100
|
+
id: string;
|
|
101
|
+
name: string;
|
|
102
|
+
email: string;
|
|
103
|
+
} | null;
|
|
104
|
+
error: string | null;
|
|
105
|
+
}
|
|
106
|
+
declare class LoginEvent implements BaseEvent {
|
|
107
|
+
readonly email: string;
|
|
108
|
+
readonly password: string;
|
|
109
|
+
readonly type = "login";
|
|
110
|
+
readonly timestamp: number;
|
|
111
|
+
constructor(email: string, password: string);
|
|
112
|
+
}
|
|
113
|
+
declare class LogoutEvent implements BaseEvent {
|
|
114
|
+
readonly type = "logout";
|
|
115
|
+
readonly timestamp: number;
|
|
116
|
+
}
|
|
117
|
+
declare class AuthVertex extends Vertex<AuthState> {
|
|
118
|
+
constructor();
|
|
119
|
+
login: (email: string, password: string) => void;
|
|
120
|
+
logout: () => void;
|
|
121
|
+
}
|
|
122
|
+
//#endregion
|
|
123
|
+
//#region src/core/StateContainerRegistry.d.ts
|
|
124
|
+
/**
|
|
125
|
+
* Lifecycle events that can be observed
|
|
126
|
+
*/
|
|
127
|
+
type LifecycleEvent = 'created' | 'stateChanged' | 'eventAdded' | 'disposed';
|
|
128
|
+
/**
|
|
129
|
+
* Listener function types for each lifecycle event
|
|
130
|
+
*/
|
|
131
|
+
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;
|
|
3
132
|
/**
|
|
4
133
|
* Registry for managing StateContainer instances
|
|
5
134
|
*/
|
|
6
135
|
declare class StateContainerRegistry {
|
|
7
136
|
private readonly instances;
|
|
8
137
|
private readonly types;
|
|
138
|
+
private readonly listeners;
|
|
9
139
|
/**
|
|
10
140
|
* Register a type with isolation mode
|
|
11
141
|
*/
|
|
@@ -18,7 +148,7 @@ declare class StateContainerRegistry {
|
|
|
18
148
|
getOrCreate<T extends StateContainer<any>>(constructor: new (...args: any[]) => T, key?: string, ...args: any[]): T;
|
|
19
149
|
/**
|
|
20
150
|
* Release a reference to an instance
|
|
21
|
-
* Disposes when ref count reaches zero (unless keepAlive)
|
|
151
|
+
* Disposes when ref count reaches zero (unless static keepAlive is true)
|
|
22
152
|
*/
|
|
23
153
|
release<T extends StateContainer<any>>(constructor: new (...args: any[]) => T, key?: string, forceDispose?: boolean): void;
|
|
24
154
|
/**
|
|
@@ -49,6 +179,18 @@ declare class StateContainerRegistry {
|
|
|
49
179
|
* Check if an instance exists
|
|
50
180
|
*/
|
|
51
181
|
hasInstance<T extends StateContainer<any>>(constructor: new (...args: any[]) => T, key?: string): boolean;
|
|
182
|
+
/**
|
|
183
|
+
* Subscribe to lifecycle events
|
|
184
|
+
* @param event - The lifecycle event to listen for
|
|
185
|
+
* @param listener - The listener function to call when the event occurs
|
|
186
|
+
* @returns Unsubscribe function
|
|
187
|
+
*/
|
|
188
|
+
on<E extends LifecycleEvent>(event: E, listener: LifecycleListener<E>): () => void;
|
|
189
|
+
/**
|
|
190
|
+
* Emit lifecycle event to all listeners
|
|
191
|
+
* @internal - Called by StateContainer/Vertex lifecycle methods
|
|
192
|
+
*/
|
|
193
|
+
emit(event: LifecycleEvent, ...args: any[]): void;
|
|
52
194
|
}
|
|
53
195
|
/**
|
|
54
196
|
* Global default registry instance
|
|
@@ -62,14 +204,10 @@ declare const globalRegistry: StateContainerRegistry;
|
|
|
62
204
|
interface StateContainerConfig {
|
|
63
205
|
/** Container name for debugging */
|
|
64
206
|
name?: string;
|
|
65
|
-
/** Whether to keep container alive when no consumers */
|
|
66
|
-
keepAlive?: boolean;
|
|
67
207
|
/** Enable debug logging */
|
|
68
208
|
debug?: boolean;
|
|
69
209
|
/** Custom instance identifier */
|
|
70
210
|
instanceId?: string;
|
|
71
|
-
/** Whether this instance should be isolated (not shared) */
|
|
72
|
-
isolated?: boolean;
|
|
73
211
|
}
|
|
74
212
|
/**
|
|
75
213
|
* Listener function for state changes
|
|
@@ -79,7 +217,7 @@ type StateListener<S$1> = (state: S$1) => void;
|
|
|
79
217
|
* Base abstract class for all state containers
|
|
80
218
|
*/
|
|
81
219
|
declare abstract class StateContainer<S$1> {
|
|
82
|
-
|
|
220
|
+
protected static _registry: StateContainerRegistry;
|
|
83
221
|
/**
|
|
84
222
|
* Set a custom registry (mainly for testing)
|
|
85
223
|
*/
|
|
@@ -135,7 +273,6 @@ declare abstract class StateContainer<S$1> {
|
|
|
135
273
|
private _disposed;
|
|
136
274
|
private readonly config;
|
|
137
275
|
readonly name: string;
|
|
138
|
-
readonly keepAlive: boolean;
|
|
139
276
|
readonly debug: boolean;
|
|
140
277
|
readonly instanceId: string;
|
|
141
278
|
/**
|
|
@@ -238,6 +375,7 @@ interface TodoState {
|
|
|
238
375
|
isLoading: boolean;
|
|
239
376
|
}
|
|
240
377
|
declare class TodoCubit extends Cubit<TodoState> {
|
|
378
|
+
static keepAlive: boolean;
|
|
241
379
|
private nextId;
|
|
242
380
|
constructor();
|
|
243
381
|
addTodo: (text: string) => void;
|
|
@@ -253,127 +391,6 @@ declare class TodoCubit extends Cubit<TodoState> {
|
|
|
253
391
|
get activeTodoCount(): number;
|
|
254
392
|
}
|
|
255
393
|
//#endregion
|
|
256
|
-
//#region src/types/events.d.ts
|
|
257
|
-
/**
|
|
258
|
-
* Base event interface for type-safe event system
|
|
259
|
-
*/
|
|
260
|
-
/**
|
|
261
|
-
* Base event interface
|
|
262
|
-
* Used by Vertex for event-driven state management
|
|
263
|
-
*/
|
|
264
|
-
interface BaseEvent {
|
|
265
|
-
readonly type: string;
|
|
266
|
-
readonly timestamp: number;
|
|
267
|
-
readonly source?: string;
|
|
268
|
-
}
|
|
269
|
-
//#endregion
|
|
270
|
-
//#region src/core/Vertex.d.ts
|
|
271
|
-
/**
|
|
272
|
-
* Event handler signature (synchronous only)
|
|
273
|
-
*/
|
|
274
|
-
type EventHandler<E extends BaseEvent, S$1> = (event: E, emit: (state: S$1) => void) => void;
|
|
275
|
-
/**
|
|
276
|
-
* Type-safe event constructor
|
|
277
|
-
*/
|
|
278
|
-
type EventConstructor<T$1 extends BaseEvent = BaseEvent> = new (...args: never[]) => T$1;
|
|
279
|
-
/**
|
|
280
|
-
* Vertex is an event-driven state container (Bloc pattern)
|
|
281
|
-
*
|
|
282
|
-
* Includes its own simple event system since events are only needed
|
|
283
|
-
* for the Vertex pattern, not for the base StateContainer.
|
|
284
|
-
*/
|
|
285
|
-
declare abstract class Vertex<S$1, E extends BaseEvent = BaseEvent> extends StateContainer<S$1> {
|
|
286
|
-
private eventHandlers;
|
|
287
|
-
private isProcessing;
|
|
288
|
-
private eventQueue;
|
|
289
|
-
/**
|
|
290
|
-
* Create a new Vertex
|
|
291
|
-
* @param initialState Initial state value
|
|
292
|
-
* @param config Configuration options
|
|
293
|
-
*/
|
|
294
|
-
constructor(initialState: S$1, config?: StateContainerConfig);
|
|
295
|
-
/**
|
|
296
|
-
* Register an event handler
|
|
297
|
-
* Arrow function to maintain correct 'this' binding
|
|
298
|
-
*/
|
|
299
|
-
protected on: <T extends E>(EventClass: EventConstructor<T>, handler: EventHandler<T, S$1>) => void;
|
|
300
|
-
/**
|
|
301
|
-
* Add an event to be processed
|
|
302
|
-
* Arrow function to maintain correct 'this' binding in React
|
|
303
|
-
*/
|
|
304
|
-
add: (event: E) => void;
|
|
305
|
-
/**
|
|
306
|
-
* Process an event (synchronously)
|
|
307
|
-
*/
|
|
308
|
-
private processEvent;
|
|
309
|
-
/**
|
|
310
|
-
* Handle a single event (synchronously)
|
|
311
|
-
*/
|
|
312
|
-
private handleEvent;
|
|
313
|
-
/**
|
|
314
|
-
* Hook for handling event processing errors
|
|
315
|
-
*/
|
|
316
|
-
protected onEventError(event: E, error: Error): void;
|
|
317
|
-
}
|
|
318
|
-
/**
|
|
319
|
-
* Example: Counter Events
|
|
320
|
-
*/
|
|
321
|
-
declare class IncrementEvent implements BaseEvent {
|
|
322
|
-
readonly amount: number;
|
|
323
|
-
readonly type = "increment";
|
|
324
|
-
readonly timestamp: number;
|
|
325
|
-
constructor(amount?: number);
|
|
326
|
-
}
|
|
327
|
-
declare class DecrementEvent implements BaseEvent {
|
|
328
|
-
readonly amount: number;
|
|
329
|
-
readonly type = "decrement";
|
|
330
|
-
readonly timestamp: number;
|
|
331
|
-
constructor(amount?: number);
|
|
332
|
-
}
|
|
333
|
-
declare class ResetEvent implements BaseEvent {
|
|
334
|
-
readonly type = "reset";
|
|
335
|
-
readonly timestamp: number;
|
|
336
|
-
}
|
|
337
|
-
/**
|
|
338
|
-
* Example: Counter Vertex
|
|
339
|
-
* Demonstrates proper typing and event handling
|
|
340
|
-
*/
|
|
341
|
-
declare class CounterVertex extends Vertex<number> {
|
|
342
|
-
constructor();
|
|
343
|
-
increment: (amount?: number) => void;
|
|
344
|
-
decrement: (amount?: number) => void;
|
|
345
|
-
reset: () => void;
|
|
346
|
-
}
|
|
347
|
-
/**
|
|
348
|
-
* Auth State and Events for testing async handlers
|
|
349
|
-
*/
|
|
350
|
-
interface AuthState {
|
|
351
|
-
isAuthenticated: boolean;
|
|
352
|
-
isLoading: boolean;
|
|
353
|
-
user: {
|
|
354
|
-
id: string;
|
|
355
|
-
name: string;
|
|
356
|
-
email: string;
|
|
357
|
-
} | null;
|
|
358
|
-
error: string | null;
|
|
359
|
-
}
|
|
360
|
-
declare class LoginEvent implements BaseEvent {
|
|
361
|
-
readonly email: string;
|
|
362
|
-
readonly password: string;
|
|
363
|
-
readonly type = "login";
|
|
364
|
-
readonly timestamp: number;
|
|
365
|
-
constructor(email: string, password: string);
|
|
366
|
-
}
|
|
367
|
-
declare class LogoutEvent implements BaseEvent {
|
|
368
|
-
readonly type = "logout";
|
|
369
|
-
readonly timestamp: number;
|
|
370
|
-
}
|
|
371
|
-
declare class AuthVertex extends Vertex<AuthState> {
|
|
372
|
-
constructor();
|
|
373
|
-
login: (email: string, password: string) => void;
|
|
374
|
-
logout: () => void;
|
|
375
|
-
}
|
|
376
|
-
//#endregion
|
|
377
394
|
//#region src/types/branded.d.ts
|
|
378
395
|
/**
|
|
379
396
|
* Branded types for type-safe IDs
|
|
@@ -864,5 +881,5 @@ declare function generateSimpleId(prefix: string): string;
|
|
|
864
881
|
*/
|
|
865
882
|
declare function __resetIdCounters(): void;
|
|
866
883
|
//#endregion
|
|
867
|
-
export { type AnyObject, AuthState, AuthVertex, BLAC_DEFAULTS, type BaseEvent, BlocConstructor, type Brand, type BrandedId, CounterCubit, CounterVertex, Cubit, DecrementEvent, EventConstructor, EventHandler, ExtractConstructorArgs, ExtractState, IncrementEvent, type InstanceId, type LogConfig, type LogEntry, LogLevel, LoginEvent, LogoutEvent, PathInfo, ProxyTracker, ProxyTrackerState, ResetEvent, StateContainer, StateContainerConfig, StateContainerRegistry, TodoCubit, TodoState, TrackerState, Vertex, __resetIdCounters, captureTrackedPaths, configureLogger, createArrayProxy, createIdGenerator, createLogger, createProxy, createProxyForTarget, createProxyInternal, createProxyTrackerState, createTrackerState, debug, error, generateId, generateSimpleId, getValueAtPath, globalProxyTracker, globalRegistry, hasChanges, hasTrackedData, info, isProxyable, parsePath, shallowEqual, startProxyTracking, startTracking, stopProxyTracking, trackAccess, warn };
|
|
884
|
+
export { type AnyObject, AuthState, AuthVertex, BLAC_DEFAULTS, type BaseEvent, BlocConstructor, type Brand, type BrandedId, CounterCubit, CounterVertex, Cubit, DecrementEvent, EventConstructor, EventHandler, ExtractConstructorArgs, ExtractState, IncrementEvent, type InstanceId, type LifecycleEvent, type LifecycleListener, type LogConfig, type LogEntry, LogLevel, LoginEvent, LogoutEvent, PathInfo, ProxyTracker, ProxyTrackerState, ResetEvent, StateContainer, StateContainerConfig, StateContainerRegistry, TodoCubit, TodoState, TrackerState, Vertex, __resetIdCounters, captureTrackedPaths, configureLogger, createArrayProxy, createIdGenerator, createLogger, createProxy, createProxyForTarget, createProxyInternal, createProxyTrackerState, createTrackerState, debug, error, generateId, generateSimpleId, getValueAtPath, globalProxyTracker, globalRegistry, hasChanges, hasTrackedData, info, isProxyable, parsePath, shallowEqual, startProxyTracking, startTracking, stopProxyTracking, trackAccess, warn };
|
|
868
885
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,141 @@
|
|
|
1
|
-
//#region src/
|
|
1
|
+
//#region src/types/events.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Base event interface for type-safe event system
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Base event interface
|
|
7
|
+
* Used by Vertex for event-driven state management
|
|
8
|
+
*/
|
|
9
|
+
interface BaseEvent {
|
|
10
|
+
readonly type: string;
|
|
11
|
+
readonly timestamp: number;
|
|
12
|
+
readonly source?: string;
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/core/Vertex.d.ts
|
|
2
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Event handler signature (synchronous only)
|
|
19
|
+
*/
|
|
20
|
+
type EventHandler<E$1 extends BaseEvent, S$1> = (event: E$1, emit: (state: S$1) => void) => void;
|
|
21
|
+
/**
|
|
22
|
+
* Type-safe event constructor
|
|
23
|
+
*/
|
|
24
|
+
type EventConstructor<T$1 extends BaseEvent = BaseEvent> = new (...args: never[]) => T$1;
|
|
25
|
+
/**
|
|
26
|
+
* Vertex is an event-driven state container (Bloc pattern)
|
|
27
|
+
*
|
|
28
|
+
* Includes its own simple event system since events are only needed
|
|
29
|
+
* for the Vertex pattern, not for the base StateContainer.
|
|
30
|
+
*/
|
|
31
|
+
declare abstract class Vertex<S$1, E$1 extends BaseEvent = BaseEvent> extends StateContainer<S$1> {
|
|
32
|
+
private eventHandlers;
|
|
33
|
+
private isProcessing;
|
|
34
|
+
private eventQueue;
|
|
35
|
+
/**
|
|
36
|
+
* Create a new Vertex
|
|
37
|
+
* @param initialState Initial state value
|
|
38
|
+
* @param config Configuration options
|
|
39
|
+
*/
|
|
40
|
+
constructor(initialState: S$1, config?: StateContainerConfig);
|
|
41
|
+
/**
|
|
42
|
+
* Register an event handler
|
|
43
|
+
* Arrow function to maintain correct 'this' binding
|
|
44
|
+
*/
|
|
45
|
+
protected on: <T extends E$1>(EventClass: EventConstructor<T>, handler: EventHandler<T, S$1>) => void;
|
|
46
|
+
/**
|
|
47
|
+
* Add an event to be processed
|
|
48
|
+
* Arrow function to maintain correct 'this' binding in React
|
|
49
|
+
*/
|
|
50
|
+
add: (event: E$1) => void;
|
|
51
|
+
/**
|
|
52
|
+
* Process an event (synchronously)
|
|
53
|
+
*/
|
|
54
|
+
private processEvent;
|
|
55
|
+
/**
|
|
56
|
+
* Handle a single event (synchronously)
|
|
57
|
+
*/
|
|
58
|
+
private handleEvent;
|
|
59
|
+
/**
|
|
60
|
+
* Hook for handling event processing errors
|
|
61
|
+
*/
|
|
62
|
+
protected onEventError(event: E$1, error: Error): void;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Example: Counter Events
|
|
66
|
+
*/
|
|
67
|
+
declare class IncrementEvent implements BaseEvent {
|
|
68
|
+
readonly amount: number;
|
|
69
|
+
readonly type = "increment";
|
|
70
|
+
readonly timestamp: number;
|
|
71
|
+
constructor(amount?: number);
|
|
72
|
+
}
|
|
73
|
+
declare class DecrementEvent implements BaseEvent {
|
|
74
|
+
readonly amount: number;
|
|
75
|
+
readonly type = "decrement";
|
|
76
|
+
readonly timestamp: number;
|
|
77
|
+
constructor(amount?: number);
|
|
78
|
+
}
|
|
79
|
+
declare class ResetEvent implements BaseEvent {
|
|
80
|
+
readonly type = "reset";
|
|
81
|
+
readonly timestamp: number;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Example: Counter Vertex
|
|
85
|
+
* Demonstrates proper typing and event handling
|
|
86
|
+
*/
|
|
87
|
+
declare class CounterVertex extends Vertex<number> {
|
|
88
|
+
constructor();
|
|
89
|
+
increment: (amount?: number) => void;
|
|
90
|
+
decrement: (amount?: number) => void;
|
|
91
|
+
reset: () => void;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Auth State and Events for testing async handlers
|
|
95
|
+
*/
|
|
96
|
+
interface AuthState {
|
|
97
|
+
isAuthenticated: boolean;
|
|
98
|
+
isLoading: boolean;
|
|
99
|
+
user: {
|
|
100
|
+
id: string;
|
|
101
|
+
name: string;
|
|
102
|
+
email: string;
|
|
103
|
+
} | null;
|
|
104
|
+
error: string | null;
|
|
105
|
+
}
|
|
106
|
+
declare class LoginEvent implements BaseEvent {
|
|
107
|
+
readonly email: string;
|
|
108
|
+
readonly password: string;
|
|
109
|
+
readonly type = "login";
|
|
110
|
+
readonly timestamp: number;
|
|
111
|
+
constructor(email: string, password: string);
|
|
112
|
+
}
|
|
113
|
+
declare class LogoutEvent implements BaseEvent {
|
|
114
|
+
readonly type = "logout";
|
|
115
|
+
readonly timestamp: number;
|
|
116
|
+
}
|
|
117
|
+
declare class AuthVertex extends Vertex<AuthState> {
|
|
118
|
+
constructor();
|
|
119
|
+
login: (email: string, password: string) => void;
|
|
120
|
+
logout: () => void;
|
|
121
|
+
}
|
|
122
|
+
//#endregion
|
|
123
|
+
//#region src/core/StateContainerRegistry.d.ts
|
|
124
|
+
/**
|
|
125
|
+
* Lifecycle events that can be observed
|
|
126
|
+
*/
|
|
127
|
+
type LifecycleEvent = 'created' | 'stateChanged' | 'eventAdded' | 'disposed';
|
|
128
|
+
/**
|
|
129
|
+
* Listener function types for each lifecycle event
|
|
130
|
+
*/
|
|
131
|
+
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;
|
|
3
132
|
/**
|
|
4
133
|
* Registry for managing StateContainer instances
|
|
5
134
|
*/
|
|
6
135
|
declare class StateContainerRegistry {
|
|
7
136
|
private readonly instances;
|
|
8
137
|
private readonly types;
|
|
138
|
+
private readonly listeners;
|
|
9
139
|
/**
|
|
10
140
|
* Register a type with isolation mode
|
|
11
141
|
*/
|
|
@@ -18,7 +148,7 @@ declare class StateContainerRegistry {
|
|
|
18
148
|
getOrCreate<T extends StateContainer<any>>(constructor: new (...args: any[]) => T, key?: string, ...args: any[]): T;
|
|
19
149
|
/**
|
|
20
150
|
* Release a reference to an instance
|
|
21
|
-
* Disposes when ref count reaches zero (unless keepAlive)
|
|
151
|
+
* Disposes when ref count reaches zero (unless static keepAlive is true)
|
|
22
152
|
*/
|
|
23
153
|
release<T extends StateContainer<any>>(constructor: new (...args: any[]) => T, key?: string, forceDispose?: boolean): void;
|
|
24
154
|
/**
|
|
@@ -49,6 +179,18 @@ declare class StateContainerRegistry {
|
|
|
49
179
|
* Check if an instance exists
|
|
50
180
|
*/
|
|
51
181
|
hasInstance<T extends StateContainer<any>>(constructor: new (...args: any[]) => T, key?: string): boolean;
|
|
182
|
+
/**
|
|
183
|
+
* Subscribe to lifecycle events
|
|
184
|
+
* @param event - The lifecycle event to listen for
|
|
185
|
+
* @param listener - The listener function to call when the event occurs
|
|
186
|
+
* @returns Unsubscribe function
|
|
187
|
+
*/
|
|
188
|
+
on<E extends LifecycleEvent>(event: E, listener: LifecycleListener<E>): () => void;
|
|
189
|
+
/**
|
|
190
|
+
* Emit lifecycle event to all listeners
|
|
191
|
+
* @internal - Called by StateContainer/Vertex lifecycle methods
|
|
192
|
+
*/
|
|
193
|
+
emit(event: LifecycleEvent, ...args: any[]): void;
|
|
52
194
|
}
|
|
53
195
|
/**
|
|
54
196
|
* Global default registry instance
|
|
@@ -62,14 +204,10 @@ declare const globalRegistry: StateContainerRegistry;
|
|
|
62
204
|
interface StateContainerConfig {
|
|
63
205
|
/** Container name for debugging */
|
|
64
206
|
name?: string;
|
|
65
|
-
/** Whether to keep container alive when no consumers */
|
|
66
|
-
keepAlive?: boolean;
|
|
67
207
|
/** Enable debug logging */
|
|
68
208
|
debug?: boolean;
|
|
69
209
|
/** Custom instance identifier */
|
|
70
210
|
instanceId?: string;
|
|
71
|
-
/** Whether this instance should be isolated (not shared) */
|
|
72
|
-
isolated?: boolean;
|
|
73
211
|
}
|
|
74
212
|
/**
|
|
75
213
|
* Listener function for state changes
|
|
@@ -79,7 +217,7 @@ type StateListener<S$1> = (state: S$1) => void;
|
|
|
79
217
|
* Base abstract class for all state containers
|
|
80
218
|
*/
|
|
81
219
|
declare abstract class StateContainer<S$1> {
|
|
82
|
-
|
|
220
|
+
protected static _registry: StateContainerRegistry;
|
|
83
221
|
/**
|
|
84
222
|
* Set a custom registry (mainly for testing)
|
|
85
223
|
*/
|
|
@@ -135,7 +273,6 @@ declare abstract class StateContainer<S$1> {
|
|
|
135
273
|
private _disposed;
|
|
136
274
|
private readonly config;
|
|
137
275
|
readonly name: string;
|
|
138
|
-
readonly keepAlive: boolean;
|
|
139
276
|
readonly debug: boolean;
|
|
140
277
|
readonly instanceId: string;
|
|
141
278
|
/**
|
|
@@ -238,6 +375,7 @@ interface TodoState {
|
|
|
238
375
|
isLoading: boolean;
|
|
239
376
|
}
|
|
240
377
|
declare class TodoCubit extends Cubit<TodoState> {
|
|
378
|
+
static keepAlive: boolean;
|
|
241
379
|
private nextId;
|
|
242
380
|
constructor();
|
|
243
381
|
addTodo: (text: string) => void;
|
|
@@ -253,127 +391,6 @@ declare class TodoCubit extends Cubit<TodoState> {
|
|
|
253
391
|
get activeTodoCount(): number;
|
|
254
392
|
}
|
|
255
393
|
//#endregion
|
|
256
|
-
//#region src/types/events.d.ts
|
|
257
|
-
/**
|
|
258
|
-
* Base event interface for type-safe event system
|
|
259
|
-
*/
|
|
260
|
-
/**
|
|
261
|
-
* Base event interface
|
|
262
|
-
* Used by Vertex for event-driven state management
|
|
263
|
-
*/
|
|
264
|
-
interface BaseEvent {
|
|
265
|
-
readonly type: string;
|
|
266
|
-
readonly timestamp: number;
|
|
267
|
-
readonly source?: string;
|
|
268
|
-
}
|
|
269
|
-
//#endregion
|
|
270
|
-
//#region src/core/Vertex.d.ts
|
|
271
|
-
/**
|
|
272
|
-
* Event handler signature (synchronous only)
|
|
273
|
-
*/
|
|
274
|
-
type EventHandler<E extends BaseEvent, S$1> = (event: E, emit: (state: S$1) => void) => void;
|
|
275
|
-
/**
|
|
276
|
-
* Type-safe event constructor
|
|
277
|
-
*/
|
|
278
|
-
type EventConstructor<T$1 extends BaseEvent = BaseEvent> = new (...args: never[]) => T$1;
|
|
279
|
-
/**
|
|
280
|
-
* Vertex is an event-driven state container (Bloc pattern)
|
|
281
|
-
*
|
|
282
|
-
* Includes its own simple event system since events are only needed
|
|
283
|
-
* for the Vertex pattern, not for the base StateContainer.
|
|
284
|
-
*/
|
|
285
|
-
declare abstract class Vertex<S$1, E extends BaseEvent = BaseEvent> extends StateContainer<S$1> {
|
|
286
|
-
private eventHandlers;
|
|
287
|
-
private isProcessing;
|
|
288
|
-
private eventQueue;
|
|
289
|
-
/**
|
|
290
|
-
* Create a new Vertex
|
|
291
|
-
* @param initialState Initial state value
|
|
292
|
-
* @param config Configuration options
|
|
293
|
-
*/
|
|
294
|
-
constructor(initialState: S$1, config?: StateContainerConfig);
|
|
295
|
-
/**
|
|
296
|
-
* Register an event handler
|
|
297
|
-
* Arrow function to maintain correct 'this' binding
|
|
298
|
-
*/
|
|
299
|
-
protected on: <T extends E>(EventClass: EventConstructor<T>, handler: EventHandler<T, S$1>) => void;
|
|
300
|
-
/**
|
|
301
|
-
* Add an event to be processed
|
|
302
|
-
* Arrow function to maintain correct 'this' binding in React
|
|
303
|
-
*/
|
|
304
|
-
add: (event: E) => void;
|
|
305
|
-
/**
|
|
306
|
-
* Process an event (synchronously)
|
|
307
|
-
*/
|
|
308
|
-
private processEvent;
|
|
309
|
-
/**
|
|
310
|
-
* Handle a single event (synchronously)
|
|
311
|
-
*/
|
|
312
|
-
private handleEvent;
|
|
313
|
-
/**
|
|
314
|
-
* Hook for handling event processing errors
|
|
315
|
-
*/
|
|
316
|
-
protected onEventError(event: E, error: Error): void;
|
|
317
|
-
}
|
|
318
|
-
/**
|
|
319
|
-
* Example: Counter Events
|
|
320
|
-
*/
|
|
321
|
-
declare class IncrementEvent implements BaseEvent {
|
|
322
|
-
readonly amount: number;
|
|
323
|
-
readonly type = "increment";
|
|
324
|
-
readonly timestamp: number;
|
|
325
|
-
constructor(amount?: number);
|
|
326
|
-
}
|
|
327
|
-
declare class DecrementEvent implements BaseEvent {
|
|
328
|
-
readonly amount: number;
|
|
329
|
-
readonly type = "decrement";
|
|
330
|
-
readonly timestamp: number;
|
|
331
|
-
constructor(amount?: number);
|
|
332
|
-
}
|
|
333
|
-
declare class ResetEvent implements BaseEvent {
|
|
334
|
-
readonly type = "reset";
|
|
335
|
-
readonly timestamp: number;
|
|
336
|
-
}
|
|
337
|
-
/**
|
|
338
|
-
* Example: Counter Vertex
|
|
339
|
-
* Demonstrates proper typing and event handling
|
|
340
|
-
*/
|
|
341
|
-
declare class CounterVertex extends Vertex<number> {
|
|
342
|
-
constructor();
|
|
343
|
-
increment: (amount?: number) => void;
|
|
344
|
-
decrement: (amount?: number) => void;
|
|
345
|
-
reset: () => void;
|
|
346
|
-
}
|
|
347
|
-
/**
|
|
348
|
-
* Auth State and Events for testing async handlers
|
|
349
|
-
*/
|
|
350
|
-
interface AuthState {
|
|
351
|
-
isAuthenticated: boolean;
|
|
352
|
-
isLoading: boolean;
|
|
353
|
-
user: {
|
|
354
|
-
id: string;
|
|
355
|
-
name: string;
|
|
356
|
-
email: string;
|
|
357
|
-
} | null;
|
|
358
|
-
error: string | null;
|
|
359
|
-
}
|
|
360
|
-
declare class LoginEvent implements BaseEvent {
|
|
361
|
-
readonly email: string;
|
|
362
|
-
readonly password: string;
|
|
363
|
-
readonly type = "login";
|
|
364
|
-
readonly timestamp: number;
|
|
365
|
-
constructor(email: string, password: string);
|
|
366
|
-
}
|
|
367
|
-
declare class LogoutEvent implements BaseEvent {
|
|
368
|
-
readonly type = "logout";
|
|
369
|
-
readonly timestamp: number;
|
|
370
|
-
}
|
|
371
|
-
declare class AuthVertex extends Vertex<AuthState> {
|
|
372
|
-
constructor();
|
|
373
|
-
login: (email: string, password: string) => void;
|
|
374
|
-
logout: () => void;
|
|
375
|
-
}
|
|
376
|
-
//#endregion
|
|
377
394
|
//#region src/types/branded.d.ts
|
|
378
395
|
/**
|
|
379
396
|
* Branded types for type-safe IDs
|
|
@@ -864,5 +881,5 @@ declare function generateSimpleId(prefix: string): string;
|
|
|
864
881
|
*/
|
|
865
882
|
declare function __resetIdCounters(): void;
|
|
866
883
|
//#endregion
|
|
867
|
-
export { type AnyObject, AuthState, AuthVertex, BLAC_DEFAULTS, type BaseEvent, BlocConstructor, type Brand, type BrandedId, CounterCubit, CounterVertex, Cubit, DecrementEvent, EventConstructor, EventHandler, ExtractConstructorArgs, ExtractState, IncrementEvent, type InstanceId, type LogConfig, type LogEntry, LogLevel, LoginEvent, LogoutEvent, PathInfo, ProxyTracker, ProxyTrackerState, ResetEvent, StateContainer, StateContainerConfig, StateContainerRegistry, TodoCubit, TodoState, TrackerState, Vertex, __resetIdCounters, captureTrackedPaths, configureLogger, createArrayProxy, createIdGenerator, createLogger, createProxy, createProxyForTarget, createProxyInternal, createProxyTrackerState, createTrackerState, debug, error, generateId, generateSimpleId, getValueAtPath, globalProxyTracker, globalRegistry, hasChanges, hasTrackedData, info, isProxyable, parsePath, shallowEqual, startProxyTracking, startTracking, stopProxyTracking, trackAccess, warn };
|
|
884
|
+
export { type AnyObject, AuthState, AuthVertex, BLAC_DEFAULTS, type BaseEvent, BlocConstructor, type Brand, type BrandedId, CounterCubit, CounterVertex, Cubit, DecrementEvent, EventConstructor, EventHandler, ExtractConstructorArgs, ExtractState, IncrementEvent, type InstanceId, type LifecycleEvent, type LifecycleListener, type LogConfig, type LogEntry, LogLevel, LoginEvent, LogoutEvent, PathInfo, ProxyTracker, ProxyTrackerState, ResetEvent, StateContainer, StateContainerConfig, StateContainerRegistry, TodoCubit, TodoState, TrackerState, Vertex, __resetIdCounters, captureTrackedPaths, configureLogger, createArrayProxy, createIdGenerator, createLogger, createProxy, createProxyForTarget, createProxyInternal, createProxyTrackerState, createTrackerState, debug, error, generateId, generateSimpleId, getValueAtPath, globalProxyTracker, globalRegistry, hasChanges, hasTrackedData, info, isProxyable, parsePath, shallowEqual, startProxyTracking, startTracking, stopProxyTracking, trackAccess, warn };
|
|
868
885
|
//# sourceMappingURL=index.d.ts.map
|