@blac/react 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.d.cts +88 -8
- package/dist/index.d.ts +88 -8
- 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
|
*/
|
|
@@ -20,7 +93,7 @@ declare class StateContainerRegistry {
|
|
|
20
93
|
getOrCreate<T extends StateContainer<any>>(constructor: new (...args: any[]) => T, key?: string, ...args: any[]): T;
|
|
21
94
|
/**
|
|
22
95
|
* Release a reference to an instance
|
|
23
|
-
* Disposes when ref count reaches zero (unless keepAlive)
|
|
96
|
+
* Disposes when ref count reaches zero (unless static keepAlive is true)
|
|
24
97
|
*/
|
|
25
98
|
release<T extends StateContainer<any>>(constructor: new (...args: any[]) => T, key?: string, forceDispose?: boolean): void;
|
|
26
99
|
/**
|
|
@@ -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
|
|
@@ -60,14 +145,10 @@ declare class StateContainerRegistry {
|
|
|
60
145
|
interface StateContainerConfig {
|
|
61
146
|
/** Container name for debugging */
|
|
62
147
|
name?: string;
|
|
63
|
-
/** Whether to keep container alive when no consumers */
|
|
64
|
-
keepAlive?: boolean;
|
|
65
148
|
/** Enable debug logging */
|
|
66
149
|
debug?: boolean;
|
|
67
150
|
/** Custom instance identifier */
|
|
68
151
|
instanceId?: string;
|
|
69
|
-
/** Whether this instance should be isolated (not shared) */
|
|
70
|
-
isolated?: boolean;
|
|
71
152
|
}
|
|
72
153
|
/**
|
|
73
154
|
* Listener function for state changes
|
|
@@ -77,7 +158,7 @@ type StateListener<S$1> = (state: S$1) => void;
|
|
|
77
158
|
* Base abstract class for all state containers
|
|
78
159
|
*/
|
|
79
160
|
declare abstract class StateContainer<S$1> {
|
|
80
|
-
|
|
161
|
+
protected static _registry: StateContainerRegistry;
|
|
81
162
|
/**
|
|
82
163
|
* Set a custom registry (mainly for testing)
|
|
83
164
|
*/
|
|
@@ -133,7 +214,6 @@ declare abstract class StateContainer<S$1> {
|
|
|
133
214
|
private _disposed;
|
|
134
215
|
private readonly config;
|
|
135
216
|
readonly name: string;
|
|
136
|
-
readonly keepAlive: boolean;
|
|
137
217
|
readonly debug: boolean;
|
|
138
218
|
readonly instanceId: string;
|
|
139
219
|
/**
|
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
|
*/
|
|
@@ -20,7 +93,7 @@ declare class StateContainerRegistry {
|
|
|
20
93
|
getOrCreate<T extends StateContainer<any>>(constructor: new (...args: any[]) => T, key?: string, ...args: any[]): T;
|
|
21
94
|
/**
|
|
22
95
|
* Release a reference to an instance
|
|
23
|
-
* Disposes when ref count reaches zero (unless keepAlive)
|
|
96
|
+
* Disposes when ref count reaches zero (unless static keepAlive is true)
|
|
24
97
|
*/
|
|
25
98
|
release<T extends StateContainer<any>>(constructor: new (...args: any[]) => T, key?: string, forceDispose?: boolean): void;
|
|
26
99
|
/**
|
|
@@ -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
|
|
@@ -60,14 +145,10 @@ declare class StateContainerRegistry {
|
|
|
60
145
|
interface StateContainerConfig {
|
|
61
146
|
/** Container name for debugging */
|
|
62
147
|
name?: string;
|
|
63
|
-
/** Whether to keep container alive when no consumers */
|
|
64
|
-
keepAlive?: boolean;
|
|
65
148
|
/** Enable debug logging */
|
|
66
149
|
debug?: boolean;
|
|
67
150
|
/** Custom instance identifier */
|
|
68
151
|
instanceId?: string;
|
|
69
|
-
/** Whether this instance should be isolated (not shared) */
|
|
70
|
-
isolated?: boolean;
|
|
71
152
|
}
|
|
72
153
|
/**
|
|
73
154
|
* Listener function for state changes
|
|
@@ -77,7 +158,7 @@ type StateListener<S$1> = (state: S$1) => void;
|
|
|
77
158
|
* Base abstract class for all state containers
|
|
78
159
|
*/
|
|
79
160
|
declare abstract class StateContainer<S$1> {
|
|
80
|
-
|
|
161
|
+
protected static _registry: StateContainerRegistry;
|
|
81
162
|
/**
|
|
82
163
|
* Set a custom registry (mainly for testing)
|
|
83
164
|
*/
|
|
@@ -133,7 +214,6 @@ declare abstract class StateContainer<S$1> {
|
|
|
133
214
|
private _disposed;
|
|
134
215
|
private readonly config;
|
|
135
216
|
readonly name: string;
|
|
136
|
-
readonly keepAlive: boolean;
|
|
137
217
|
readonly debug: boolean;
|
|
138
218
|
readonly instanceId: string;
|
|
139
219
|
/**
|
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",
|