@blac/react 2.0.0-rc.4 → 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.d.cts +87 -2
- package/dist/index.d.ts +87 -2
- package/package.json +3 -3
package/dist/index.d.cts
CHANGED
|
@@ -1,13 +1,86 @@
|
|
|
1
1
|
import { RefObject } from "react";
|
|
2
2
|
|
|
3
|
-
//#region ../blac/src/
|
|
3
|
+
//#region ../blac/src/types/events.d.ts
|
|
4
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;
|
|
5
77
|
/**
|
|
6
78
|
* Registry for managing StateContainer instances
|
|
7
79
|
*/
|
|
8
80
|
declare class StateContainerRegistry {
|
|
9
81
|
private readonly instances;
|
|
10
82
|
private readonly types;
|
|
83
|
+
private readonly listeners;
|
|
11
84
|
/**
|
|
12
85
|
* Register a type with isolation mode
|
|
13
86
|
*/
|
|
@@ -51,6 +124,18 @@ declare class StateContainerRegistry {
|
|
|
51
124
|
* Check if an instance exists
|
|
52
125
|
*/
|
|
53
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;
|
|
54
139
|
}
|
|
55
140
|
//#endregion
|
|
56
141
|
//#region ../blac/src/core/StateContainer.d.ts
|
|
@@ -73,7 +158,7 @@ type StateListener<S$1> = (state: S$1) => void;
|
|
|
73
158
|
* Base abstract class for all state containers
|
|
74
159
|
*/
|
|
75
160
|
declare abstract class StateContainer<S$1> {
|
|
76
|
-
|
|
161
|
+
protected static _registry: StateContainerRegistry;
|
|
77
162
|
/**
|
|
78
163
|
* Set a custom registry (mainly for testing)
|
|
79
164
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,86 @@
|
|
|
1
1
|
import { RefObject } from "react";
|
|
2
2
|
|
|
3
|
-
//#region ../blac/src/
|
|
3
|
+
//#region ../blac/src/types/events.d.ts
|
|
4
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;
|
|
5
77
|
/**
|
|
6
78
|
* Registry for managing StateContainer instances
|
|
7
79
|
*/
|
|
8
80
|
declare class StateContainerRegistry {
|
|
9
81
|
private readonly instances;
|
|
10
82
|
private readonly types;
|
|
83
|
+
private readonly listeners;
|
|
11
84
|
/**
|
|
12
85
|
* Register a type with isolation mode
|
|
13
86
|
*/
|
|
@@ -51,6 +124,18 @@ declare class StateContainerRegistry {
|
|
|
51
124
|
* Check if an instance exists
|
|
52
125
|
*/
|
|
53
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;
|
|
54
139
|
}
|
|
55
140
|
//#endregion
|
|
56
141
|
//#region ../blac/src/core/StateContainer.d.ts
|
|
@@ -73,7 +158,7 @@ type StateListener<S$1> = (state: S$1) => void;
|
|
|
73
158
|
* Base abstract class for all state containers
|
|
74
159
|
*/
|
|
75
160
|
declare abstract class StateContainer<S$1> {
|
|
76
|
-
|
|
161
|
+
protected static _registry: StateContainerRegistry;
|
|
77
162
|
/**
|
|
78
163
|
* Set a custom registry (mainly for testing)
|
|
79
164
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blac/react",
|
|
3
|
-
"version": "2.0.0-rc.
|
|
3
|
+
"version": "2.0.0-rc.5",
|
|
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.
|
|
39
|
+
"@blac/core": "2.0.0-rc.5"
|
|
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.
|
|
68
|
+
"@blac/core": "2.0.0-rc.5"
|
|
69
69
|
},
|
|
70
70
|
"scripts": {
|
|
71
71
|
"dev": "tsdown --watch",
|