@blac/core 2.0.0-rc.6 → 2.0.0-rc.9

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.
@@ -0,0 +1,113 @@
1
+ /**
2
+ * Vertex - Event-driven state container (Bloc pattern)
3
+ *
4
+ * Simplified version that includes its own event handling,
5
+ * since events are only needed for the Vertex pattern.
6
+ */
7
+ import { StateContainer } from './StateContainer';
8
+ import { BaseEvent } from '../types/events';
9
+ /**
10
+ * Event handler signature (synchronous only)
11
+ */
12
+ export type EventHandler<E extends BaseEvent, S> = (event: E, emit: (state: S) => void) => void;
13
+ /**
14
+ * Type-safe event constructor
15
+ */
16
+ export type EventConstructor<T extends BaseEvent = BaseEvent> = new (...args: never[]) => T;
17
+ /**
18
+ * Vertex is an event-driven state container (Bloc pattern)
19
+ *
20
+ * Includes its own simple event system since events are only needed
21
+ * for the Vertex pattern, not for the base StateContainer.
22
+ */
23
+ export declare abstract class Vertex<S, E extends BaseEvent = BaseEvent> extends StateContainer<S> {
24
+ private eventHandlers;
25
+ private isProcessing;
26
+ private eventQueue;
27
+ /**
28
+ * Create a new Vertex
29
+ * @param initialState Initial state value
30
+ */
31
+ constructor(initialState: S);
32
+ /**
33
+ * Register an event handler
34
+ * Arrow function to maintain correct 'this' binding
35
+ */
36
+ protected on: <T extends E>(EventClass: EventConstructor<T>, handler: EventHandler<T, S>) => void;
37
+ /**
38
+ * Add an event to be processed
39
+ * Arrow function to maintain correct 'this' binding in React
40
+ */
41
+ add: (event: E) => void;
42
+ /**
43
+ * Process an event (synchronously)
44
+ */
45
+ private processEvent;
46
+ /**
47
+ * Handle a single event (synchronously)
48
+ */
49
+ private handleEvent;
50
+ /**
51
+ * Hook for handling event processing errors
52
+ */
53
+ protected onEventError(_event: E, _error: Error): void;
54
+ }
55
+ /**
56
+ * Example: Counter Events
57
+ */
58
+ export declare class IncrementEvent implements BaseEvent {
59
+ readonly amount: number;
60
+ readonly type = "increment";
61
+ readonly timestamp: number;
62
+ constructor(amount?: number);
63
+ }
64
+ export declare class DecrementEvent implements BaseEvent {
65
+ readonly amount: number;
66
+ readonly type = "decrement";
67
+ readonly timestamp: number;
68
+ constructor(amount?: number);
69
+ }
70
+ export declare class ResetEvent implements BaseEvent {
71
+ readonly type = "reset";
72
+ readonly timestamp: number;
73
+ }
74
+ /**
75
+ * Example: Counter Vertex
76
+ * Demonstrates proper typing and event handling
77
+ */
78
+ export declare class CounterVertex extends Vertex<number> {
79
+ constructor();
80
+ increment: (amount?: number) => void;
81
+ decrement: (amount?: number) => void;
82
+ reset: () => void;
83
+ }
84
+ /**
85
+ * Auth State and Events for testing async handlers
86
+ */
87
+ export interface AuthState {
88
+ isAuthenticated: boolean;
89
+ isLoading: boolean;
90
+ user: {
91
+ id: string;
92
+ name: string;
93
+ email: string;
94
+ } | null;
95
+ error: string | null;
96
+ }
97
+ export declare class LoginEvent implements BaseEvent {
98
+ readonly email: string;
99
+ readonly password: string;
100
+ readonly type = "login";
101
+ readonly timestamp: number;
102
+ constructor(email: string, password: string);
103
+ }
104
+ export declare class LogoutEvent implements BaseEvent {
105
+ readonly type = "logout";
106
+ readonly timestamp: number;
107
+ }
108
+ export declare class AuthVertex extends Vertex<AuthState> {
109
+ constructor();
110
+ login: (email: string, password: string) => void;
111
+ logout: () => void;
112
+ }
113
+ //# sourceMappingURL=Vertex.d.ts.map