@blac/core 2.0.0-rc.10 → 2.0.0-rc.11
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 +427 -197
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1298 -21
- package/dist/index.d.ts +1298 -21
- package/dist/index.js +428 -189
- package/dist/index.js.map +1 -0
- package/package.json +10 -6
- package/dist/adapter/framework-adapter.d.ts +0 -33
- package/dist/adapter/index.d.ts +0 -8
- package/dist/constants.d.ts +0 -82
- package/dist/core/Cubit.d.ts +0 -40
- package/dist/core/StateContainer.d.ts +0 -78
- package/dist/core/StateContainerRegistry.d.ts +0 -119
- package/dist/core/Vertex.d.ts +0 -74
- package/dist/decorators/blac.d.ts +0 -31
- package/dist/decorators/index.d.ts +0 -2
- package/dist/logging/Logger.d.ts +0 -57
- package/dist/plugin/BlacPlugin.d.ts +0 -46
- package/dist/plugin/PluginManager.d.ts +0 -38
- package/dist/registry/index.d.ts +0 -20
- package/dist/test-utils/index.d.ts +0 -43
- package/dist/tracking/dependency-tracker.d.ts +0 -21
- package/dist/tracking/getter-tracker.d.ts +0 -31
- package/dist/tracking/index.d.ts +0 -38
- package/dist/tracking/path-utils.d.ts +0 -39
- package/dist/tracking/proxy-tracker.d.ts +0 -88
- package/dist/types/branded.d.ts +0 -9
- package/dist/types/events.d.ts +0 -13
- package/dist/types/utilities.d.ts +0 -19
- package/dist/utils/equality.d.ts +0 -9
- package/dist/utils/idGenerator.d.ts +0 -76
- package/dist/utils/immutable.d.ts +0 -16
- package/dist/utils/stack-trace.d.ts +0 -19
- package/dist/utils/static-props.d.ts +0 -29
package/dist/index.d.ts
CHANGED
|
@@ -1,21 +1,1298 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
/* Excluded from this release type: __resetIdCounters */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Internal state for framework adapters, holding tracking and caching data.
|
|
5
|
+
* @template TBloc - The state container type
|
|
6
|
+
*/
|
|
7
|
+
export declare interface AdapterState<TBloc extends StateContainer<any, any>> {
|
|
8
|
+
/** Proxy tracker for state property access tracking */
|
|
9
|
+
tracker: TrackerState<ExtractState<TBloc>> | null;
|
|
10
|
+
/** Cached manual dependencies for comparison */
|
|
11
|
+
manualDepsCache: unknown[] | null;
|
|
12
|
+
/** Getter tracker for computed property tracking */
|
|
13
|
+
getterTracker: GetterTrackerState | null;
|
|
14
|
+
/** Proxied bloc instance for auto-tracking */
|
|
15
|
+
proxiedBloc: TBloc | null;
|
|
16
|
+
}
|
|
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
|
+
/**
|
|
32
|
+
* Decorator to configure StateContainer classes.
|
|
33
|
+
*
|
|
34
|
+
* @example Decorator syntax (requires experimentalDecorators or TC39 decorators)
|
|
35
|
+
* ```ts
|
|
36
|
+
* @blac({ isolated: true })
|
|
37
|
+
* class FormBloc extends Cubit<FormState> {}
|
|
38
|
+
*
|
|
39
|
+
* @blac({ keepAlive: true })
|
|
40
|
+
* class AuthBloc extends Cubit<AuthState> {}
|
|
41
|
+
*
|
|
42
|
+
* @blac({ excludeFromDevTools: true })
|
|
43
|
+
* class InternalBloc extends Cubit<InternalState> {}
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @example Function syntax (no decorator support needed)
|
|
47
|
+
* ```ts
|
|
48
|
+
* const FormBloc = blac({ isolated: true })(
|
|
49
|
+
* class extends Cubit<FormState> {}
|
|
50
|
+
* );
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare function blac(options: BlacOptions): <T extends new (...args: any[]) => any>(target: T, _context?: ClassDecoratorContext) => T;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Default configuration constants for BlaC
|
|
57
|
+
*/
|
|
58
|
+
export declare const BLAC_DEFAULTS: {
|
|
59
|
+
/**
|
|
60
|
+
* Default instance key for shared instances
|
|
61
|
+
*/
|
|
62
|
+
readonly DEFAULT_INSTANCE_KEY: "default";
|
|
63
|
+
/**
|
|
64
|
+
* Maximum getter nesting depth (prevents infinite recursion)
|
|
65
|
+
*/
|
|
66
|
+
readonly MAX_GETTER_DEPTH: 10;
|
|
67
|
+
/**
|
|
68
|
+
* Default cleanup interval for subscriptions (30 seconds)
|
|
69
|
+
*/
|
|
70
|
+
readonly CLEANUP_INTERVAL_MS: 30000;
|
|
71
|
+
/**
|
|
72
|
+
* Cleanup interval for weak reference stage (10 seconds)
|
|
73
|
+
*/
|
|
74
|
+
readonly WEAKREF_CLEANUP_INTERVAL_MS: 10000;
|
|
75
|
+
/**
|
|
76
|
+
* Default maximum subscriptions per container
|
|
77
|
+
*/
|
|
78
|
+
readonly MAX_SUBSCRIPTIONS: 1000;
|
|
79
|
+
/**
|
|
80
|
+
* Maximum subscriptions for high-performance mode
|
|
81
|
+
*/
|
|
82
|
+
readonly MAX_SUBSCRIPTIONS_HIGH_PERF: 10000;
|
|
83
|
+
/**
|
|
84
|
+
* Default timeout for pipeline execution (5 seconds)
|
|
85
|
+
*/
|
|
86
|
+
readonly PIPELINE_TIMEOUT_MS: 5000;
|
|
87
|
+
/**
|
|
88
|
+
* Cleanup interval for high-performance mode (5 seconds)
|
|
89
|
+
*/
|
|
90
|
+
readonly CLEANUP_INTERVAL_HIGH_PERF_MS: 5000;
|
|
91
|
+
/**
|
|
92
|
+
* Maximum number of stages in a pipeline
|
|
93
|
+
*/
|
|
94
|
+
readonly MAX_PIPELINE_STAGES: 30;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Standard error message prefix
|
|
99
|
+
*/
|
|
100
|
+
export declare const BLAC_ERROR_PREFIX: "[BlaC]";
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* ID generation patterns and constants
|
|
104
|
+
*/
|
|
105
|
+
export declare const BLAC_ID_PATTERNS: {
|
|
106
|
+
/**
|
|
107
|
+
* Prefix for isolated instance keys
|
|
108
|
+
*/
|
|
109
|
+
readonly ISOLATED_PREFIX: "isolated-";
|
|
110
|
+
/**
|
|
111
|
+
* Length of generated ID portion (9 characters from base36)
|
|
112
|
+
*/
|
|
113
|
+
readonly ID_LENGTH: 9;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Static property names for StateContainer classes
|
|
118
|
+
* Used for feature flags and configuration on bloc classes
|
|
119
|
+
*/
|
|
120
|
+
export declare const BLAC_STATIC_PROPS: {
|
|
121
|
+
/**
|
|
122
|
+
* Mark a bloc as isolated (each component gets its own instance)
|
|
123
|
+
*/
|
|
124
|
+
readonly ISOLATED: "isolated";
|
|
125
|
+
/**
|
|
126
|
+
* Mark a bloc to never be auto-disposed (kept alive permanently)
|
|
127
|
+
*/
|
|
128
|
+
readonly KEEP_ALIVE: "keepAlive";
|
|
129
|
+
/**
|
|
130
|
+
* Exclude a bloc from DevTools reporting (prevents infinite loops)
|
|
131
|
+
*/
|
|
132
|
+
readonly EXCLUDE_FROM_DEVTOOLS: "__excludeFromDevTools";
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Configuration options for the @blac decorator.
|
|
137
|
+
* Only one option can be specified at a time (union type).
|
|
138
|
+
*/
|
|
139
|
+
export declare type BlacOptions =
|
|
140
|
+
/** Mark bloc as isolated (each component gets its own instance) */
|
|
141
|
+
{
|
|
142
|
+
isolated: true;
|
|
143
|
+
}
|
|
144
|
+
/** Mark bloc to never be auto-disposed when ref count reaches 0 */
|
|
145
|
+
| {
|
|
146
|
+
keepAlive: true;
|
|
147
|
+
}
|
|
148
|
+
/** Exclude bloc from DevTools tracking (prevents infinite loops) */
|
|
149
|
+
| {
|
|
150
|
+
excludeFromDevTools: true;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Interface for plugins that extend BlaC functionality
|
|
155
|
+
*/
|
|
156
|
+
export declare interface BlacPlugin {
|
|
157
|
+
/** Unique plugin identifier */
|
|
158
|
+
readonly name: string;
|
|
159
|
+
/** Plugin version identifier */
|
|
160
|
+
readonly version: string;
|
|
161
|
+
/**
|
|
162
|
+
* Called when the plugin is installed (optional)
|
|
163
|
+
*/
|
|
164
|
+
onInstall?(context: PluginContext): void;
|
|
165
|
+
/**
|
|
166
|
+
* Called when the plugin is uninstalled
|
|
167
|
+
*/
|
|
168
|
+
onUninstall?(): void;
|
|
169
|
+
/**
|
|
170
|
+
* Called when a state container instance is created
|
|
171
|
+
*/
|
|
172
|
+
onInstanceCreated?(instance: StateContainer<any>, context: PluginContext): void;
|
|
173
|
+
/**
|
|
174
|
+
* Called when state changes in a container instance
|
|
175
|
+
*/
|
|
176
|
+
onStateChanged?<S>(instance: StateContainer<S>, previousState: S, currentState: S, callstack: string | undefined, context: PluginContext): void;
|
|
177
|
+
/**
|
|
178
|
+
* Called when an event is added to a Vertex instance
|
|
179
|
+
*/
|
|
180
|
+
onEventAdded?<E extends BaseEvent>(vertex: Vertex<any, E>, event: E, context: PluginContext): void;
|
|
181
|
+
/**
|
|
182
|
+
* Called when a state container instance is disposed
|
|
183
|
+
*/
|
|
184
|
+
onInstanceDisposed?(instance: StateContainer<any>, context: PluginContext): void;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Plugin interface variant that requires mandatory onInstall hook
|
|
189
|
+
*/
|
|
190
|
+
export declare interface BlacPluginWithInit extends BlacPlugin {
|
|
191
|
+
/**
|
|
192
|
+
* Required initialization hook called when plugin is installed
|
|
193
|
+
*/
|
|
194
|
+
onInstall(context: PluginContext): void;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Constructor type for StateContainer classes with static registry methods.
|
|
199
|
+
* Used for type-safe hook parameters.
|
|
200
|
+
* @template TBloc - The StateContainer instance type
|
|
201
|
+
*/
|
|
202
|
+
export declare type BlocConstructor<TBloc extends StateContainer<any, any>> = (new (...args: any[]) => TBloc) & {
|
|
203
|
+
resolve(instanceKey?: string, ...args: any[]): TBloc;
|
|
204
|
+
get(instanceKey?: string): TBloc;
|
|
205
|
+
getSafe(instanceKey?: string): {
|
|
206
|
+
error: Error;
|
|
207
|
+
instance: null;
|
|
208
|
+
} | {
|
|
209
|
+
error: null;
|
|
210
|
+
instance: TBloc;
|
|
211
|
+
};
|
|
212
|
+
release(instanceKey?: string): void;
|
|
213
|
+
isolated?: boolean;
|
|
214
|
+
keepAlive?: boolean;
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Utility type for creating branded/nominal types.
|
|
219
|
+
* Prevents accidental type confusion between similar primitive types.
|
|
220
|
+
* @template T - The base type
|
|
221
|
+
* @template B - The brand identifier
|
|
222
|
+
*/
|
|
223
|
+
export declare type Brand<T, B> = T & {
|
|
224
|
+
[brand]: B;
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
declare const brand: unique symbol;
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Branded string type for type-safe IDs.
|
|
231
|
+
* @template B - The brand identifier
|
|
232
|
+
*/
|
|
233
|
+
export declare type BrandedId<B> = Brand<string, B>;
|
|
234
|
+
|
|
235
|
+
/* Excluded from this release type: captureTrackedPaths */
|
|
236
|
+
|
|
237
|
+
/* Excluded from this release type: clearActiveTracker */
|
|
238
|
+
|
|
239
|
+
/* Excluded from this release type: clearExternalDependencies */
|
|
240
|
+
|
|
241
|
+
/* Excluded from this release type: commitTrackedGetters */
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Configuration function that recreates the default logger
|
|
245
|
+
*
|
|
246
|
+
* @param opts - Partial logger configuration
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
* ```ts
|
|
250
|
+
* configureLogger({ enabled: true, level: LogLevel.DEBUG });
|
|
251
|
+
* ```
|
|
252
|
+
*/
|
|
253
|
+
export declare function configureLogger(opts: Partial<LogConfig>): void;
|
|
254
|
+
|
|
255
|
+
/* Excluded from this release type: createArrayProxy */
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Create a snapshot function for auto-tracking mode.
|
|
259
|
+
* Returns a proxied state that tracks property access.
|
|
260
|
+
* @param instance - The state container instance
|
|
261
|
+
* @param adapterState - The adapter state for tracking
|
|
262
|
+
* @returns Snapshot function for use with useSyncExternalStore
|
|
263
|
+
*/
|
|
264
|
+
export declare function createAutoTrackSnapshot<TBloc extends StateContainer<any, any>>(instance: TBloc, adapterState: AdapterState<TBloc>): SnapshotFunction<ExtractState<TBloc>>;
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Create a subscribe function for auto-tracking mode.
|
|
268
|
+
* Only triggers callback when tracked properties change.
|
|
269
|
+
* @param instance - The state container instance
|
|
270
|
+
* @param adapterState - The adapter state for tracking
|
|
271
|
+
* @returns Subscribe function for use with useSyncExternalStore
|
|
272
|
+
*/
|
|
273
|
+
export declare function createAutoTrackSubscribe<TBloc extends StateContainer<any, any>>(instance: TBloc, adapterState: AdapterState<TBloc>): SubscribeFunction;
|
|
274
|
+
|
|
275
|
+
/* Excluded from this release type: createBlocProxy */
|
|
276
|
+
|
|
277
|
+
/* Excluded from this release type: createGetterTracker */
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Centralized ID Generation
|
|
281
|
+
*
|
|
282
|
+
* Provides consistent, collision-resistant ID generation for all BlaC subsystems.
|
|
283
|
+
* Uses timestamp + counter + random suffix for uniqueness.
|
|
284
|
+
*/
|
|
285
|
+
/**
|
|
286
|
+
* Creates an ID generator with isolated counter state
|
|
287
|
+
*
|
|
288
|
+
* @param prefix - Prefix for generated IDs
|
|
289
|
+
* @returns Object with next(), nextSimple(), and reset() methods
|
|
290
|
+
*
|
|
291
|
+
* @example
|
|
292
|
+
* ```ts
|
|
293
|
+
* const generator = createIdGenerator('sub');
|
|
294
|
+
* const id1 = generator.next(); // "sub:1698765432100_1_a3k9d7f2q"
|
|
295
|
+
* const id2 = generator.next(); // "sub:1698765432101_2_b4n8e9g3r"
|
|
296
|
+
* ```
|
|
297
|
+
*/
|
|
298
|
+
export declare function createIdGenerator(prefix: string): {
|
|
299
|
+
next: () => string;
|
|
300
|
+
nextSimple: () => string;
|
|
301
|
+
reset: () => void;
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Creates a logger instance with given configuration
|
|
306
|
+
*
|
|
307
|
+
* @param config - Logger configuration
|
|
308
|
+
* @returns Logger instance with debug, info, warn, error, and configure methods
|
|
309
|
+
*
|
|
310
|
+
* @example
|
|
311
|
+
* ```ts
|
|
312
|
+
* const logger = createLogger({
|
|
313
|
+
* enabled: true,
|
|
314
|
+
* level: LogLevel.DEBUG,
|
|
315
|
+
* output: (entry) => console.log(JSON.stringify(entry))
|
|
316
|
+
* });
|
|
317
|
+
* logger.debug('MyComponent', 'Rendering', { props: { foo: 'bar' } });
|
|
318
|
+
* ```
|
|
319
|
+
*/
|
|
320
|
+
export declare function createLogger(config: LogConfig): {
|
|
321
|
+
debug: (context: string, message: string, data?: any) => void;
|
|
322
|
+
info: (context: string, message: string, data?: any) => void;
|
|
323
|
+
warn: (context: string, message: string, data?: any) => void;
|
|
324
|
+
error: (context: string, message: string, data?: any) => void;
|
|
325
|
+
configure: (opts: Partial<LogConfig>) => void;
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Create a snapshot function for manual dependency tracking mode.
|
|
330
|
+
* Caches dependencies for comparison on next render.
|
|
331
|
+
* @param instance - The state container instance
|
|
332
|
+
* @param adapterState - The adapter state for caching
|
|
333
|
+
* @param config - Configuration with dependencies function
|
|
334
|
+
* @returns Snapshot function for use with useSyncExternalStore
|
|
335
|
+
*/
|
|
336
|
+
export declare function createManualDepsSnapshot<TBloc extends StateContainer<any, any>>(instance: TBloc, adapterState: AdapterState<TBloc>, config: ManualDepsConfig<TBloc>): SnapshotFunction<ExtractState<TBloc>>;
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Create a subscribe function for manual dependency tracking mode.
|
|
340
|
+
* Only triggers callback when dependencies array changes.
|
|
341
|
+
* @param instance - The state container instance
|
|
342
|
+
* @param adapterState - The adapter state for caching
|
|
343
|
+
* @param config - Configuration with dependencies function
|
|
344
|
+
* @returns Subscribe function for use with useSyncExternalStore
|
|
345
|
+
*/
|
|
346
|
+
export declare function createManualDepsSubscribe<TBloc extends StateContainer<any, any>>(instance: TBloc, adapterState: AdapterState<TBloc>, config: ManualDepsConfig<TBloc>): SubscribeFunction;
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Create a snapshot function for no-tracking mode.
|
|
350
|
+
* Returns the raw state directly.
|
|
351
|
+
* @param instance - The state container instance
|
|
352
|
+
* @returns Snapshot function for use with useSyncExternalStore
|
|
353
|
+
*/
|
|
354
|
+
export declare function createNoTrackSnapshot<TBloc extends StateContainer<any, any>>(instance: TBloc): SnapshotFunction<ExtractState<TBloc>>;
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Create a subscribe function for no-tracking mode.
|
|
358
|
+
* Triggers callback on every state change.
|
|
359
|
+
* @param instance - The state container instance
|
|
360
|
+
* @returns Subscribe function for use with useSyncExternalStore
|
|
361
|
+
*/
|
|
362
|
+
export declare function createNoTrackSubscribe<TBloc extends StateContainer<any, any>>(instance: TBloc): SubscribeFunction;
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Create a plugin manager instance
|
|
366
|
+
*/
|
|
367
|
+
export declare function createPluginManager(registry: StateContainerRegistry): PluginManager;
|
|
368
|
+
|
|
369
|
+
/* Excluded from this release type: createProxy */
|
|
370
|
+
|
|
371
|
+
/* Excluded from this release type: createProxyForTarget */
|
|
372
|
+
|
|
373
|
+
/* Excluded from this release type: createProxyInternal */
|
|
374
|
+
|
|
375
|
+
/* Excluded from this release type: createProxyTrackerState */
|
|
376
|
+
|
|
377
|
+
/* Excluded from this release type: createTrackerState */
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Simple state container with direct state emission.
|
|
381
|
+
* Extends StateContainer with public methods for emitting and updating state.
|
|
382
|
+
*
|
|
383
|
+
* @template S - State type
|
|
384
|
+
* @template P - Props type (optional)
|
|
385
|
+
*/
|
|
386
|
+
export declare abstract class Cubit<S, P = undefined> extends StateContainer<S, P> {
|
|
387
|
+
constructor(initialState: S);
|
|
388
|
+
/**
|
|
389
|
+
* Replace state with a new value and notify all listeners
|
|
390
|
+
* @param newState - The new state value
|
|
391
|
+
*/
|
|
392
|
+
emit(newState: S): void;
|
|
393
|
+
/**
|
|
394
|
+
* Transform current state using an updater function and emit the new state
|
|
395
|
+
* @param updater - Function that receives current state and returns new state
|
|
396
|
+
*/
|
|
397
|
+
update(updater: (current: S) => S): void;
|
|
398
|
+
/**
|
|
399
|
+
* Merge partial state changes into current state (only for object states)
|
|
400
|
+
*/
|
|
401
|
+
patch: S extends object ? (partial: Partial<S>) => void : never;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* Log a debug message (tree-shakeable export)
|
|
406
|
+
* @param context - Context identifier (module or component name)
|
|
407
|
+
* @param message - Log message
|
|
408
|
+
* @param data - Optional structured data
|
|
409
|
+
*/
|
|
410
|
+
export declare const debug: (context: string, message: string, data?: any) => void;
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* Disable getter tracking after render phase completes.
|
|
414
|
+
* Clears the active tracker to prevent tracking outside of render.
|
|
415
|
+
* @param adapterState - The adapter state
|
|
416
|
+
* @param rawInstance - The raw bloc instance
|
|
417
|
+
*/
|
|
418
|
+
export declare function disableGetterTracking<TBloc extends StateContainer<any, any>>(adapterState: AdapterState<TBloc>, rawInstance: TBloc): void;
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Log an error message (tree-shakeable export)
|
|
422
|
+
* @param context - Context identifier (module or component name)
|
|
423
|
+
* @param message - Log message
|
|
424
|
+
* @param data - Optional structured data
|
|
425
|
+
*/
|
|
426
|
+
export declare const error: (context: string, message: string, data?: any) => void;
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* Constructor type for event classes
|
|
430
|
+
* @template T - Event type
|
|
431
|
+
*/
|
|
432
|
+
export declare type EventConstructor<T extends BaseEvent = BaseEvent> = new (...args: never[]) => T;
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* Handler function for processing events in Vertex
|
|
436
|
+
* @template E - Event type
|
|
437
|
+
* @template S - State type
|
|
438
|
+
* @param event - The event being handled
|
|
439
|
+
* @param emit - Function to emit new state
|
|
440
|
+
*/
|
|
441
|
+
export declare type EventHandler<E extends BaseEvent, S> = (event: E, emit: (state: S) => void) => void;
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* Manages subscriptions to external bloc dependencies for getter tracking.
|
|
445
|
+
* When a getter accesses another bloc's state, this manager ensures
|
|
446
|
+
* re-renders occur when those external dependencies change.
|
|
447
|
+
*/
|
|
448
|
+
export declare class ExternalDependencyManager {
|
|
449
|
+
private subscriptions;
|
|
450
|
+
private previousDeps;
|
|
451
|
+
private areDependenciesEqual;
|
|
452
|
+
/**
|
|
453
|
+
* Update subscriptions to external bloc dependencies.
|
|
454
|
+
* Creates subscriptions to blocs accessed via getters.
|
|
455
|
+
* @param getterTracker - The getter tracker state with external dependencies
|
|
456
|
+
* @param rawInstance - The primary bloc instance (excluded from subscriptions)
|
|
457
|
+
* @param onGetterChange - Callback to invoke when external dependency changes
|
|
458
|
+
* @returns true if subscriptions were updated, false if unchanged
|
|
459
|
+
*/
|
|
460
|
+
updateSubscriptions(getterTracker: GetterTrackerState | null, rawInstance: StateContainer<any, any>, onGetterChange: () => void): boolean;
|
|
461
|
+
/**
|
|
462
|
+
* Clean up all active subscriptions
|
|
463
|
+
*/
|
|
464
|
+
cleanup(): void;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* Extract constructor argument types from a class
|
|
469
|
+
* @template T - The class type
|
|
470
|
+
*/
|
|
471
|
+
export declare type ExtractConstructorArgs<T> = T extends new (...args: infer P) => any ? P : never[];
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* Extract the props type from a StateContainer
|
|
475
|
+
* @template T - The StateContainer type
|
|
476
|
+
*/
|
|
477
|
+
export declare type ExtractProps<T> = T extends StateContainer<any, infer P> ? P : undefined;
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* Extract the state type from a StateContainer
|
|
481
|
+
* @template T - The StateContainer type
|
|
482
|
+
*/
|
|
483
|
+
export declare type ExtractState<T> = T extends StateContainer<infer S, any> ? S : never;
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* Generate ID with timestamp, counter, and random suffix (tree-shakeable)
|
|
487
|
+
*
|
|
488
|
+
* Format: `${prefix}:${timestamp}_${counter}_${random}`
|
|
489
|
+
*
|
|
490
|
+
* @param prefix - Prefix for the ID (e.g., 'sub', 'consumer', 'stage')
|
|
491
|
+
* @returns Branded ID string
|
|
492
|
+
*
|
|
493
|
+
* @example
|
|
494
|
+
* const id = generateId('sub');
|
|
495
|
+
* // Returns: "sub:1698765432100_1_a3k9d7f2q"
|
|
496
|
+
*/
|
|
497
|
+
export declare function generateId(prefix: string): string;
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* Generate a unique isolated instance key
|
|
501
|
+
* Uses base36 encoding for compact, URL-safe identifiers
|
|
502
|
+
*
|
|
503
|
+
* Format: "isolated-{9-char-random-string}"
|
|
504
|
+
* Example: "isolated-k7x2m9p4q"
|
|
505
|
+
*
|
|
506
|
+
* @returns A unique isolated instance key
|
|
507
|
+
*/
|
|
508
|
+
export declare function generateIsolatedKey(): string;
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* Generate simple ID with timestamp and random (no counter tracking)
|
|
512
|
+
*
|
|
513
|
+
* Format: `${prefix}:${timestamp}_${random}`
|
|
514
|
+
*
|
|
515
|
+
* @param prefix - Prefix for the ID
|
|
516
|
+
* @returns Branded ID string
|
|
517
|
+
*
|
|
518
|
+
* @example
|
|
519
|
+
* ```ts
|
|
520
|
+
* const id = generateSimpleId('CounterBloc');
|
|
521
|
+
* // Returns: "CounterBloc:1698765432100_a3k9d7f2q"
|
|
522
|
+
* ```
|
|
523
|
+
*/
|
|
524
|
+
export declare function generateSimpleId(prefix: string, affix?: string): string;
|
|
525
|
+
|
|
526
|
+
/* Excluded from this release type: getActiveTracker */
|
|
527
|
+
|
|
528
|
+
/* Excluded from this release type: getDescriptor */
|
|
529
|
+
|
|
530
|
+
/* Excluded from this release type: getGetterExecutionContext */
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* Get the global plugin manager
|
|
534
|
+
*/
|
|
535
|
+
export declare function getPluginManager(): any;
|
|
536
|
+
|
|
537
|
+
/**
|
|
538
|
+
* Utility functions for accessing static properties on StateContainer classes
|
|
539
|
+
*/
|
|
540
|
+
/**
|
|
541
|
+
* Get a static property from a class constructor
|
|
542
|
+
* Type-safe helper that avoids (Type as any) casts
|
|
543
|
+
*
|
|
544
|
+
* @param Type - The class constructor
|
|
545
|
+
* @param propName - The property name to access
|
|
546
|
+
* @param defaultValue - Optional default value if property is undefined
|
|
547
|
+
* @returns The property value or default
|
|
548
|
+
*/
|
|
549
|
+
export declare function getStaticProp<T>(Type: new (...args: any[]) => any, propName: string, defaultValue?: T): T | undefined;
|
|
550
|
+
|
|
551
|
+
declare interface GetterExecutionContext {
|
|
552
|
+
tracker: GetterTrackerState | null;
|
|
553
|
+
currentBloc: StateContainer<any> | null;
|
|
554
|
+
depth: number;
|
|
555
|
+
visitedBlocs: Set<StateContainer<any>>;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
/* Excluded from this release type: GetterTrackerState */
|
|
559
|
+
|
|
560
|
+
/* Excluded from this release type: getValueAtPath */
|
|
561
|
+
|
|
562
|
+
/**
|
|
563
|
+
* Global default registry instance
|
|
564
|
+
*/
|
|
565
|
+
export declare const globalRegistry: StateContainerRegistry;
|
|
566
|
+
|
|
567
|
+
/* Excluded from this release type: hasChanges */
|
|
568
|
+
|
|
569
|
+
/* Excluded from this release type: hasGetterChanges */
|
|
570
|
+
|
|
571
|
+
/**
|
|
572
|
+
* Type guard to check if a plugin has a required onInstall hook
|
|
573
|
+
* @param plugin - The plugin to check
|
|
574
|
+
* @returns true if the plugin implements BlacPluginWithInit
|
|
575
|
+
*/
|
|
576
|
+
export declare function hasInitHook(plugin: BlacPlugin): plugin is BlacPluginWithInit;
|
|
577
|
+
|
|
578
|
+
/* Excluded from this release type: hasTrackedData */
|
|
579
|
+
|
|
580
|
+
/**
|
|
581
|
+
* Log an info message (tree-shakeable export)
|
|
582
|
+
* @param context - Context identifier (module or component name)
|
|
583
|
+
* @param message - Log message
|
|
584
|
+
* @param data - Optional structured data
|
|
585
|
+
*/
|
|
586
|
+
export declare const info: (context: string, message: string, data?: any) => void;
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* Initialize adapter state for auto-tracking mode.
|
|
590
|
+
* Creates getter tracker and proxied bloc instance.
|
|
591
|
+
* @param instance - The state container instance
|
|
592
|
+
* @returns Initialized adapter state
|
|
593
|
+
*/
|
|
594
|
+
export declare function initAutoTrackState<TBloc extends StateContainer<any, any>>(instance: TBloc): AdapterState<TBloc>;
|
|
595
|
+
|
|
596
|
+
/**
|
|
597
|
+
* Initialize adapter state for manual dependency tracking mode.
|
|
598
|
+
* No proxy is created; bloc is used directly.
|
|
599
|
+
* @param instance - The state container instance
|
|
600
|
+
* @returns Initialized adapter state
|
|
601
|
+
*/
|
|
602
|
+
export declare function initManualDepsState<TBloc extends StateContainer<any, any>>(instance: TBloc): AdapterState<TBloc>;
|
|
603
|
+
|
|
604
|
+
/**
|
|
605
|
+
* Initialize adapter state for no-tracking mode.
|
|
606
|
+
* No tracking or proxy is created.
|
|
607
|
+
* @param instance - The state container instance
|
|
608
|
+
* @returns Initialized adapter state
|
|
609
|
+
*/
|
|
610
|
+
export declare function initNoTrackState<TBloc extends StateContainer<any, any>>(instance: TBloc): AdapterState<TBloc>;
|
|
611
|
+
|
|
612
|
+
/**
|
|
613
|
+
* Entry in the instance registry, tracking the instance and its reference count
|
|
614
|
+
* @template T - Instance type
|
|
615
|
+
*/
|
|
616
|
+
export declare interface InstanceEntry<T = any> {
|
|
617
|
+
/** The state container instance */
|
|
618
|
+
instance: T;
|
|
619
|
+
/** Number of active references to this instance */
|
|
620
|
+
refCount: number;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
* Branded string type for state container instance IDs
|
|
625
|
+
*/
|
|
626
|
+
export declare type InstanceId = Brand<string, 'InstanceId'>;
|
|
627
|
+
|
|
628
|
+
/**
|
|
629
|
+
* Metadata information about a state container instance for debugging and inspection
|
|
630
|
+
*/
|
|
631
|
+
export declare interface InstanceMetadata {
|
|
632
|
+
/** Unique instance identifier */
|
|
633
|
+
id: string;
|
|
634
|
+
/** Name of the state container class */
|
|
635
|
+
className: string;
|
|
636
|
+
/** Whether the instance has been disposed */
|
|
637
|
+
isDisposed: boolean;
|
|
638
|
+
/** Display name for the instance */
|
|
639
|
+
name: string;
|
|
640
|
+
/** When state last changed (milliseconds) */
|
|
641
|
+
lastStateChangeTimestamp: number;
|
|
642
|
+
/** Current state value */
|
|
643
|
+
state: any;
|
|
644
|
+
/** Timestamp when instance was created (milliseconds) */
|
|
645
|
+
createdAt: number;
|
|
646
|
+
/** Whether this is an isolated (component-scoped) instance */
|
|
647
|
+
isIsolated: boolean;
|
|
648
|
+
/** Stack trace from when instance was created (for debugging) */
|
|
649
|
+
callstack?: string;
|
|
650
|
+
/** Previous state value */
|
|
651
|
+
previousState?: any;
|
|
652
|
+
/** Current state value */
|
|
653
|
+
currentState?: any;
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
/* Excluded from this release type: invalidateRenderCache */
|
|
657
|
+
|
|
658
|
+
/**
|
|
659
|
+
* Check if a class should be excluded from DevTools
|
|
660
|
+
* Used to prevent infinite loops when DevTools tracks itself
|
|
661
|
+
*/
|
|
662
|
+
export declare function isExcludedFromDevTools(Type: new (...args: any[]) => any): boolean;
|
|
663
|
+
|
|
664
|
+
/* Excluded from this release type: isGetter */
|
|
665
|
+
|
|
666
|
+
/**
|
|
667
|
+
* Check if a class is marked as isolated
|
|
668
|
+
* Isolated classes create separate instances per component
|
|
669
|
+
*/
|
|
670
|
+
export declare function isIsolatedClass(Type: new (...args: any[]) => any): boolean;
|
|
671
|
+
|
|
672
|
+
/**
|
|
673
|
+
* Check if a key is an isolated instance key
|
|
674
|
+
* @param key - The instance key to check
|
|
675
|
+
* @returns true if the key is an isolated instance key
|
|
676
|
+
*/
|
|
677
|
+
export declare function isIsolatedKey(key: string): boolean;
|
|
678
|
+
|
|
679
|
+
/**
|
|
680
|
+
* Check if a class is marked as keepAlive
|
|
681
|
+
* KeepAlive classes are never auto-disposed when ref count reaches 0
|
|
682
|
+
*/
|
|
683
|
+
export declare function isKeepAliveClass(Type: new (...args: any[]) => any): boolean;
|
|
684
|
+
|
|
685
|
+
/* Excluded from this release type: isProxyable */
|
|
686
|
+
|
|
687
|
+
/**
|
|
688
|
+
* Lifecycle events emitted by the registry
|
|
689
|
+
*/
|
|
690
|
+
export declare type LifecycleEvent = 'created' | 'stateChanged' | 'eventAdded' | 'disposed';
|
|
691
|
+
|
|
692
|
+
/**
|
|
693
|
+
* Listener function type for each lifecycle event
|
|
694
|
+
* @template E - The lifecycle event type
|
|
695
|
+
*/
|
|
696
|
+
export declare type LifecycleListener<E extends LifecycleEvent> = E extends 'created' ? (container: StateContainer<any>) => void : E extends 'stateChanged' ? (container: StateContainer<any>, previousState: any, currentState: any, callstack?: string) => void : E extends 'eventAdded' ? (container: Vertex<any, any>, event: any) => void : E extends 'disposed' ? (container: StateContainer<any>) => void : never;
|
|
697
|
+
|
|
698
|
+
/**
|
|
699
|
+
* Configuration for the logger
|
|
700
|
+
*/
|
|
701
|
+
export declare interface LogConfig {
|
|
702
|
+
/** Whether logging is enabled */
|
|
703
|
+
enabled: boolean;
|
|
704
|
+
/** Minimum log level to output */
|
|
705
|
+
level: LogLevel;
|
|
706
|
+
/** Function called to output log entries */
|
|
707
|
+
output: (entry: LogEntry) => void;
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
/**
|
|
711
|
+
* Structure of a log entry passed to output handlers
|
|
712
|
+
*/
|
|
713
|
+
export declare interface LogEntry {
|
|
714
|
+
/** Log level as string (DEBUG, INFO, WARN, ERROR) */
|
|
715
|
+
level: string;
|
|
716
|
+
/** Context identifier (typically component or module name) */
|
|
717
|
+
context: string;
|
|
718
|
+
/** Log message */
|
|
719
|
+
message: string;
|
|
720
|
+
/** Optional structured data */
|
|
721
|
+
data?: any;
|
|
722
|
+
/** Unix timestamp in milliseconds */
|
|
723
|
+
timestamp: number;
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
/**
|
|
727
|
+
* Log severity levels (lower number = higher severity)
|
|
728
|
+
*/
|
|
729
|
+
export declare enum LogLevel {
|
|
730
|
+
/** Critical errors that may cause application failure */
|
|
731
|
+
ERROR = 0,
|
|
732
|
+
/** Warning conditions that should be addressed */
|
|
733
|
+
WARN = 1,
|
|
734
|
+
/** Informational messages about application state */
|
|
735
|
+
INFO = 2,
|
|
736
|
+
/** Detailed debugging information */
|
|
737
|
+
DEBUG = 3
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
/**
|
|
741
|
+
* Configuration for manual dependency tracking mode
|
|
742
|
+
* @template TBloc - The state container type
|
|
743
|
+
*/
|
|
744
|
+
export declare interface ManualDepsConfig<TBloc extends StateContainer<any, any>> {
|
|
745
|
+
/** Function that returns dependency array from state and bloc */
|
|
746
|
+
dependencies: (state: any, bloc: TBloc) => unknown[];
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
/* Excluded from this release type: parsePath */
|
|
750
|
+
|
|
751
|
+
/* Excluded from this release type: PathInfo */
|
|
752
|
+
|
|
753
|
+
/**
|
|
754
|
+
* Configuration options for plugin installation
|
|
755
|
+
*/
|
|
756
|
+
export declare interface PluginConfig {
|
|
757
|
+
/** Enable or disable the plugin */
|
|
758
|
+
enabled?: boolean;
|
|
759
|
+
/** Environments where plugin runs */
|
|
760
|
+
environment?: 'development' | 'production' | 'test' | 'all';
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
/**
|
|
764
|
+
* Safe context API provided to plugins for accessing registry data
|
|
765
|
+
*/
|
|
766
|
+
export declare interface PluginContext {
|
|
767
|
+
/**
|
|
768
|
+
* Get metadata for a specific instance
|
|
769
|
+
*/
|
|
770
|
+
getInstanceMetadata(instance: StateContainer<any>): InstanceMetadata;
|
|
771
|
+
/**
|
|
772
|
+
* Get current state from a container
|
|
773
|
+
*/
|
|
774
|
+
getState<S>(instance: StateContainer<S>): S;
|
|
775
|
+
/**
|
|
776
|
+
* Get all instances of a specific type
|
|
777
|
+
*/
|
|
778
|
+
queryInstances<T extends StateContainer<any>>(typeClass: new (...args: any[]) => T): T[];
|
|
779
|
+
/**
|
|
780
|
+
* Get all registered state container types
|
|
781
|
+
*/
|
|
782
|
+
getAllTypes(): Array<new (...args: any[]) => StateContainer<any>>;
|
|
783
|
+
/**
|
|
784
|
+
* Get registry statistics
|
|
785
|
+
*/
|
|
786
|
+
getStats(): {
|
|
787
|
+
registeredTypes: number;
|
|
788
|
+
totalInstances: number;
|
|
789
|
+
typeBreakdown: Record<string, number>;
|
|
790
|
+
};
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
/**
|
|
794
|
+
* Manages plugin lifecycle for the BlaC state management system.
|
|
795
|
+
* Plugins receive notifications about state container lifecycle events.
|
|
796
|
+
*
|
|
797
|
+
* @example
|
|
798
|
+
* ```ts
|
|
799
|
+
* const manager = createPluginManager(registry);
|
|
800
|
+
* manager.install(myPlugin, { environment: 'development' });
|
|
801
|
+
* ```
|
|
802
|
+
*/
|
|
803
|
+
export declare class PluginManager {
|
|
804
|
+
private plugins;
|
|
805
|
+
private registry;
|
|
806
|
+
/**
|
|
807
|
+
* Create a new PluginManager
|
|
808
|
+
* @param registry - The StateContainerRegistry to monitor for lifecycle events
|
|
809
|
+
*/
|
|
810
|
+
constructor(registry: StateContainerRegistry);
|
|
811
|
+
/**
|
|
812
|
+
* Install a plugin with optional configuration
|
|
813
|
+
* @param plugin - The plugin to install
|
|
814
|
+
* @param config - Optional plugin configuration
|
|
815
|
+
* @throws Error if plugin is already installed
|
|
816
|
+
*/
|
|
817
|
+
install(plugin: BlacPlugin, config?: PluginConfig): void;
|
|
818
|
+
/**
|
|
819
|
+
* Uninstall a plugin by name
|
|
820
|
+
* @param pluginName - The name of the plugin to uninstall
|
|
821
|
+
* @throws Error if plugin is not installed
|
|
822
|
+
*/
|
|
823
|
+
uninstall(pluginName: string): void;
|
|
824
|
+
/**
|
|
825
|
+
* Get an installed plugin by name
|
|
826
|
+
* @param pluginName - The name of the plugin to retrieve
|
|
827
|
+
* @returns The plugin instance or undefined if not found
|
|
828
|
+
*/
|
|
829
|
+
getPlugin(pluginName: string): BlacPlugin | undefined;
|
|
830
|
+
/**
|
|
831
|
+
* Get all installed plugins
|
|
832
|
+
* @returns Array of all installed plugins
|
|
833
|
+
*/
|
|
834
|
+
getAllPlugins(): BlacPlugin[];
|
|
835
|
+
/**
|
|
836
|
+
* Check if a plugin is installed
|
|
837
|
+
* @param pluginName - The name of the plugin to check
|
|
838
|
+
* @returns true if the plugin is installed
|
|
839
|
+
*/
|
|
840
|
+
hasPlugin(pluginName: string): boolean;
|
|
841
|
+
/**
|
|
842
|
+
* Uninstall all plugins
|
|
843
|
+
*/
|
|
844
|
+
clear(): void;
|
|
845
|
+
/**
|
|
846
|
+
* Setup lifecycle hooks to notify plugins
|
|
847
|
+
*/
|
|
848
|
+
private setupLifecycleHooks;
|
|
849
|
+
/**
|
|
850
|
+
* Notify all plugins of a lifecycle event
|
|
851
|
+
*/
|
|
852
|
+
private notifyPlugins;
|
|
853
|
+
/**
|
|
854
|
+
* Create plugin context with safe API access
|
|
855
|
+
*/
|
|
856
|
+
private createPluginContext;
|
|
857
|
+
/**
|
|
858
|
+
* Check if plugin should be enabled based on environment
|
|
859
|
+
*/
|
|
860
|
+
private shouldEnablePlugin;
|
|
861
|
+
/**
|
|
862
|
+
* Get current environment
|
|
863
|
+
*/
|
|
864
|
+
private getCurrentEnvironment;
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
/* Excluded from this release type: ProxyTrackerState */
|
|
868
|
+
|
|
869
|
+
/* Excluded from this release type: resetGetterTracker */
|
|
870
|
+
|
|
871
|
+
/* Excluded from this release type: setActiveTracker */
|
|
872
|
+
|
|
873
|
+
/* Excluded from this release type: shallowEqual */
|
|
874
|
+
|
|
875
|
+
/**
|
|
876
|
+
* Function that returns a snapshot of the current state
|
|
877
|
+
* @template TState - The state type
|
|
878
|
+
*/
|
|
879
|
+
export declare type SnapshotFunction<TState> = () => TState;
|
|
880
|
+
|
|
881
|
+
/* Excluded from this release type: startProxyTracking */
|
|
882
|
+
|
|
883
|
+
/* Excluded from this release type: startTracking */
|
|
884
|
+
|
|
885
|
+
/**
|
|
886
|
+
* Abstract base class for all state containers in BlaC.
|
|
887
|
+
* Provides lifecycle management, subscription handling, ref counting,
|
|
888
|
+
* and integration with the global registry.
|
|
889
|
+
*
|
|
890
|
+
* @template S - State type managed by this container
|
|
891
|
+
* @template P - Props type passed to the container (optional)
|
|
892
|
+
*
|
|
893
|
+
* @example
|
|
894
|
+
* ```ts
|
|
895
|
+
* class CounterBloc extends StateContainer<number> {
|
|
896
|
+
* constructor() {
|
|
897
|
+
* super(0);
|
|
898
|
+
* }
|
|
899
|
+
* increment() {
|
|
900
|
+
* this.emit(this.state + 1);
|
|
901
|
+
* }
|
|
902
|
+
* }
|
|
903
|
+
* ```
|
|
904
|
+
*/
|
|
905
|
+
export declare abstract class StateContainer<S, P = undefined> {
|
|
906
|
+
/* Excluded from this release type: __excludeFromDevTools */
|
|
907
|
+
/* Excluded from this release type: _registry */
|
|
908
|
+
/**
|
|
909
|
+
* Get the global StateContainerRegistry
|
|
910
|
+
* @returns The registry managing all state container instances
|
|
911
|
+
*/
|
|
912
|
+
static getRegistry(): StateContainerRegistry;
|
|
913
|
+
/**
|
|
914
|
+
* Replace the global registry (clears existing instances)
|
|
915
|
+
* @param registry - The new registry to use
|
|
916
|
+
*/
|
|
917
|
+
static setRegistry(registry: StateContainerRegistry): void;
|
|
918
|
+
/**
|
|
919
|
+
* Register this class with the global registry
|
|
920
|
+
* @param isolated - Whether instances should be isolated (component-scoped)
|
|
921
|
+
*/
|
|
922
|
+
static register<T extends StateContainer<any>>(this: new (...args: any[]) => T, isolated?: boolean): void;
|
|
923
|
+
/**
|
|
924
|
+
* Resolve an instance with ref counting (ownership semantics).
|
|
925
|
+
* Creates a new instance if one doesn't exist, or returns existing and increments ref count.
|
|
926
|
+
* @param instanceKey - Optional instance key (defaults to 'default')
|
|
927
|
+
* @param constructorArgs - Arguments to pass to constructor if creating new instance
|
|
928
|
+
* @returns The state container instance
|
|
929
|
+
*/
|
|
930
|
+
static resolve<T extends StateContainer<any>>(this: new (...args: any[]) => T, instanceKey?: string, constructorArgs?: any): T;
|
|
931
|
+
/**
|
|
932
|
+
* Get an existing instance without incrementing ref count (borrowing semantics).
|
|
933
|
+
* @param instanceKey - Optional instance key (defaults to 'default')
|
|
934
|
+
* @returns The state container instance
|
|
935
|
+
* @throws Error if instance doesn't exist
|
|
936
|
+
*/
|
|
937
|
+
static get<T extends StateContainer<any>>(this: new (...args: any[]) => T, instanceKey?: string): T;
|
|
938
|
+
/**
|
|
939
|
+
* Safely get an existing instance with error handling.
|
|
940
|
+
* @param instanceKey - Optional instance key (defaults to 'default')
|
|
941
|
+
* @returns Discriminated union with either the instance or an error
|
|
942
|
+
*/
|
|
943
|
+
static getSafe<T extends StateContainer<any>>(this: new (...args: any[]) => T, instanceKey?: string): {
|
|
944
|
+
error: Error;
|
|
945
|
+
instance: null;
|
|
946
|
+
} | {
|
|
947
|
+
error: null;
|
|
948
|
+
instance: T;
|
|
949
|
+
};
|
|
950
|
+
/**
|
|
951
|
+
* Connect to an instance for bloc-to-bloc communication (borrowing semantics).
|
|
952
|
+
* Gets or creates instance without incrementing ref count.
|
|
953
|
+
* @param instanceKey - Optional instance key (defaults to 'default')
|
|
954
|
+
* @param constructorArgs - Arguments to pass to constructor if creating new instance
|
|
955
|
+
* @returns The state container instance
|
|
956
|
+
*/
|
|
957
|
+
static connect<T extends StateContainer<any>>(this: new (...args: any[]) => T, instanceKey?: string, constructorArgs?: any): T;
|
|
958
|
+
/**
|
|
959
|
+
* Release a reference to an instance.
|
|
960
|
+
* Decrements ref count and disposes when it reaches 0 (unless keepAlive).
|
|
961
|
+
* @param instanceKey - Optional instance key (defaults to 'default')
|
|
962
|
+
* @param forceDispose - Force immediate disposal regardless of ref count
|
|
963
|
+
*/
|
|
964
|
+
static release<T extends StateContainer<any>>(this: new (...args: any[]) => T, instanceKey?: string, forceDispose?: boolean): void;
|
|
965
|
+
/**
|
|
966
|
+
* Get all instances of this class
|
|
967
|
+
* @returns Array of all instances
|
|
968
|
+
*/
|
|
969
|
+
static getAll<T extends StateContainer<any>>(this: new (...args: any[]) => T): T[];
|
|
970
|
+
/**
|
|
971
|
+
* Iterate over all instances of this class
|
|
972
|
+
* @param callback - Function to call for each instance
|
|
973
|
+
*/
|
|
974
|
+
static forEach<T extends StateContainer<any>>(this: new (...args: any[]) => T, callback: (instance: T) => void): void;
|
|
975
|
+
/**
|
|
976
|
+
* Clear all instances of this class (disposes them)
|
|
977
|
+
*/
|
|
978
|
+
static clear<T extends StateContainer<any>>(this: new (...args: any[]) => T): void;
|
|
979
|
+
/**
|
|
980
|
+
* Clear all instances from all registered types
|
|
981
|
+
*/
|
|
982
|
+
static clearAllInstances(): void;
|
|
983
|
+
/**
|
|
984
|
+
* Get registry statistics for debugging
|
|
985
|
+
* @returns Object with registeredTypes, totalInstances, and typeBreakdown
|
|
986
|
+
*/
|
|
987
|
+
static getStats(): {
|
|
988
|
+
registeredTypes: number;
|
|
989
|
+
totalInstances: number;
|
|
990
|
+
typeBreakdown: Record<string, number>;
|
|
991
|
+
};
|
|
992
|
+
/**
|
|
993
|
+
* Get reference count for an instance
|
|
994
|
+
* @param instanceKey - Optional instance key (defaults to 'default')
|
|
995
|
+
* @returns Current ref count (0 if instance doesn't exist)
|
|
996
|
+
*/
|
|
997
|
+
static getRefCount<T extends StateContainer<any>>(this: new (...args: any[]) => T, instanceKey?: string): number;
|
|
998
|
+
/**
|
|
999
|
+
* Check if an instance exists
|
|
1000
|
+
* @param instanceKey - Optional instance key (defaults to 'default')
|
|
1001
|
+
* @returns true if instance exists
|
|
1002
|
+
*/
|
|
1003
|
+
static hasInstance<T extends StateContainer<any>>(this: new (...args: any[]) => T, instanceKey?: string): boolean;
|
|
1004
|
+
private _state;
|
|
1005
|
+
private readonly listeners;
|
|
1006
|
+
private _disposed;
|
|
1007
|
+
private config;
|
|
1008
|
+
private _props;
|
|
1009
|
+
private readonly systemEventHandlers;
|
|
1010
|
+
/** Display name for this instance */
|
|
1011
|
+
name: string;
|
|
1012
|
+
/** Whether debug logging is enabled */
|
|
1013
|
+
debug: boolean;
|
|
1014
|
+
/** Unique identifier for this instance */
|
|
1015
|
+
instanceId: string;
|
|
1016
|
+
/** Timestamp when this instance was created */
|
|
1017
|
+
createdAt: number;
|
|
1018
|
+
/** Current props value passed to this container */
|
|
1019
|
+
get props(): P | undefined;
|
|
1020
|
+
constructor(initialState: S);
|
|
1021
|
+
/**
|
|
1022
|
+
* Initialize configuration for this instance.
|
|
1023
|
+
* Called by the registry after construction.
|
|
1024
|
+
* @param config - Configuration options
|
|
1025
|
+
*/
|
|
1026
|
+
initConfig(config: StateContainerConfig): void;
|
|
1027
|
+
/** Current state value */
|
|
1028
|
+
get state(): S;
|
|
1029
|
+
/** Whether this instance has been disposed */
|
|
1030
|
+
get isDisposed(): boolean;
|
|
1031
|
+
/**
|
|
1032
|
+
* Subscribe to state changes
|
|
1033
|
+
* @param listener - Function called when state changes
|
|
1034
|
+
* @returns Unsubscribe function
|
|
1035
|
+
*/
|
|
1036
|
+
subscribe(listener: StateListener<S>): () => void;
|
|
1037
|
+
/**
|
|
1038
|
+
* Dispose this instance and clean up resources.
|
|
1039
|
+
* Clears all listeners and emits the 'dispose' system event.
|
|
1040
|
+
*/
|
|
1041
|
+
dispose(): void;
|
|
1042
|
+
/**
|
|
1043
|
+
* Emit a new state value and notify all listeners.
|
|
1044
|
+
* @param newState - The new state value
|
|
1045
|
+
* @protected
|
|
1046
|
+
*/
|
|
1047
|
+
protected emit(newState: S): void;
|
|
1048
|
+
/** Whether to capture stack traces on state changes (disabled in production) */
|
|
1049
|
+
static enableStackTrace: boolean;
|
|
1050
|
+
private captureStackTrace;
|
|
1051
|
+
private formatStackLine;
|
|
1052
|
+
private cleanFilePath;
|
|
1053
|
+
/** Timestamp of the last state update */
|
|
1054
|
+
lastUpdateTimestamp: number;
|
|
1055
|
+
/**
|
|
1056
|
+
* Update state using a transform function.
|
|
1057
|
+
* @param updater - Function that receives current state and returns new state
|
|
1058
|
+
* @protected
|
|
1059
|
+
*/
|
|
1060
|
+
protected update(updater: (current: S) => S): void;
|
|
1061
|
+
/**
|
|
1062
|
+
* Subscribe to system lifecycle events.
|
|
1063
|
+
* @param event - The event type to listen for
|
|
1064
|
+
* @param handler - Handler function called when event occurs
|
|
1065
|
+
* @returns Unsubscribe function
|
|
1066
|
+
* @protected
|
|
1067
|
+
*/
|
|
1068
|
+
protected onSystemEvent: <E extends SystemEvent>(event: E, handler: SystemEventHandler<S, P, E>) => (() => void);
|
|
1069
|
+
private emitSystemEvent;
|
|
1070
|
+
/**
|
|
1071
|
+
* Update the props for this container.
|
|
1072
|
+
* Emits the 'propsUpdated' system event.
|
|
1073
|
+
* @param newProps - The new props value
|
|
1074
|
+
*/
|
|
1075
|
+
updateProps(newProps: P): void;
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
/**
|
|
1079
|
+
* Configuration options for initializing a StateContainer instance
|
|
1080
|
+
*/
|
|
1081
|
+
export declare interface StateContainerConfig {
|
|
1082
|
+
/** Display name for the instance (defaults to class name) */
|
|
1083
|
+
name?: string;
|
|
1084
|
+
/** Enable debug logging for this instance */
|
|
1085
|
+
debug?: boolean;
|
|
1086
|
+
/** Custom instance identifier */
|
|
1087
|
+
instanceId?: string;
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
/**
|
|
1091
|
+
* Central registry for managing StateContainer instances.
|
|
1092
|
+
* Handles instance lifecycle, ref counting, and lifecycle event emission.
|
|
1093
|
+
*
|
|
1094
|
+
* @example
|
|
1095
|
+
* ```ts
|
|
1096
|
+
* const registry = new StateContainerRegistry();
|
|
1097
|
+
* const instance = registry.resolve(MyBloc);
|
|
1098
|
+
* registry.on('stateChanged', (container, prev, next) => {
|
|
1099
|
+
* console.log('State changed:', prev, '->', next);
|
|
1100
|
+
* });
|
|
1101
|
+
* ```
|
|
1102
|
+
*/
|
|
1103
|
+
export declare class StateContainerRegistry {
|
|
1104
|
+
private readonly instancesByConstructor;
|
|
1105
|
+
private readonly types;
|
|
1106
|
+
private readonly typeConfigs;
|
|
1107
|
+
private readonly listeners;
|
|
1108
|
+
/**
|
|
1109
|
+
* Register a type for lifecycle event tracking
|
|
1110
|
+
* @param constructor - The StateContainer class constructor
|
|
1111
|
+
*/
|
|
1112
|
+
registerType<T extends StateContainer<any>>(constructor: new (...args: any[]) => T): void;
|
|
1113
|
+
/**
|
|
1114
|
+
* Register a StateContainer class with configuration
|
|
1115
|
+
* @param constructor - The StateContainer class constructor
|
|
1116
|
+
* @param isolated - Whether instances should be isolated (component-scoped)
|
|
1117
|
+
* @throws Error if type is already registered
|
|
1118
|
+
*/
|
|
1119
|
+
register<T extends StateContainer<any>>(constructor: new (...args: any[]) => T, isolated?: boolean): void;
|
|
1120
|
+
private ensureInstancesMap;
|
|
1121
|
+
/**
|
|
1122
|
+
* Get the instances Map for a specific class (public API for stats/debugging)
|
|
1123
|
+
*/
|
|
1124
|
+
getInstancesMap<T extends StateContainer<any>>(Type: new (...args: any[]) => T): Map<string, InstanceEntry>;
|
|
1125
|
+
/**
|
|
1126
|
+
* Resolve an instance with ref counting (ownership semantics)
|
|
1127
|
+
*/
|
|
1128
|
+
resolve<T extends StateContainer<any>>(Type: new (...args: any[]) => T, instanceKey?: string, constructorArgs?: any): T;
|
|
1129
|
+
/**
|
|
1130
|
+
* Get an existing instance without ref counting (borrowing semantics)
|
|
1131
|
+
* @throws Error if instance doesn't exist
|
|
1132
|
+
*/
|
|
1133
|
+
get<T extends StateContainer<any>>(Type: new (...args: any[]) => T, instanceKey?: string): T;
|
|
1134
|
+
/**
|
|
1135
|
+
* Safely get an existing instance (borrowing semantics with error handling)
|
|
1136
|
+
* Returns discriminated union for type-safe conditional access
|
|
1137
|
+
*/
|
|
1138
|
+
getSafe<T extends StateContainer<any>>(Type: new (...args: any[]) => T, instanceKey?: string): {
|
|
1139
|
+
error: Error;
|
|
1140
|
+
instance: null;
|
|
1141
|
+
} | {
|
|
1142
|
+
error: null;
|
|
1143
|
+
instance: T;
|
|
1144
|
+
};
|
|
1145
|
+
/**
|
|
1146
|
+
* Connect to an instance with borrowing semantics (for B2B communication)
|
|
1147
|
+
* Gets existing instance OR creates it if it doesn't exist, without incrementing ref count.
|
|
1148
|
+
* Tracks cross-bloc dependency for reactive updates.
|
|
1149
|
+
*
|
|
1150
|
+
* Use this in bloc-to-bloc communication when you need to ensure an instance exists
|
|
1151
|
+
* but don't want to claim ownership (no ref count increment).
|
|
1152
|
+
*
|
|
1153
|
+
* @param Type - The bloc class constructor
|
|
1154
|
+
* @param instanceKey - Optional instance key (defaults to 'default')
|
|
1155
|
+
* @param constructorArgs - Constructor arguments (only used if creating new instance)
|
|
1156
|
+
* @returns The bloc instance
|
|
1157
|
+
*/
|
|
1158
|
+
connect<T extends StateContainer<any>>(Type: new (...args: any[]) => T, instanceKey?: string, constructorArgs?: any): T;
|
|
1159
|
+
/**
|
|
1160
|
+
* Release a reference to an instance
|
|
1161
|
+
*/
|
|
1162
|
+
release<T extends StateContainer<any>>(Type: new (...args: any[]) => T, instanceKey?: string, forceDispose?: boolean): void;
|
|
1163
|
+
/**
|
|
1164
|
+
* Get all instances of a specific type
|
|
1165
|
+
*/
|
|
1166
|
+
getAll<T extends StateContainer<any>>(Type: new (...args: any[]) => T): T[];
|
|
1167
|
+
/**
|
|
1168
|
+
* Safely iterate over all instances of a type
|
|
1169
|
+
*/
|
|
1170
|
+
forEach<T extends StateContainer<any>>(Type: new (...args: any[]) => T, callback: (instance: T) => void): void;
|
|
1171
|
+
/**
|
|
1172
|
+
* Clear all instances of a specific type
|
|
1173
|
+
*/
|
|
1174
|
+
clear<T extends StateContainer<any>>(Type: new (...args: any[]) => T): void;
|
|
1175
|
+
/**
|
|
1176
|
+
* Get reference count for an instance
|
|
1177
|
+
*/
|
|
1178
|
+
getRefCount<T extends StateContainer<any>>(Type: new (...args: any[]) => T, instanceKey?: string): number;
|
|
1179
|
+
/**
|
|
1180
|
+
* Check if an instance exists
|
|
1181
|
+
*/
|
|
1182
|
+
hasInstance<T extends StateContainer<any>>(Type: new (...args: any[]) => T, instanceKey?: string): boolean;
|
|
1183
|
+
/**
|
|
1184
|
+
* Clear all instances from all types (for testing)
|
|
1185
|
+
*
|
|
1186
|
+
* Iterates all registered types and clears their instances.
|
|
1187
|
+
* Also clears type tracking to reset the registry state.
|
|
1188
|
+
*/
|
|
1189
|
+
clearAll(): void;
|
|
1190
|
+
/**
|
|
1191
|
+
* Get registry statistics (for debugging)
|
|
1192
|
+
*/
|
|
1193
|
+
getStats(): {
|
|
1194
|
+
registeredTypes: number;
|
|
1195
|
+
totalInstances: number;
|
|
1196
|
+
typeBreakdown: Record<string, number>;
|
|
1197
|
+
};
|
|
1198
|
+
/**
|
|
1199
|
+
* Get all registered types (for plugin system)
|
|
1200
|
+
*/
|
|
1201
|
+
getTypes(): Array<new (...args: any[]) => StateContainer<any>>;
|
|
1202
|
+
/**
|
|
1203
|
+
* Subscribe to lifecycle events
|
|
1204
|
+
* @param event - The lifecycle event to listen for
|
|
1205
|
+
* @param listener - The listener function to call when the event occurs
|
|
1206
|
+
* @returns Unsubscribe function
|
|
1207
|
+
*/
|
|
1208
|
+
on<E extends LifecycleEvent>(event: E, listener: LifecycleListener<E>): () => void;
|
|
1209
|
+
/* Excluded from this release type: emit */
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
/* Excluded from this release type: StateListener */
|
|
1213
|
+
|
|
1214
|
+
/* Excluded from this release type: stopProxyTracking */
|
|
1215
|
+
|
|
1216
|
+
/**
|
|
1217
|
+
* Function that subscribes to state changes and returns an unsubscribe function
|
|
1218
|
+
*/
|
|
1219
|
+
export declare type SubscribeFunction = (callback: SubscriptionCallback) => () => void;
|
|
1220
|
+
|
|
1221
|
+
/**
|
|
1222
|
+
* Callback function invoked when subscribed state changes
|
|
1223
|
+
*/
|
|
1224
|
+
export declare type SubscriptionCallback = () => void;
|
|
1225
|
+
|
|
1226
|
+
/**
|
|
1227
|
+
* System events emitted by StateContainer lifecycle
|
|
1228
|
+
*/
|
|
1229
|
+
export declare type SystemEvent = 'propsUpdated' | 'stateChanged' | 'dispose';
|
|
1230
|
+
|
|
1231
|
+
/* Excluded from this release type: SystemEventHandler */
|
|
1232
|
+
|
|
1233
|
+
/**
|
|
1234
|
+
* Payload types for each system event
|
|
1235
|
+
* @template S - State type
|
|
1236
|
+
* @template P - Props type
|
|
1237
|
+
*/
|
|
1238
|
+
export declare interface SystemEventPayloads<S, P> {
|
|
1239
|
+
/** Emitted when props are updated via updateProps() */
|
|
1240
|
+
propsUpdated: {
|
|
1241
|
+
props: P;
|
|
1242
|
+
previousProps: P | undefined;
|
|
1243
|
+
};
|
|
1244
|
+
/** Emitted when state changes via emit() or update() */
|
|
1245
|
+
stateChanged: {
|
|
1246
|
+
state: S;
|
|
1247
|
+
previousState: S;
|
|
1248
|
+
};
|
|
1249
|
+
/** Emitted when the instance is disposed */
|
|
1250
|
+
dispose: void;
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
/* Excluded from this release type: TrackerState */
|
|
1254
|
+
|
|
1255
|
+
/**
|
|
1256
|
+
* Event-driven state container that processes events to update state.
|
|
1257
|
+
* Use with event handlers registered via the on() method.
|
|
1258
|
+
*
|
|
1259
|
+
* @template S - State type
|
|
1260
|
+
* @template E - Event type (extends BaseEvent)
|
|
1261
|
+
* @template P - Props type (optional)
|
|
1262
|
+
*/
|
|
1263
|
+
export declare abstract class Vertex<S, E extends BaseEvent = BaseEvent, P = undefined> extends StateContainer<S, P> {
|
|
1264
|
+
private eventHandlers;
|
|
1265
|
+
private isProcessing;
|
|
1266
|
+
private eventQueue;
|
|
1267
|
+
constructor(initialState: S);
|
|
1268
|
+
/**
|
|
1269
|
+
* Register a handler for a specific event type
|
|
1270
|
+
* @param EventClass - The event class constructor
|
|
1271
|
+
* @param handler - Function to handle events of this type
|
|
1272
|
+
*/
|
|
1273
|
+
protected on: <T extends E>(EventClass: EventConstructor<T>, handler: EventHandler<T, S>) => void;
|
|
1274
|
+
/**
|
|
1275
|
+
* Add an event to the event stream for processing
|
|
1276
|
+
* @param event - The event to process
|
|
1277
|
+
*/
|
|
1278
|
+
add: (event: E) => void;
|
|
1279
|
+
private processEvent;
|
|
1280
|
+
private handleEvent;
|
|
1281
|
+
/**
|
|
1282
|
+
* Handle errors that occur during event processing.
|
|
1283
|
+
* Override this method to implement custom error handling.
|
|
1284
|
+
* @param _event - The event that caused the error
|
|
1285
|
+
* @param _error - The error that occurred
|
|
1286
|
+
*/
|
|
1287
|
+
protected onEventError(_event: E, _error: Error): void;
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
/**
|
|
1291
|
+
* Log a warning message (tree-shakeable export)
|
|
1292
|
+
* @param context - Context identifier (module or component name)
|
|
1293
|
+
* @param message - Log message
|
|
1294
|
+
* @param data - Optional structured data
|
|
1295
|
+
*/
|
|
1296
|
+
export declare const warn: (context: string, message: string, data?: any) => void;
|
|
1297
|
+
|
|
1298
|
+
export { }
|