@blac/core 2.0.0-rc.15 → 2.0.0-rc.16
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 +128 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +161 -42
- package/dist/index.d.ts +161 -42
- package/dist/index.js +125 -26
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -15,19 +15,6 @@ export declare interface AdapterState<TBloc extends StateContainerConstructor> {
|
|
|
15
15
|
proxiedBloc: InstanceState<TBloc> | null;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
/**
|
|
19
|
-
* Base event interface
|
|
20
|
-
* Used by Vertex for event-driven state management
|
|
21
|
-
*/
|
|
22
|
-
export declare interface BaseEvent {
|
|
23
|
-
/** Event type identifier (typically the class name) */
|
|
24
|
-
readonly type: string;
|
|
25
|
-
/** Unix timestamp when the event was created */
|
|
26
|
-
readonly timestamp: number;
|
|
27
|
-
/** Optional source identifier for debugging */
|
|
28
|
-
readonly source?: string;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
18
|
/**
|
|
32
19
|
* Decorator to configure StateContainer classes.
|
|
33
20
|
*
|
|
@@ -132,6 +119,16 @@ export declare const BLAC_STATIC_PROPS: {
|
|
|
132
119
|
readonly EXCLUDE_FROM_DEVTOOLS: "__excludeFromDevTools";
|
|
133
120
|
};
|
|
134
121
|
|
|
122
|
+
/**
|
|
123
|
+
* Global configuration for @blac/core
|
|
124
|
+
*/
|
|
125
|
+
export declare interface BlacConfig {
|
|
126
|
+
/** Enable development mode (enables additional warnings and checks) */
|
|
127
|
+
devMode: boolean;
|
|
128
|
+
/** Logger configuration */
|
|
129
|
+
logger: Partial<LogConfig>;
|
|
130
|
+
}
|
|
131
|
+
|
|
135
132
|
/**
|
|
136
133
|
* Configuration options for the @blac decorator.
|
|
137
134
|
* Only one option can be specified at a time (union type).
|
|
@@ -177,7 +174,7 @@ export declare interface BlacPlugin {
|
|
|
177
174
|
/**
|
|
178
175
|
* Called when an event is added to a Vertex instance
|
|
179
176
|
*/
|
|
180
|
-
onEventAdded?<E extends
|
|
177
|
+
onEventAdded?<E extends DiscriminatedEvent>(vertex: Vertex<any, E>, event: EventWithMetadata<E>, context: PluginContext): void;
|
|
181
178
|
/**
|
|
182
179
|
* Called when a state container instance is disposed
|
|
183
180
|
*/
|
|
@@ -246,6 +243,26 @@ export declare type BrandedId<B> = Brand<string, B>;
|
|
|
246
243
|
|
|
247
244
|
/* Excluded from this release type: commitTrackedGetters */
|
|
248
245
|
|
|
246
|
+
/**
|
|
247
|
+
* Configure global defaults for @blac/core.
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* ```ts
|
|
251
|
+
* import { configureBlac, LogLevel } from '@blac/core';
|
|
252
|
+
*
|
|
253
|
+
* configureBlac({
|
|
254
|
+
* devMode: true,
|
|
255
|
+
* logger: {
|
|
256
|
+
* enabled: true,
|
|
257
|
+
* level: LogLevel.DEBUG
|
|
258
|
+
* }
|
|
259
|
+
* });
|
|
260
|
+
* ```
|
|
261
|
+
*
|
|
262
|
+
* @param config - Partial configuration to merge with defaults
|
|
263
|
+
*/
|
|
264
|
+
export declare function configureBlac(config: Partial<BlacConfig>): void;
|
|
265
|
+
|
|
249
266
|
/**
|
|
250
267
|
* Configuration function that recreates the default logger
|
|
251
268
|
*
|
|
@@ -425,6 +442,21 @@ export declare const debug: (context: string, message: string, data?: any) => vo
|
|
|
425
442
|
*/
|
|
426
443
|
export declare function disableGetterTracking<TBloc extends StateContainerConstructor>(adapterState: AdapterState<TBloc>, rawInstance: InstanceState<TBloc>): void;
|
|
427
444
|
|
|
445
|
+
/**
|
|
446
|
+
* Base type for discriminated union events.
|
|
447
|
+
* All events must have a `type` property as the discriminator.
|
|
448
|
+
*
|
|
449
|
+
* @example
|
|
450
|
+
* ```typescript
|
|
451
|
+
* type MyEvent =
|
|
452
|
+
* | { type: 'increment'; amount: number }
|
|
453
|
+
* | { type: 'decrement' };
|
|
454
|
+
* ```
|
|
455
|
+
*/
|
|
456
|
+
export declare interface DiscriminatedEvent {
|
|
457
|
+
readonly type: string;
|
|
458
|
+
}
|
|
459
|
+
|
|
428
460
|
/**
|
|
429
461
|
* Log an error message (tree-shakeable export)
|
|
430
462
|
* @param context - Context identifier (module or component name)
|
|
@@ -434,19 +466,45 @@ export declare function disableGetterTracking<TBloc extends StateContainerConstr
|
|
|
434
466
|
export declare const error: (context: string, message: string, data?: any) => void;
|
|
435
467
|
|
|
436
468
|
/**
|
|
437
|
-
*
|
|
438
|
-
*
|
|
469
|
+
* Map of event handlers requiring exhaustive coverage.
|
|
470
|
+
* TypeScript enforces that every event type in the union has a handler.
|
|
471
|
+
*
|
|
472
|
+
* @template E - The discriminated event union type
|
|
473
|
+
* @template S - The state type
|
|
474
|
+
*
|
|
475
|
+
* @example
|
|
476
|
+
* ```typescript
|
|
477
|
+
* type CounterEvent =
|
|
478
|
+
* | { type: 'increment'; amount: number }
|
|
479
|
+
* | { type: 'reset' };
|
|
480
|
+
*
|
|
481
|
+
* // All event types must be handled:
|
|
482
|
+
* const handlers: EventHandlerMap<CounterEvent, { count: number }> = {
|
|
483
|
+
* increment: (event, emit) => emit({ count: event.amount }),
|
|
484
|
+
* reset: (_, emit) => emit({ count: 0 }),
|
|
485
|
+
* };
|
|
486
|
+
* ```
|
|
439
487
|
*/
|
|
440
|
-
export declare type
|
|
488
|
+
export declare type EventHandlerMap<E extends DiscriminatedEvent, S extends object> = {
|
|
489
|
+
[K in EventType<E>]: VertexEventHandler<ExtractEvent<E, K>, S>;
|
|
490
|
+
};
|
|
491
|
+
|
|
492
|
+
/* Excluded from this release type: EventMetadata */
|
|
441
493
|
|
|
442
494
|
/**
|
|
443
|
-
*
|
|
444
|
-
*
|
|
445
|
-
* @template
|
|
446
|
-
*
|
|
447
|
-
* @
|
|
495
|
+
* Extract the `type` literal union from a discriminated event union.
|
|
496
|
+
*
|
|
497
|
+
* @template E - The discriminated event union type
|
|
498
|
+
*
|
|
499
|
+
* @example
|
|
500
|
+
* ```typescript
|
|
501
|
+
* type MyEvent = { type: 'a' } | { type: 'b' };
|
|
502
|
+
* type Types = EventType<MyEvent>; // 'a' | 'b'
|
|
503
|
+
* ```
|
|
448
504
|
*/
|
|
449
|
-
export declare type
|
|
505
|
+
export declare type EventType<E extends DiscriminatedEvent> = E['type'];
|
|
506
|
+
|
|
507
|
+
/* Excluded from this release type: EventWithMetadata */
|
|
450
508
|
|
|
451
509
|
/**
|
|
452
510
|
* Manages subscriptions to external bloc dependencies for getter tracking.
|
|
@@ -478,6 +536,22 @@ export declare class ExternalDependencyManager {
|
|
|
478
536
|
*/
|
|
479
537
|
export declare type ExtractConstructorArgs<T> = T extends new (...args: infer P) => any ? P : never[];
|
|
480
538
|
|
|
539
|
+
/**
|
|
540
|
+
* Extract a specific event variant from a union by its type.
|
|
541
|
+
*
|
|
542
|
+
* @template E - The discriminated event union type
|
|
543
|
+
* @template T - The type literal to extract
|
|
544
|
+
*
|
|
545
|
+
* @example
|
|
546
|
+
* ```typescript
|
|
547
|
+
* type MyEvent = { type: 'a'; value: number } | { type: 'b' };
|
|
548
|
+
* type EventA = ExtractEvent<MyEvent, 'a'>; // { type: 'a'; value: number }
|
|
549
|
+
* ```
|
|
550
|
+
*/
|
|
551
|
+
export declare type ExtractEvent<E extends DiscriminatedEvent, T extends EventType<E>> = Extract<E, {
|
|
552
|
+
type: T;
|
|
553
|
+
}>;
|
|
554
|
+
|
|
481
555
|
/**
|
|
482
556
|
* Extract the props type from a StateContainer
|
|
483
557
|
* @template T - The StateContainer type
|
|
@@ -535,6 +609,8 @@ export declare function generateSimpleId(prefix: string, affix?: string): string
|
|
|
535
609
|
|
|
536
610
|
/* Excluded from this release type: getActiveTracker */
|
|
537
611
|
|
|
612
|
+
/* Excluded from this release type: getBlacConfig */
|
|
613
|
+
|
|
538
614
|
/* Excluded from this release type: getDescriptor */
|
|
539
615
|
|
|
540
616
|
/* Excluded from this release type: getGetterExecutionContext */
|
|
@@ -670,6 +746,11 @@ export declare type InstanceState<T extends StateContainerConstructor = any> = O
|
|
|
670
746
|
|
|
671
747
|
/* Excluded from this release type: invalidateRenderCache */
|
|
672
748
|
|
|
749
|
+
/**
|
|
750
|
+
* Check if development mode is enabled.
|
|
751
|
+
*/
|
|
752
|
+
export declare function isDevMode(): boolean;
|
|
753
|
+
|
|
673
754
|
/**
|
|
674
755
|
* Check if a class should be excluded from DevTools.
|
|
675
756
|
* Used to prevent infinite loops when DevTools tracks itself.
|
|
@@ -887,6 +968,8 @@ export declare class PluginManager {
|
|
|
887
968
|
|
|
888
969
|
/* Excluded from this release type: ProxyTrackerState */
|
|
889
970
|
|
|
971
|
+
/* Excluded from this release type: resetBlacConfig */
|
|
972
|
+
|
|
890
973
|
/* Excluded from this release type: resetGetterTracker */
|
|
891
974
|
|
|
892
975
|
/* Excluded from this release type: setActiveTracker */
|
|
@@ -1336,40 +1419,76 @@ export declare interface SystemEventPayloads<S, P> {
|
|
|
1336
1419
|
/* Excluded from this release type: TrackerState */
|
|
1337
1420
|
|
|
1338
1421
|
/**
|
|
1339
|
-
* Event-driven state container
|
|
1340
|
-
*
|
|
1422
|
+
* Event-driven state container using discriminated union events.
|
|
1423
|
+
* Extends StateContainer with event-based state transitions and
|
|
1424
|
+
* compile-time exhaustive checking for event handlers.
|
|
1341
1425
|
*
|
|
1342
|
-
* @template S - State type
|
|
1343
|
-
* @template E - Event type (
|
|
1426
|
+
* @template S - State type (must be an object)
|
|
1427
|
+
* @template E - Event union type (discriminated by 'type' property)
|
|
1344
1428
|
* @template P - Props type (optional)
|
|
1429
|
+
*
|
|
1430
|
+
* @example
|
|
1431
|
+
* ```typescript
|
|
1432
|
+
* type CounterEvent =
|
|
1433
|
+
* | { type: 'increment'; amount: number }
|
|
1434
|
+
* | { type: 'decrement' }
|
|
1435
|
+
* | { type: 'reset' };
|
|
1436
|
+
*
|
|
1437
|
+
* class CounterVertex extends Vertex<{ count: number }, CounterEvent> {
|
|
1438
|
+
* constructor() {
|
|
1439
|
+
* super({ count: 0 });
|
|
1440
|
+
* this.createHandlers({
|
|
1441
|
+
* increment: (event, emit) => {
|
|
1442
|
+
* emit({ count: this.state.count + event.amount });
|
|
1443
|
+
* },
|
|
1444
|
+
* decrement: (_, emit) => {
|
|
1445
|
+
* emit({ count: this.state.count - 1 });
|
|
1446
|
+
* },
|
|
1447
|
+
* reset: (_, emit) => {
|
|
1448
|
+
* emit({ count: 0 });
|
|
1449
|
+
* },
|
|
1450
|
+
* });
|
|
1451
|
+
* }
|
|
1452
|
+
*
|
|
1453
|
+
* increment = (amount = 1) => this.add({ type: 'increment', amount });
|
|
1454
|
+
* }
|
|
1455
|
+
* ```
|
|
1345
1456
|
*/
|
|
1346
|
-
export declare abstract class Vertex<S extends object =
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1457
|
+
export declare abstract class Vertex<S extends object = object, E extends DiscriminatedEvent = DiscriminatedEvent, P = undefined> extends StateContainer<S, P> {
|
|
1458
|
+
/* Excluded from this release type: handlers */
|
|
1459
|
+
/* Excluded from this release type: isProcessing */
|
|
1460
|
+
/* Excluded from this release type: eventQueue */
|
|
1350
1461
|
constructor(initialState: S);
|
|
1351
1462
|
/**
|
|
1352
|
-
* Register
|
|
1353
|
-
*
|
|
1354
|
-
*
|
|
1463
|
+
* Register all event handlers with exhaustive type checking.
|
|
1464
|
+
* TypeScript will error if any event type from the union is missing.
|
|
1465
|
+
*
|
|
1466
|
+
* @param handlers - Map of event type to handler function
|
|
1355
1467
|
*/
|
|
1356
|
-
protected
|
|
1468
|
+
protected createHandlers(handlers: EventHandlerMap<E, S>): void;
|
|
1357
1469
|
/**
|
|
1358
|
-
*
|
|
1359
|
-
*
|
|
1470
|
+
* Dispatch an event for processing.
|
|
1471
|
+
* Events are processed synchronously; if called during processing,
|
|
1472
|
+
* the event is queued and processed after the current event completes.
|
|
1473
|
+
*
|
|
1474
|
+
* @param event - The event to process (must match the event union type)
|
|
1360
1475
|
*/
|
|
1361
1476
|
add: (event: E) => void;
|
|
1362
|
-
|
|
1363
|
-
|
|
1477
|
+
/* Excluded from this release type: enrichEvent */
|
|
1478
|
+
/* Excluded from this release type: processEvent */
|
|
1479
|
+
/* Excluded from this release type: handleEvent */
|
|
1364
1480
|
/**
|
|
1365
|
-
*
|
|
1366
|
-
* Override
|
|
1481
|
+
* Called when an error occurs during event processing.
|
|
1482
|
+
* Override to implement custom error handling.
|
|
1483
|
+
*
|
|
1367
1484
|
* @param _event - The event that caused the error
|
|
1368
1485
|
* @param _error - The error that occurred
|
|
1369
1486
|
*/
|
|
1370
|
-
protected onEventError(_event: E
|
|
1487
|
+
protected onEventError(_event: EventWithMetadata<E>, _error: Error): void;
|
|
1371
1488
|
}
|
|
1372
1489
|
|
|
1490
|
+
/* Excluded from this release type: VertexEventHandler */
|
|
1491
|
+
|
|
1373
1492
|
/**
|
|
1374
1493
|
* Log a warning message (tree-shakeable export)
|
|
1375
1494
|
* @param context - Context identifier (module or component name)
|
package/dist/index.d.ts
CHANGED
|
@@ -15,19 +15,6 @@ export declare interface AdapterState<TBloc extends StateContainerConstructor> {
|
|
|
15
15
|
proxiedBloc: InstanceState<TBloc> | null;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
/**
|
|
19
|
-
* Base event interface
|
|
20
|
-
* Used by Vertex for event-driven state management
|
|
21
|
-
*/
|
|
22
|
-
export declare interface BaseEvent {
|
|
23
|
-
/** Event type identifier (typically the class name) */
|
|
24
|
-
readonly type: string;
|
|
25
|
-
/** Unix timestamp when the event was created */
|
|
26
|
-
readonly timestamp: number;
|
|
27
|
-
/** Optional source identifier for debugging */
|
|
28
|
-
readonly source?: string;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
18
|
/**
|
|
32
19
|
* Decorator to configure StateContainer classes.
|
|
33
20
|
*
|
|
@@ -132,6 +119,16 @@ export declare const BLAC_STATIC_PROPS: {
|
|
|
132
119
|
readonly EXCLUDE_FROM_DEVTOOLS: "__excludeFromDevTools";
|
|
133
120
|
};
|
|
134
121
|
|
|
122
|
+
/**
|
|
123
|
+
* Global configuration for @blac/core
|
|
124
|
+
*/
|
|
125
|
+
export declare interface BlacConfig {
|
|
126
|
+
/** Enable development mode (enables additional warnings and checks) */
|
|
127
|
+
devMode: boolean;
|
|
128
|
+
/** Logger configuration */
|
|
129
|
+
logger: Partial<LogConfig>;
|
|
130
|
+
}
|
|
131
|
+
|
|
135
132
|
/**
|
|
136
133
|
* Configuration options for the @blac decorator.
|
|
137
134
|
* Only one option can be specified at a time (union type).
|
|
@@ -177,7 +174,7 @@ export declare interface BlacPlugin {
|
|
|
177
174
|
/**
|
|
178
175
|
* Called when an event is added to a Vertex instance
|
|
179
176
|
*/
|
|
180
|
-
onEventAdded?<E extends
|
|
177
|
+
onEventAdded?<E extends DiscriminatedEvent>(vertex: Vertex<any, E>, event: EventWithMetadata<E>, context: PluginContext): void;
|
|
181
178
|
/**
|
|
182
179
|
* Called when a state container instance is disposed
|
|
183
180
|
*/
|
|
@@ -246,6 +243,26 @@ export declare type BrandedId<B> = Brand<string, B>;
|
|
|
246
243
|
|
|
247
244
|
/* Excluded from this release type: commitTrackedGetters */
|
|
248
245
|
|
|
246
|
+
/**
|
|
247
|
+
* Configure global defaults for @blac/core.
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* ```ts
|
|
251
|
+
* import { configureBlac, LogLevel } from '@blac/core';
|
|
252
|
+
*
|
|
253
|
+
* configureBlac({
|
|
254
|
+
* devMode: true,
|
|
255
|
+
* logger: {
|
|
256
|
+
* enabled: true,
|
|
257
|
+
* level: LogLevel.DEBUG
|
|
258
|
+
* }
|
|
259
|
+
* });
|
|
260
|
+
* ```
|
|
261
|
+
*
|
|
262
|
+
* @param config - Partial configuration to merge with defaults
|
|
263
|
+
*/
|
|
264
|
+
export declare function configureBlac(config: Partial<BlacConfig>): void;
|
|
265
|
+
|
|
249
266
|
/**
|
|
250
267
|
* Configuration function that recreates the default logger
|
|
251
268
|
*
|
|
@@ -425,6 +442,21 @@ export declare const debug: (context: string, message: string, data?: any) => vo
|
|
|
425
442
|
*/
|
|
426
443
|
export declare function disableGetterTracking<TBloc extends StateContainerConstructor>(adapterState: AdapterState<TBloc>, rawInstance: InstanceState<TBloc>): void;
|
|
427
444
|
|
|
445
|
+
/**
|
|
446
|
+
* Base type for discriminated union events.
|
|
447
|
+
* All events must have a `type` property as the discriminator.
|
|
448
|
+
*
|
|
449
|
+
* @example
|
|
450
|
+
* ```typescript
|
|
451
|
+
* type MyEvent =
|
|
452
|
+
* | { type: 'increment'; amount: number }
|
|
453
|
+
* | { type: 'decrement' };
|
|
454
|
+
* ```
|
|
455
|
+
*/
|
|
456
|
+
export declare interface DiscriminatedEvent {
|
|
457
|
+
readonly type: string;
|
|
458
|
+
}
|
|
459
|
+
|
|
428
460
|
/**
|
|
429
461
|
* Log an error message (tree-shakeable export)
|
|
430
462
|
* @param context - Context identifier (module or component name)
|
|
@@ -434,19 +466,45 @@ export declare function disableGetterTracking<TBloc extends StateContainerConstr
|
|
|
434
466
|
export declare const error: (context: string, message: string, data?: any) => void;
|
|
435
467
|
|
|
436
468
|
/**
|
|
437
|
-
*
|
|
438
|
-
*
|
|
469
|
+
* Map of event handlers requiring exhaustive coverage.
|
|
470
|
+
* TypeScript enforces that every event type in the union has a handler.
|
|
471
|
+
*
|
|
472
|
+
* @template E - The discriminated event union type
|
|
473
|
+
* @template S - The state type
|
|
474
|
+
*
|
|
475
|
+
* @example
|
|
476
|
+
* ```typescript
|
|
477
|
+
* type CounterEvent =
|
|
478
|
+
* | { type: 'increment'; amount: number }
|
|
479
|
+
* | { type: 'reset' };
|
|
480
|
+
*
|
|
481
|
+
* // All event types must be handled:
|
|
482
|
+
* const handlers: EventHandlerMap<CounterEvent, { count: number }> = {
|
|
483
|
+
* increment: (event, emit) => emit({ count: event.amount }),
|
|
484
|
+
* reset: (_, emit) => emit({ count: 0 }),
|
|
485
|
+
* };
|
|
486
|
+
* ```
|
|
439
487
|
*/
|
|
440
|
-
export declare type
|
|
488
|
+
export declare type EventHandlerMap<E extends DiscriminatedEvent, S extends object> = {
|
|
489
|
+
[K in EventType<E>]: VertexEventHandler<ExtractEvent<E, K>, S>;
|
|
490
|
+
};
|
|
491
|
+
|
|
492
|
+
/* Excluded from this release type: EventMetadata */
|
|
441
493
|
|
|
442
494
|
/**
|
|
443
|
-
*
|
|
444
|
-
*
|
|
445
|
-
* @template
|
|
446
|
-
*
|
|
447
|
-
* @
|
|
495
|
+
* Extract the `type` literal union from a discriminated event union.
|
|
496
|
+
*
|
|
497
|
+
* @template E - The discriminated event union type
|
|
498
|
+
*
|
|
499
|
+
* @example
|
|
500
|
+
* ```typescript
|
|
501
|
+
* type MyEvent = { type: 'a' } | { type: 'b' };
|
|
502
|
+
* type Types = EventType<MyEvent>; // 'a' | 'b'
|
|
503
|
+
* ```
|
|
448
504
|
*/
|
|
449
|
-
export declare type
|
|
505
|
+
export declare type EventType<E extends DiscriminatedEvent> = E['type'];
|
|
506
|
+
|
|
507
|
+
/* Excluded from this release type: EventWithMetadata */
|
|
450
508
|
|
|
451
509
|
/**
|
|
452
510
|
* Manages subscriptions to external bloc dependencies for getter tracking.
|
|
@@ -478,6 +536,22 @@ export declare class ExternalDependencyManager {
|
|
|
478
536
|
*/
|
|
479
537
|
export declare type ExtractConstructorArgs<T> = T extends new (...args: infer P) => any ? P : never[];
|
|
480
538
|
|
|
539
|
+
/**
|
|
540
|
+
* Extract a specific event variant from a union by its type.
|
|
541
|
+
*
|
|
542
|
+
* @template E - The discriminated event union type
|
|
543
|
+
* @template T - The type literal to extract
|
|
544
|
+
*
|
|
545
|
+
* @example
|
|
546
|
+
* ```typescript
|
|
547
|
+
* type MyEvent = { type: 'a'; value: number } | { type: 'b' };
|
|
548
|
+
* type EventA = ExtractEvent<MyEvent, 'a'>; // { type: 'a'; value: number }
|
|
549
|
+
* ```
|
|
550
|
+
*/
|
|
551
|
+
export declare type ExtractEvent<E extends DiscriminatedEvent, T extends EventType<E>> = Extract<E, {
|
|
552
|
+
type: T;
|
|
553
|
+
}>;
|
|
554
|
+
|
|
481
555
|
/**
|
|
482
556
|
* Extract the props type from a StateContainer
|
|
483
557
|
* @template T - The StateContainer type
|
|
@@ -535,6 +609,8 @@ export declare function generateSimpleId(prefix: string, affix?: string): string
|
|
|
535
609
|
|
|
536
610
|
/* Excluded from this release type: getActiveTracker */
|
|
537
611
|
|
|
612
|
+
/* Excluded from this release type: getBlacConfig */
|
|
613
|
+
|
|
538
614
|
/* Excluded from this release type: getDescriptor */
|
|
539
615
|
|
|
540
616
|
/* Excluded from this release type: getGetterExecutionContext */
|
|
@@ -670,6 +746,11 @@ export declare type InstanceState<T extends StateContainerConstructor = any> = O
|
|
|
670
746
|
|
|
671
747
|
/* Excluded from this release type: invalidateRenderCache */
|
|
672
748
|
|
|
749
|
+
/**
|
|
750
|
+
* Check if development mode is enabled.
|
|
751
|
+
*/
|
|
752
|
+
export declare function isDevMode(): boolean;
|
|
753
|
+
|
|
673
754
|
/**
|
|
674
755
|
* Check if a class should be excluded from DevTools.
|
|
675
756
|
* Used to prevent infinite loops when DevTools tracks itself.
|
|
@@ -887,6 +968,8 @@ export declare class PluginManager {
|
|
|
887
968
|
|
|
888
969
|
/* Excluded from this release type: ProxyTrackerState */
|
|
889
970
|
|
|
971
|
+
/* Excluded from this release type: resetBlacConfig */
|
|
972
|
+
|
|
890
973
|
/* Excluded from this release type: resetGetterTracker */
|
|
891
974
|
|
|
892
975
|
/* Excluded from this release type: setActiveTracker */
|
|
@@ -1336,40 +1419,76 @@ export declare interface SystemEventPayloads<S, P> {
|
|
|
1336
1419
|
/* Excluded from this release type: TrackerState */
|
|
1337
1420
|
|
|
1338
1421
|
/**
|
|
1339
|
-
* Event-driven state container
|
|
1340
|
-
*
|
|
1422
|
+
* Event-driven state container using discriminated union events.
|
|
1423
|
+
* Extends StateContainer with event-based state transitions and
|
|
1424
|
+
* compile-time exhaustive checking for event handlers.
|
|
1341
1425
|
*
|
|
1342
|
-
* @template S - State type
|
|
1343
|
-
* @template E - Event type (
|
|
1426
|
+
* @template S - State type (must be an object)
|
|
1427
|
+
* @template E - Event union type (discriminated by 'type' property)
|
|
1344
1428
|
* @template P - Props type (optional)
|
|
1429
|
+
*
|
|
1430
|
+
* @example
|
|
1431
|
+
* ```typescript
|
|
1432
|
+
* type CounterEvent =
|
|
1433
|
+
* | { type: 'increment'; amount: number }
|
|
1434
|
+
* | { type: 'decrement' }
|
|
1435
|
+
* | { type: 'reset' };
|
|
1436
|
+
*
|
|
1437
|
+
* class CounterVertex extends Vertex<{ count: number }, CounterEvent> {
|
|
1438
|
+
* constructor() {
|
|
1439
|
+
* super({ count: 0 });
|
|
1440
|
+
* this.createHandlers({
|
|
1441
|
+
* increment: (event, emit) => {
|
|
1442
|
+
* emit({ count: this.state.count + event.amount });
|
|
1443
|
+
* },
|
|
1444
|
+
* decrement: (_, emit) => {
|
|
1445
|
+
* emit({ count: this.state.count - 1 });
|
|
1446
|
+
* },
|
|
1447
|
+
* reset: (_, emit) => {
|
|
1448
|
+
* emit({ count: 0 });
|
|
1449
|
+
* },
|
|
1450
|
+
* });
|
|
1451
|
+
* }
|
|
1452
|
+
*
|
|
1453
|
+
* increment = (amount = 1) => this.add({ type: 'increment', amount });
|
|
1454
|
+
* }
|
|
1455
|
+
* ```
|
|
1345
1456
|
*/
|
|
1346
|
-
export declare abstract class Vertex<S extends object =
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1457
|
+
export declare abstract class Vertex<S extends object = object, E extends DiscriminatedEvent = DiscriminatedEvent, P = undefined> extends StateContainer<S, P> {
|
|
1458
|
+
/* Excluded from this release type: handlers */
|
|
1459
|
+
/* Excluded from this release type: isProcessing */
|
|
1460
|
+
/* Excluded from this release type: eventQueue */
|
|
1350
1461
|
constructor(initialState: S);
|
|
1351
1462
|
/**
|
|
1352
|
-
* Register
|
|
1353
|
-
*
|
|
1354
|
-
*
|
|
1463
|
+
* Register all event handlers with exhaustive type checking.
|
|
1464
|
+
* TypeScript will error if any event type from the union is missing.
|
|
1465
|
+
*
|
|
1466
|
+
* @param handlers - Map of event type to handler function
|
|
1355
1467
|
*/
|
|
1356
|
-
protected
|
|
1468
|
+
protected createHandlers(handlers: EventHandlerMap<E, S>): void;
|
|
1357
1469
|
/**
|
|
1358
|
-
*
|
|
1359
|
-
*
|
|
1470
|
+
* Dispatch an event for processing.
|
|
1471
|
+
* Events are processed synchronously; if called during processing,
|
|
1472
|
+
* the event is queued and processed after the current event completes.
|
|
1473
|
+
*
|
|
1474
|
+
* @param event - The event to process (must match the event union type)
|
|
1360
1475
|
*/
|
|
1361
1476
|
add: (event: E) => void;
|
|
1362
|
-
|
|
1363
|
-
|
|
1477
|
+
/* Excluded from this release type: enrichEvent */
|
|
1478
|
+
/* Excluded from this release type: processEvent */
|
|
1479
|
+
/* Excluded from this release type: handleEvent */
|
|
1364
1480
|
/**
|
|
1365
|
-
*
|
|
1366
|
-
* Override
|
|
1481
|
+
* Called when an error occurs during event processing.
|
|
1482
|
+
* Override to implement custom error handling.
|
|
1483
|
+
*
|
|
1367
1484
|
* @param _event - The event that caused the error
|
|
1368
1485
|
* @param _error - The error that occurred
|
|
1369
1486
|
*/
|
|
1370
|
-
protected onEventError(_event: E
|
|
1487
|
+
protected onEventError(_event: EventWithMetadata<E>, _error: Error): void;
|
|
1371
1488
|
}
|
|
1372
1489
|
|
|
1490
|
+
/* Excluded from this release type: VertexEventHandler */
|
|
1491
|
+
|
|
1373
1492
|
/**
|
|
1374
1493
|
* Log a warning message (tree-shakeable export)
|
|
1375
1494
|
* @param context - Context identifier (module or component name)
|