@blac/core 2.0.4 → 2.0.6
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/README.md +98 -126
- package/dist/StateContainerRegistry-Brmferpf.js +588 -0
- package/dist/StateContainerRegistry-Brmferpf.js.map +1 -0
- package/dist/StateContainerRegistry-CVPTMaHn.cjs +629 -0
- package/dist/StateContainerRegistry-CVPTMaHn.cjs.map +1 -0
- package/dist/branded-DndTHjv2.cjs +18 -0
- package/dist/branded-DndTHjv2.cjs.map +1 -0
- package/dist/branded-mwGzzPF1.js +13 -0
- package/dist/branded-mwGzzPF1.js.map +1 -0
- package/dist/config-BInS_9WT.cjs +101 -0
- package/dist/config-BInS_9WT.cjs.map +1 -0
- package/dist/config-BmFnPVM0.js +42 -0
- package/dist/config-BmFnPVM0.js.map +1 -0
- package/dist/constants.d.cts +81 -0
- package/dist/constants.d.ts +81 -0
- package/dist/core/Cubit.d.ts +24 -0
- package/dist/core/StateContainer.d.ts +177 -0
- package/dist/core/StateContainerRegistry.d.ts +189 -0
- package/dist/debug.cjs +11 -26
- package/dist/debug.d.cts +35 -0
- package/dist/debug.d.ts +35 -0
- package/dist/debug.js +2 -18
- package/dist/decorators/blac.d.ts +40 -0
- package/dist/decorators/index.d.ts +1 -0
- package/dist/index.cjs +162 -55
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -794
- package/dist/index.d.ts +17 -794
- package/dist/index.js +145 -31
- package/dist/index.js.map +1 -1
- package/dist/plugin/BlacPlugin.d.ts +143 -0
- package/dist/plugin/PluginManager.d.ts +81 -0
- package/dist/plugins.cjs +3 -3
- package/dist/plugins.d.cts +25 -0
- package/dist/plugins.d.ts +25 -0
- package/dist/plugins.js +2 -3
- package/dist/registry/acquire.d.ts +2 -0
- package/dist/registry/borrow.d.ts +9 -0
- package/dist/registry/config.d.ts +8 -0
- package/dist/registry/ensure.d.ts +2 -0
- package/dist/registry/index.d.ts +7 -0
- package/dist/registry/management.d.ts +4 -0
- package/dist/registry/queries.d.ts +5 -0
- package/dist/registry/release.d.ts +2 -0
- package/dist/resolve-dependencies-B22YjFGk.cjs +773 -0
- package/dist/resolve-dependencies-B22YjFGk.cjs.map +1 -0
- package/dist/resolve-dependencies-Cvq0glJF.js +648 -0
- package/dist/resolve-dependencies-Cvq0glJF.js.map +1 -0
- package/dist/tracked-B_MUXIpe.cjs +216 -0
- package/dist/tracked-B_MUXIpe.cjs.map +1 -0
- package/dist/tracked-I_q9buYg.js +181 -0
- package/dist/tracked-I_q9buYg.js.map +1 -0
- package/dist/tracking.cjs +3 -3
- package/dist/tracking.js +2 -3
- package/dist/types/branded.d.ts +26 -0
- package/dist/types/utilities.d.ts +51 -0
- package/dist/types.cjs +3 -14
- package/dist/types.js +1 -12
- package/dist/utils/idGenerator.d.ts +73 -0
- package/dist/utils/static-props.d.ts +35 -0
- package/dist/watch/index.d.ts +2 -0
- package/dist/watch/watch.d.ts +50 -0
- package/dist/watch-entry.cjs +7 -109
- package/dist/watch-entry.d.cts +26 -0
- package/dist/watch-entry.d.ts +26 -0
- package/dist/watch-entry.js +1 -104
- package/package.json +29 -51
- package/dist/StateContainerRegistry.cjs.map +0 -1
- package/dist/StateContainerRegistry.js.map +0 -1
- package/dist/debug.cjs.map +0 -1
- package/dist/debug.js.map +0 -1
- package/dist/management.cjs.map +0 -1
- package/dist/management.js.map +0 -1
- package/dist/resolve-dependencies.cjs.map +0 -1
- package/dist/resolve-dependencies.js.map +0 -1
- package/dist/types.cjs.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/watch-entry.cjs.map +0 -1
- package/dist/watch-entry.js.map +0 -1
- package/dist/watch.cjs.map +0 -1
- package/dist/watch.js.map +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,794 +1,17 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
* @example Function syntax (no decorator support needed)
|
|
19
|
-
* ```ts
|
|
20
|
-
* const FormBloc = blac({ isolated: true })(
|
|
21
|
-
* class extends Cubit<FormState> {}
|
|
22
|
-
* );
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
export declare function blac(options: BlacOptions): <T extends new (...args: any[]) => any>(target: T, _context?: ClassDecoratorContext) => T;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Configuration options for the @blac decorator.
|
|
29
|
-
* Only one option can be specified at a time (union type).
|
|
30
|
-
*/
|
|
31
|
-
export declare type BlacOptions =
|
|
32
|
-
/** Mark bloc as isolated (each component gets its own instance) */
|
|
33
|
-
{
|
|
34
|
-
isolated: true;
|
|
35
|
-
}
|
|
36
|
-
/** Mark bloc to never be auto-disposed when ref count reaches 0 */
|
|
37
|
-
| {
|
|
38
|
-
keepAlive: true;
|
|
39
|
-
}
|
|
40
|
-
/** Exclude bloc from DevTools tracking (prevents infinite loops) */
|
|
41
|
-
| {
|
|
42
|
-
excludeFromDevTools: true;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Interface for plugins that extend BlaC functionality
|
|
47
|
-
*/
|
|
48
|
-
export declare interface BlacPlugin {
|
|
49
|
-
/** Unique plugin identifier */
|
|
50
|
-
readonly name: string;
|
|
51
|
-
/** Plugin version identifier */
|
|
52
|
-
readonly version: string;
|
|
53
|
-
/**
|
|
54
|
-
* Called when the plugin is installed (optional)
|
|
55
|
-
*/
|
|
56
|
-
onInstall?(context: PluginContext): void;
|
|
57
|
-
/**
|
|
58
|
-
* Called when the plugin is uninstalled
|
|
59
|
-
*/
|
|
60
|
-
onUninstall?(): void;
|
|
61
|
-
/**
|
|
62
|
-
* Called when a state container instance is created
|
|
63
|
-
*/
|
|
64
|
-
onInstanceCreated?(instance: StateContainer<any>, context: PluginContext): void;
|
|
65
|
-
/**
|
|
66
|
-
* Called when state changes in a container instance
|
|
67
|
-
*/
|
|
68
|
-
onStateChanged?<S extends object = any>(instance: StateContainer<S>, previousState: S, currentState: S, callstack: string | undefined, context: PluginContext): void;
|
|
69
|
-
/**
|
|
70
|
-
* Called when a state container instance is disposed
|
|
71
|
-
*/
|
|
72
|
-
onInstanceDisposed?(instance: StateContainer<any>, context: PluginContext): void;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Plugin interface variant that requires mandatory onInstall hook
|
|
77
|
-
*/
|
|
78
|
-
export declare interface BlacPluginWithInit extends BlacPlugin {
|
|
79
|
-
/**
|
|
80
|
-
* Required initialization hook called when plugin is installed
|
|
81
|
-
*/
|
|
82
|
-
onInstall(context: PluginContext): void;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
declare const BLOC_REF_MARKER: unique symbol;
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Constructor type for StateContainer classes with static registry methods.
|
|
89
|
-
* Used for type-safe hook parameters.
|
|
90
|
-
* @template TBloc - The StateContainer instance type
|
|
91
|
-
*/
|
|
92
|
-
export declare type BlocConstructor<S extends object = any, T extends new (...args: any[]) => StateContainer<S> = new (...args: any[]) => StateContainer<S>> = (new (...args: any[]) => InstanceType<T>) & {
|
|
93
|
-
acquire(instanceKey?: string, ...args: any[]): InstanceType<T>;
|
|
94
|
-
borrow(instanceKey?: string, ...args: any[]): InstanceType<T> | null;
|
|
95
|
-
borrowSafe(instanceKey?: string, ...args: any[]): {
|
|
96
|
-
error: Error;
|
|
97
|
-
instance: null;
|
|
98
|
-
} | {
|
|
99
|
-
error: null;
|
|
100
|
-
instance: InstanceType<T>;
|
|
101
|
-
};
|
|
102
|
-
ensure(instanceKey?: string): InstanceType<T>;
|
|
103
|
-
release(instanceKey?: string): void;
|
|
104
|
-
isolated?: boolean;
|
|
105
|
-
keepAlive?: boolean;
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
declare type BlocInput = StateContainerConstructor | BlocRef<StateContainerConstructor>;
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Extract instance type from an abstract class constructor
|
|
112
|
-
* @template T - The abstract class constructor type
|
|
113
|
-
*/
|
|
114
|
-
export declare type BlocInstanceType<T extends abstract new (...args: any) => any> = T extends abstract new (...args: any) => infer R ? R : any;
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Reference to a specific bloc instance by class and instance ID.
|
|
118
|
-
*/
|
|
119
|
-
export declare interface BlocRef<T extends StateContainerConstructor> {
|
|
120
|
-
[BLOC_REF_MARKER]: true;
|
|
121
|
-
blocClass: T;
|
|
122
|
-
instanceId: string;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export declare function borrow<T extends StateContainerConstructor>(BlocClass: T, instanceKey?: string): InstanceType<T>;
|
|
126
|
-
|
|
127
|
-
export declare function borrowSafe<T extends StateContainerConstructor>(BlocClass: T, instanceKey?: string): {
|
|
128
|
-
error: Error;
|
|
129
|
-
instance: null;
|
|
130
|
-
} | {
|
|
131
|
-
error: null;
|
|
132
|
-
instance: InstanceType<T>;
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
/* Excluded from this release type: capturePaths */
|
|
136
|
-
|
|
137
|
-
export declare function clear<T extends StateContainerConstructor>(BlocClass: T): void;
|
|
138
|
-
|
|
139
|
-
/* Excluded from this release type: clearActiveTracker */
|
|
140
|
-
|
|
141
|
-
export declare function clearAll(): void;
|
|
142
|
-
|
|
143
|
-
/* Excluded from this release type: commitTrackedGetters */
|
|
144
|
-
|
|
145
|
-
/* Excluded from this release type: createBlocProxy */
|
|
146
|
-
|
|
147
|
-
/* Excluded from this release type: createDependencyProxy */
|
|
148
|
-
|
|
149
|
-
/* Excluded from this release type: createDependencyState */
|
|
150
|
-
|
|
151
|
-
/* Excluded from this release type: createGetterState */
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Simple state container with direct state emission.
|
|
155
|
-
* Extends StateContainer with public methods for emitting and updating state.
|
|
156
|
-
*
|
|
157
|
-
* @template S - State type
|
|
158
|
-
*/
|
|
159
|
-
export declare abstract class Cubit<S extends object = any> extends StateContainer<S> {
|
|
160
|
-
constructor(initialState: S);
|
|
161
|
-
/**
|
|
162
|
-
* Replace state with a new value and notify all listeners
|
|
163
|
-
* @param newState - The new state value
|
|
164
|
-
*/
|
|
165
|
-
emit(newState: S): void;
|
|
166
|
-
/**
|
|
167
|
-
* Transform current state using an updater function and emit the new state
|
|
168
|
-
* @param updater - Function that receives current state and returns new state
|
|
169
|
-
*/
|
|
170
|
-
update(updater: (current: S) => S): void;
|
|
171
|
-
/**
|
|
172
|
-
* Merge partial state changes into current state (only for object states)
|
|
173
|
-
*/
|
|
174
|
-
patch: S extends object ? (partial: Partial<S>) => void : never;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Manages subscriptions to state container dependencies.
|
|
179
|
-
* Provides efficient sync mechanism to add/remove subscriptions
|
|
180
|
-
* as dependencies change between callback invocations.
|
|
181
|
-
*/
|
|
182
|
-
export declare class DependencyManager {
|
|
183
|
-
private subscriptions;
|
|
184
|
-
private currentDeps;
|
|
185
|
-
/**
|
|
186
|
-
* Sync subscriptions with a new set of dependencies.
|
|
187
|
-
* Adds subscriptions for new deps, removes subscriptions for stale deps.
|
|
188
|
-
*
|
|
189
|
-
* @param newDeps - The new set of dependencies to subscribe to
|
|
190
|
-
* @param onChange - Callback to invoke when any dependency changes
|
|
191
|
-
* @param exclude - Optional instance to exclude from subscriptions (e.g., primary bloc)
|
|
192
|
-
* @returns true if the dependency set changed, false if unchanged
|
|
193
|
-
*/
|
|
194
|
-
sync(newDeps: Set<StateContainerInstance>, onChange: () => void, exclude?: StateContainerInstance): boolean;
|
|
195
|
-
/**
|
|
196
|
-
* Add a single dependency subscription.
|
|
197
|
-
*/
|
|
198
|
-
add(dep: StateContainerInstance, onChange: () => void): void;
|
|
199
|
-
/**
|
|
200
|
-
* Check if a dependency is currently subscribed.
|
|
201
|
-
*/
|
|
202
|
-
has(dep: StateContainerInstance): boolean;
|
|
203
|
-
/**
|
|
204
|
-
* Get the current set of dependencies.
|
|
205
|
-
*/
|
|
206
|
-
getDependencies(): Set<StateContainerInstance>;
|
|
207
|
-
/**
|
|
208
|
-
* Clean up all active subscriptions.
|
|
209
|
-
*/
|
|
210
|
-
cleanup(): void;
|
|
211
|
-
private areSetsEqual;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
/* Excluded from this release type: DependencyState */
|
|
215
|
-
|
|
216
|
-
export declare function ensure<T extends StateContainerConstructor>(BlocClass: T, instanceKey?: string): InstanceType<T>;
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* Extract constructor argument types from a class
|
|
220
|
-
* @template T - The class type
|
|
221
|
-
*/
|
|
222
|
-
export declare type ExtractConstructorArgs<T> = T extends new (...args: infer P) => any ? P : never[];
|
|
223
|
-
|
|
224
|
-
declare type ExtractInstance<T> = T extends BlocRef<infer C> ? InstanceType<C> : T extends StateContainerConstructor ? InstanceType<T> : never;
|
|
225
|
-
|
|
226
|
-
declare type ExtractInstances<T extends readonly BlocInput[]> = {
|
|
227
|
-
[K in keyof T]: ExtractInstance<T[K]>;
|
|
228
|
-
};
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* Extract the state type from a StateContainer
|
|
232
|
-
* @template T - The StateContainer type
|
|
233
|
-
*/
|
|
234
|
-
export declare type ExtractState<T> = T extends StateContainerConstructor<infer S> ? Readonly<S> : never;
|
|
235
|
-
|
|
236
|
-
export declare type ExtractStateMutable<T> = T extends StateContainerConstructor<infer S> ? S : never;
|
|
237
|
-
|
|
238
|
-
export declare function forEach<T extends StateContainerConstructor>(BlocClass: T, callback: (instance: InstanceReadonlyState<T>) => void): void;
|
|
239
|
-
|
|
240
|
-
/**
|
|
241
|
-
* Generate a unique isolated instance key
|
|
242
|
-
* Uses base36 encoding for compact, URL-safe identifiers
|
|
243
|
-
*
|
|
244
|
-
* Format: "isolated-{9-char-random-string}"
|
|
245
|
-
* Example: "isolated-k7x2m9p4q"
|
|
246
|
-
*
|
|
247
|
-
* @returns A unique isolated instance key
|
|
248
|
-
*/
|
|
249
|
-
export declare function generateIsolatedKey(): string;
|
|
250
|
-
|
|
251
|
-
export declare function getAll<T extends StateContainerConstructor>(BlocClass: T): InstanceReadonlyState<T>[];
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* Get the global plugin manager
|
|
255
|
-
*/
|
|
256
|
-
export declare function getPluginManager(): any;
|
|
257
|
-
|
|
258
|
-
export declare function getRefCount<T extends StateContainerConstructor>(BlocClass: T, instanceKey?: string): number;
|
|
259
|
-
|
|
260
|
-
/* Excluded from this release type: GetterState */
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* Global default registry instance
|
|
264
|
-
*/
|
|
265
|
-
export declare const globalRegistry: StateContainerRegistry;
|
|
266
|
-
|
|
267
|
-
/* Excluded from this release type: hasDependencyChanges */
|
|
268
|
-
|
|
269
|
-
/* Excluded from this release type: hasGetterChanges */
|
|
270
|
-
|
|
271
|
-
export declare function hasInstance<T extends StateContainerConstructor>(BlocClass: T, instanceKey?: string): boolean;
|
|
272
|
-
|
|
273
|
-
/* Excluded from this release type: hasTrackedData */
|
|
274
|
-
|
|
275
|
-
/**
|
|
276
|
-
* Create a reference to a specific bloc instance.
|
|
277
|
-
*
|
|
278
|
-
* @example
|
|
279
|
-
* ```ts
|
|
280
|
-
* watch(instance(UserBloc, 'user-123'), (userBloc) => {
|
|
281
|
-
* console.log(userBloc.state.name);
|
|
282
|
-
* });
|
|
283
|
-
* ```
|
|
284
|
-
*/
|
|
285
|
-
export declare function instance<T extends StateContainerConstructor>(BlocClass: T, instanceId: string): BlocRef<T>;
|
|
286
|
-
|
|
287
|
-
/**
|
|
288
|
-
* Entry in the instance registry, tracking the instance and its reference count
|
|
289
|
-
* @template T - Instance type
|
|
290
|
-
*/
|
|
291
|
-
export declare interface InstanceEntry<T = any> {
|
|
292
|
-
/** The state container instance */
|
|
293
|
-
instance: T;
|
|
294
|
-
/** Number of active references to this instance */
|
|
295
|
-
refCount: number;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
/**
|
|
299
|
-
* Metadata information about a state container instance for debugging and inspection
|
|
300
|
-
*/
|
|
301
|
-
export declare interface InstanceMetadata {
|
|
302
|
-
/** Unique instance identifier */
|
|
303
|
-
id: string;
|
|
304
|
-
/** Name of the state container class */
|
|
305
|
-
className: string;
|
|
306
|
-
/** Whether the instance has been disposed */
|
|
307
|
-
isDisposed: boolean;
|
|
308
|
-
/** Display name for the instance */
|
|
309
|
-
name: string;
|
|
310
|
-
/** When state last changed (milliseconds) */
|
|
311
|
-
lastStateChangeTimestamp: number;
|
|
312
|
-
/** Current state value */
|
|
313
|
-
state: any;
|
|
314
|
-
/** Timestamp when instance was created (milliseconds) */
|
|
315
|
-
createdAt: number;
|
|
316
|
-
/** Whether this is an isolated (component-scoped) instance */
|
|
317
|
-
isIsolated: boolean;
|
|
318
|
-
/** Stack trace from when instance was created (for debugging) */
|
|
319
|
-
callstack?: string;
|
|
320
|
-
/** Previous state value */
|
|
321
|
-
previousState?: any;
|
|
322
|
-
/** Current state value */
|
|
323
|
-
currentState?: any;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
export declare type InstanceReadonlyState<T extends StateContainerConstructor = any> = Omit<InstanceType<T>, 'state'> & {
|
|
327
|
-
state: ExtractState<T>;
|
|
328
|
-
};
|
|
329
|
-
|
|
330
|
-
export declare type InstanceState<T extends StateContainerConstructor = any> = Omit<InstanceType<T>, 'state'> & {
|
|
331
|
-
state: ExtractStateMutable<T>;
|
|
332
|
-
};
|
|
333
|
-
|
|
334
|
-
/* Excluded from this release type: invalidateRenderCache */
|
|
335
|
-
|
|
336
|
-
/**
|
|
337
|
-
* Check if a class is marked as isolated.
|
|
338
|
-
* Isolated classes create separate instances per component.
|
|
339
|
-
* @param Type - The class constructor to check
|
|
340
|
-
* @returns true if the class has `static isolated = true`
|
|
341
|
-
*/
|
|
342
|
-
export declare function isIsolatedClass<T extends StateContainerConstructor>(Type: T): boolean;
|
|
343
|
-
|
|
344
|
-
/**
|
|
345
|
-
* Lifecycle events emitted by the registry
|
|
346
|
-
*/
|
|
347
|
-
export declare type LifecycleEvent = 'created' | 'stateChanged' | 'disposed';
|
|
348
|
-
|
|
349
|
-
/**
|
|
350
|
-
* Listener function type for each lifecycle event
|
|
351
|
-
* @template E - The lifecycle event type
|
|
352
|
-
*/
|
|
353
|
-
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 'disposed' ? (container: StateContainer<any>) => void : never;
|
|
354
|
-
|
|
355
|
-
/* Excluded from this release type: PathInfo */
|
|
356
|
-
|
|
357
|
-
/**
|
|
358
|
-
* Configuration options for plugin installation
|
|
359
|
-
*/
|
|
360
|
-
export declare interface PluginConfig {
|
|
361
|
-
/** Enable or disable the plugin */
|
|
362
|
-
enabled?: boolean;
|
|
363
|
-
/** Environments where plugin runs */
|
|
364
|
-
environment?: 'development' | 'production' | 'test' | 'all';
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
/**
|
|
368
|
-
* Safe context API provided to plugins for accessing registry data
|
|
369
|
-
*/
|
|
370
|
-
export declare interface PluginContext {
|
|
371
|
-
/**
|
|
372
|
-
* Get metadata for a specific instance
|
|
373
|
-
*/
|
|
374
|
-
getInstanceMetadata(instance: StateContainer<any>): InstanceMetadata;
|
|
375
|
-
/**
|
|
376
|
-
* Get current state from a container
|
|
377
|
-
*/
|
|
378
|
-
getState<S extends object = any>(instance: StateContainer<S>): S;
|
|
379
|
-
/**
|
|
380
|
-
* Get all instances of a specific type
|
|
381
|
-
*/
|
|
382
|
-
queryInstances<T extends StateContainer<any>>(typeClass: new (...args: any[]) => T): T[];
|
|
383
|
-
/**
|
|
384
|
-
* Get all registered state container types
|
|
385
|
-
*/
|
|
386
|
-
getAllTypes(): Array<new (...args: any[]) => StateContainer<any>>;
|
|
387
|
-
/**
|
|
388
|
-
* Get registry statistics
|
|
389
|
-
*/
|
|
390
|
-
getStats(): {
|
|
391
|
-
registeredTypes: number;
|
|
392
|
-
totalInstances: number;
|
|
393
|
-
typeBreakdown: Record<string, number>;
|
|
394
|
-
};
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
/**
|
|
398
|
-
* Manages plugin lifecycle for the BlaC state management system.
|
|
399
|
-
* Plugins receive notifications about state container lifecycle events.
|
|
400
|
-
*
|
|
401
|
-
* @example
|
|
402
|
-
* ```ts
|
|
403
|
-
* const manager = createPluginManager(registry);
|
|
404
|
-
* manager.install(myPlugin, { environment: 'development' });
|
|
405
|
-
* ```
|
|
406
|
-
*/
|
|
407
|
-
export declare class PluginManager {
|
|
408
|
-
private plugins;
|
|
409
|
-
private registry;
|
|
410
|
-
/**
|
|
411
|
-
* Create a new PluginManager
|
|
412
|
-
* @param registry - The StateContainerRegistry to monitor for lifecycle events
|
|
413
|
-
*/
|
|
414
|
-
constructor(registry: StateContainerRegistry);
|
|
415
|
-
/**
|
|
416
|
-
* Install a plugin with optional configuration
|
|
417
|
-
* @param plugin - The plugin to install
|
|
418
|
-
* @param config - Optional plugin configuration
|
|
419
|
-
* @throws Error if plugin is already installed
|
|
420
|
-
*/
|
|
421
|
-
install(plugin: BlacPlugin, config?: PluginConfig): void;
|
|
422
|
-
/**
|
|
423
|
-
* Uninstall a plugin by name
|
|
424
|
-
* @param pluginName - The name of the plugin to uninstall
|
|
425
|
-
* @throws Error if plugin is not installed
|
|
426
|
-
*/
|
|
427
|
-
uninstall(pluginName: string): void;
|
|
428
|
-
/**
|
|
429
|
-
* Get an installed plugin by name
|
|
430
|
-
* @param pluginName - The name of the plugin to retrieve
|
|
431
|
-
* @returns The plugin instance or undefined if not found
|
|
432
|
-
*/
|
|
433
|
-
getPlugin(pluginName: string): BlacPlugin | undefined;
|
|
434
|
-
/**
|
|
435
|
-
* Get all installed plugins
|
|
436
|
-
* @returns Array of all installed plugins
|
|
437
|
-
*/
|
|
438
|
-
getAllPlugins(): BlacPlugin[];
|
|
439
|
-
/**
|
|
440
|
-
* Check if a plugin is installed
|
|
441
|
-
* @param pluginName - The name of the plugin to check
|
|
442
|
-
* @returns true if the plugin is installed
|
|
443
|
-
*/
|
|
444
|
-
hasPlugin(pluginName: string): boolean;
|
|
445
|
-
/**
|
|
446
|
-
* Uninstall all plugins
|
|
447
|
-
*/
|
|
448
|
-
clear(): void;
|
|
449
|
-
/**
|
|
450
|
-
* Setup lifecycle hooks to notify plugins
|
|
451
|
-
*/
|
|
452
|
-
private setupLifecycleHooks;
|
|
453
|
-
/**
|
|
454
|
-
* Notify all plugins of a lifecycle event
|
|
455
|
-
*/
|
|
456
|
-
private notifyPlugins;
|
|
457
|
-
/**
|
|
458
|
-
* Create plugin context with safe API access
|
|
459
|
-
*/
|
|
460
|
-
private createPluginContext;
|
|
461
|
-
/**
|
|
462
|
-
* Check if plugin should be enabled based on environment
|
|
463
|
-
*/
|
|
464
|
-
private shouldEnablePlugin;
|
|
465
|
-
/**
|
|
466
|
-
* Get current environment
|
|
467
|
-
*/
|
|
468
|
-
private getCurrentEnvironment;
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
/* Excluded from this release type: ProxyState */
|
|
472
|
-
|
|
473
|
-
export declare function release<T extends StateContainerConstructor>(BlocClass: T, instanceKey?: string, forceDispose?: boolean): void;
|
|
474
|
-
|
|
475
|
-
/* Excluded from this release type: resolveDependencies */
|
|
476
|
-
|
|
477
|
-
/* Excluded from this release type: setActiveTracker */
|
|
478
|
-
|
|
479
|
-
/* Excluded from this release type: shallowEqual */
|
|
480
|
-
|
|
481
|
-
/* Excluded from this release type: startDependency */
|
|
482
|
-
|
|
483
|
-
/**
|
|
484
|
-
* Abstract base class for all state containers in BlaC.
|
|
485
|
-
* Provides lifecycle management, subscription handling, ref counting,
|
|
486
|
-
* and integration with the global registry.
|
|
487
|
-
*
|
|
488
|
-
* @template S - State type managed by this container
|
|
489
|
-
*
|
|
490
|
-
* @example
|
|
491
|
-
* ```ts
|
|
492
|
-
* class CounterBloc extends StateContainer<{ count: number }> {
|
|
493
|
-
* constructor() {
|
|
494
|
-
* super({ count: 0 });
|
|
495
|
-
* }
|
|
496
|
-
* increment() {
|
|
497
|
-
* this.emit({ count: this.state.count + 1 });
|
|
498
|
-
* }
|
|
499
|
-
* }
|
|
500
|
-
* ```
|
|
501
|
-
*/
|
|
502
|
-
export declare abstract class StateContainer<S extends object = any> {
|
|
503
|
-
static __excludeFromDevTools: boolean;
|
|
504
|
-
static enableStackTrace: boolean;
|
|
505
|
-
private _state;
|
|
506
|
-
private readonly listeners;
|
|
507
|
-
private _disposed;
|
|
508
|
-
private config;
|
|
509
|
-
private readonly systemEventHandlers;
|
|
510
|
-
/** Display name for this instance */
|
|
511
|
-
name: string;
|
|
512
|
-
/** Whether debug logging is enabled */
|
|
513
|
-
debug: boolean;
|
|
514
|
-
/** Unique identifier for this instance */
|
|
515
|
-
instanceId: string;
|
|
516
|
-
/** Timestamp when this instance was created */
|
|
517
|
-
createdAt: number;
|
|
518
|
-
private _dependencies;
|
|
519
|
-
get dependencies(): ReadonlyMap<StateContainerConstructor, string>;
|
|
520
|
-
protected depend<T extends StateContainerConstructor>(Type: T, instanceKey?: string): () => InstanceType<T>;
|
|
521
|
-
constructor(initialState: S);
|
|
522
|
-
/**
|
|
523
|
-
* Initialize configuration for this instance.
|
|
524
|
-
* Called by the registry after construction.
|
|
525
|
-
* @param config - Configuration options
|
|
526
|
-
*/
|
|
527
|
-
initConfig(config: StateContainerConfig): void;
|
|
528
|
-
/** Current state value */
|
|
529
|
-
get state(): Readonly<S>;
|
|
530
|
-
/** Whether this instance has been disposed */
|
|
531
|
-
get isDisposed(): boolean;
|
|
532
|
-
/**
|
|
533
|
-
* Subscribe to state changes
|
|
534
|
-
* @param listener - Function called when state changes
|
|
535
|
-
* @returns Unsubscribe function
|
|
536
|
-
*/
|
|
537
|
-
subscribe(listener: StateListener<S>): () => void;
|
|
538
|
-
/**
|
|
539
|
-
* Dispose this instance and clean up resources.
|
|
540
|
-
* Clears all listeners and emits the 'dispose' system event.
|
|
541
|
-
*/
|
|
542
|
-
dispose(): void;
|
|
543
|
-
/**
|
|
544
|
-
* Emit a new state value and notify all listeners.
|
|
545
|
-
* @param newState - The new state value
|
|
546
|
-
* @protected
|
|
547
|
-
*/
|
|
548
|
-
protected emit(newState: S): void;
|
|
549
|
-
private captureStackTrace;
|
|
550
|
-
private formatStackLine;
|
|
551
|
-
private cleanFilePath;
|
|
552
|
-
/** Timestamp of the last state update */
|
|
553
|
-
lastUpdateTimestamp: number;
|
|
554
|
-
/**
|
|
555
|
-
* Update state using a transform function.
|
|
556
|
-
* @param updater - Function that receives current state and returns new state
|
|
557
|
-
* @protected
|
|
558
|
-
*/
|
|
559
|
-
protected update(updater: (current: S) => S): void;
|
|
560
|
-
/**
|
|
561
|
-
* Subscribe to system lifecycle events.
|
|
562
|
-
* @param event - The event type to listen for
|
|
563
|
-
* @param handler - Handler function called when event occurs
|
|
564
|
-
* @returns Unsubscribe function
|
|
565
|
-
* @protected
|
|
566
|
-
*/
|
|
567
|
-
protected onSystemEvent: <E extends SystemEvent>(event: E, handler: SystemEventHandler<S, E>) => (() => void);
|
|
568
|
-
private emitSystemEvent;
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
/**
|
|
572
|
-
* Configuration options for initializing a StateContainer instance
|
|
573
|
-
*/
|
|
574
|
-
export declare interface StateContainerConfig {
|
|
575
|
-
/** Display name for the instance (defaults to class name) */
|
|
576
|
-
name?: string;
|
|
577
|
-
/** Enable debug logging for this instance */
|
|
578
|
-
debug?: boolean;
|
|
579
|
-
/** Custom instance identifier */
|
|
580
|
-
instanceId?: string;
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
/**
|
|
584
|
-
* Constructor type for StateContainer classes
|
|
585
|
-
* @template S - State type managed by the container
|
|
586
|
-
*/
|
|
587
|
-
export declare type StateContainerConstructor<S extends object = any> = new (...args: any[]) => StateContainer<S>;
|
|
588
|
-
|
|
589
|
-
export declare type StateContainerInstance<S extends object = any> = Omit<StateContainer<S>, 'state'> & {
|
|
590
|
-
state: Readonly<S>;
|
|
591
|
-
};
|
|
592
|
-
|
|
593
|
-
/**
|
|
594
|
-
* Central registry for managing StateContainer instances.
|
|
595
|
-
* Handles instance lifecycle, ref counting, and lifecycle event emission.
|
|
596
|
-
*
|
|
597
|
-
* @example
|
|
598
|
-
* ```ts
|
|
599
|
-
* const registry = new StateContainerRegistry();
|
|
600
|
-
* const instance = registry.acquire(MyBloc); // ownership, must release
|
|
601
|
-
* const other = registry.ensure(OtherBloc); // no ownership, bloc-to-bloc
|
|
602
|
-
* registry.on('stateChanged', (container, prev, next) => {
|
|
603
|
-
* console.log('State changed:', prev, '->', next);
|
|
604
|
-
* });
|
|
605
|
-
* ```
|
|
606
|
-
*/
|
|
607
|
-
declare class StateContainerRegistry {
|
|
608
|
-
private readonly instancesByConstructor;
|
|
609
|
-
private readonly types;
|
|
610
|
-
private readonly typeConfigs;
|
|
611
|
-
private readonly listeners;
|
|
612
|
-
/**
|
|
613
|
-
* Register a type for lifecycle event tracking
|
|
614
|
-
* @param constructor - The StateContainer class constructor
|
|
615
|
-
*/
|
|
616
|
-
registerType<T extends StateContainerConstructor>(constructor: T): void;
|
|
617
|
-
/**
|
|
618
|
-
* Register a StateContainer class with configuration
|
|
619
|
-
* @param constructor - The StateContainer class constructor
|
|
620
|
-
* @param isolated - Whether instances should be isolated (component-scoped)
|
|
621
|
-
* @throws Error if type is already registered
|
|
622
|
-
*/
|
|
623
|
-
register<T extends StateContainerConstructor>(constructor: T, isolated?: boolean): void;
|
|
624
|
-
private ensureInstancesMap;
|
|
625
|
-
/**
|
|
626
|
-
* Get the instances Map for a specific class (public API for stats/debugging)
|
|
627
|
-
*/
|
|
628
|
-
getInstancesMap<T extends StateContainerConstructor>(Type: T): Map<string, InstanceEntry>;
|
|
629
|
-
/**
|
|
630
|
-
* Acquire an instance with ref counting (ownership semantics).
|
|
631
|
-
* Creates a new instance if one doesn't exist, or returns existing and increments ref count.
|
|
632
|
-
* You must call `release()` when done to decrement the ref count.
|
|
633
|
-
* @param Type - The StateContainer class constructor
|
|
634
|
-
* @param instanceKey - Instance key (defaults to 'default')
|
|
635
|
-
* @param options - Acquisition options
|
|
636
|
-
* @param options.canCreate - Whether to create new instance if not found (default: true)
|
|
637
|
-
* @param options.countRef - Whether to increment ref count (default: true)
|
|
638
|
-
* @returns The state container instance
|
|
639
|
-
*/
|
|
640
|
-
acquire<T extends StateContainerConstructor = StateContainerConstructor>(Type: T, instanceKey?: string, options?: {
|
|
641
|
-
canCreate?: boolean;
|
|
642
|
-
countRef?: boolean;
|
|
643
|
-
}): InstanceType<T>;
|
|
644
|
-
/**
|
|
645
|
-
* Borrow an existing instance without incrementing ref count (borrowing semantics).
|
|
646
|
-
* Tracks cross-bloc dependency for reactive updates.
|
|
647
|
-
* @param Type - The StateContainer class constructor
|
|
648
|
-
* @param instanceKey - Instance key (defaults to 'default')
|
|
649
|
-
* @returns The state container instance
|
|
650
|
-
* @throws Error if instance doesn't exist
|
|
651
|
-
*/
|
|
652
|
-
borrow<T extends StateContainerConstructor = StateContainerConstructor>(Type: T, instanceKey?: string): InstanceType<T>;
|
|
653
|
-
/**
|
|
654
|
-
* Safely borrow an existing instance (borrowing semantics with error handling).
|
|
655
|
-
* Returns discriminated union for type-safe conditional access.
|
|
656
|
-
* @param Type - The StateContainer class constructor
|
|
657
|
-
* @param instanceKey - Instance key (defaults to 'default')
|
|
658
|
-
* @returns Discriminated union with either the instance or an error
|
|
659
|
-
*/
|
|
660
|
-
borrowSafe<T extends StateContainerConstructor = StateContainerConstructor>(Type: T, instanceKey?: string): {
|
|
661
|
-
error: Error;
|
|
662
|
-
instance: null;
|
|
663
|
-
} | {
|
|
664
|
-
error: null;
|
|
665
|
-
instance: InstanceType<T>;
|
|
666
|
-
};
|
|
667
|
-
/**
|
|
668
|
-
* Ensure an instance exists without taking ownership (for bloc-to-bloc communication).
|
|
669
|
-
* Gets existing instance OR creates it if it doesn't exist, without incrementing ref count.
|
|
670
|
-
* Tracks cross-bloc dependency for reactive updates.
|
|
671
|
-
*
|
|
672
|
-
* Use this in bloc-to-bloc communication when you need to ensure an instance exists
|
|
673
|
-
* but don't want to claim ownership (no ref count increment).
|
|
674
|
-
* @param Type - The StateContainer class constructor
|
|
675
|
-
* @param instanceKey - Instance key (defaults to 'default')
|
|
676
|
-
* @returns The state container instance
|
|
677
|
-
*/
|
|
678
|
-
ensure<T extends StateContainerConstructor = StateContainerConstructor>(Type: T, instanceKey?: string): InstanceType<T>;
|
|
679
|
-
/**
|
|
680
|
-
* Release a reference to an instance.
|
|
681
|
-
* Decrements ref count and disposes when it reaches 0 (unless keepAlive).
|
|
682
|
-
* @param Type - The StateContainer class constructor
|
|
683
|
-
* @param instanceKey - Instance key (defaults to 'default')
|
|
684
|
-
* @param forceDispose - Force immediate disposal regardless of ref count
|
|
685
|
-
*/
|
|
686
|
-
release<T extends StateContainerConstructor>(Type: T, instanceKey?: string, forceDispose?: boolean): void;
|
|
687
|
-
/**
|
|
688
|
-
* Get all instances of a specific type.
|
|
689
|
-
* @param Type - The StateContainer class constructor
|
|
690
|
-
* @returns Array of all instances
|
|
691
|
-
*/
|
|
692
|
-
getAll<T extends StateContainerConstructor>(Type: T): InstanceReadonlyState<T>[];
|
|
693
|
-
/**
|
|
694
|
-
* Safely iterate over all instances of a type.
|
|
695
|
-
* Skips disposed instances and catches callback errors.
|
|
696
|
-
* @param Type - The StateContainer class constructor
|
|
697
|
-
* @param callback - Function to call for each instance
|
|
698
|
-
*/
|
|
699
|
-
forEach<T extends StateContainerConstructor>(Type: T, callback: (instance: InstanceReadonlyState<T>) => void): void;
|
|
700
|
-
/**
|
|
701
|
-
* Clear all instances of a specific type (disposes them).
|
|
702
|
-
* @param Type - The StateContainer class constructor
|
|
703
|
-
*/
|
|
704
|
-
clear<T extends StateContainerConstructor>(Type: T): void;
|
|
705
|
-
/**
|
|
706
|
-
* Get reference count for an instance.
|
|
707
|
-
* @param Type - The StateContainer class constructor
|
|
708
|
-
* @param instanceKey - Instance key (defaults to 'default')
|
|
709
|
-
* @returns Current ref count (0 if instance doesn't exist)
|
|
710
|
-
*/
|
|
711
|
-
getRefCount<T extends StateContainerConstructor>(Type: T, instanceKey?: string): number;
|
|
712
|
-
/**
|
|
713
|
-
* Check if an instance exists.
|
|
714
|
-
* @param Type - The StateContainer class constructor
|
|
715
|
-
* @param instanceKey - Instance key (defaults to 'default')
|
|
716
|
-
* @returns true if instance exists
|
|
717
|
-
*/
|
|
718
|
-
hasInstance<T extends StateContainerConstructor>(Type: T, instanceKey?: string): boolean;
|
|
719
|
-
/**
|
|
720
|
-
* Clear all instances from all types (for testing)
|
|
721
|
-
*
|
|
722
|
-
* Iterates all registered types and clears their instances.
|
|
723
|
-
* Also clears type tracking to reset the registry state.
|
|
724
|
-
*/
|
|
725
|
-
clearAll(): void;
|
|
726
|
-
/**
|
|
727
|
-
* Get registry statistics for debugging.
|
|
728
|
-
* @returns Object with registeredTypes, totalInstances, and typeBreakdown
|
|
729
|
-
*/
|
|
730
|
-
getStats(): {
|
|
731
|
-
registeredTypes: number;
|
|
732
|
-
totalInstances: number;
|
|
733
|
-
typeBreakdown: Record<string, number>;
|
|
734
|
-
};
|
|
735
|
-
/**
|
|
736
|
-
* Get all registered types (for plugin system).
|
|
737
|
-
* @returns Array of all registered StateContainer class constructors
|
|
738
|
-
*/
|
|
739
|
-
getTypes(): StateContainerConstructor[];
|
|
740
|
-
/**
|
|
741
|
-
* Subscribe to lifecycle events
|
|
742
|
-
* @param event - The lifecycle event to listen for
|
|
743
|
-
* @param listener - The listener function to call when the event occurs
|
|
744
|
-
* @returns Unsubscribe function
|
|
745
|
-
*/
|
|
746
|
-
on<E extends LifecycleEvent>(event: E, listener: LifecycleListener<E>): () => void;
|
|
747
|
-
/* Excluded from this release type: emit */
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
/* Excluded from this release type: StateListener */
|
|
751
|
-
|
|
752
|
-
declare const STOP: unique symbol;
|
|
753
|
-
|
|
754
|
-
declare type StopSymbol = typeof STOP;
|
|
755
|
-
|
|
756
|
-
/**
|
|
757
|
-
* System events emitted by StateContainer lifecycle
|
|
758
|
-
*/
|
|
759
|
-
export declare type SystemEvent = 'stateChanged' | 'dispose';
|
|
760
|
-
|
|
761
|
-
/* Excluded from this release type: SystemEventHandler */
|
|
762
|
-
|
|
763
|
-
/**
|
|
764
|
-
* Payload types for each system event
|
|
765
|
-
* @template S - State type
|
|
766
|
-
*/
|
|
767
|
-
export declare interface SystemEventPayloads<S> {
|
|
768
|
-
/** Emitted when state changes via emit() or update() */
|
|
769
|
-
stateChanged: {
|
|
770
|
-
state: S;
|
|
771
|
-
previousState: S;
|
|
772
|
-
};
|
|
773
|
-
/** Emitted when the instance is disposed */
|
|
774
|
-
dispose: void;
|
|
775
|
-
}
|
|
776
|
-
|
|
777
|
-
export declare const watch: WatchFn;
|
|
778
|
-
|
|
779
|
-
/**
|
|
780
|
-
* Combined watch function type.
|
|
781
|
-
*/
|
|
782
|
-
export declare interface WatchFn extends WatchSingleFn {
|
|
783
|
-
<T extends readonly BlocInput[]>(blocs: T, callback: (blocs: ExtractInstances<T>) => void | StopSymbol): () => void;
|
|
784
|
-
}
|
|
785
|
-
|
|
786
|
-
/**
|
|
787
|
-
* Watch function signature for single bloc.
|
|
788
|
-
*/
|
|
789
|
-
declare interface WatchSingleFn {
|
|
790
|
-
<T extends StateContainerConstructor>(bloc: T | BlocRef<T>, callback: (bloc: InstanceType<T>) => void | StopSymbol): () => void;
|
|
791
|
-
STOP: StopSymbol;
|
|
792
|
-
}
|
|
793
|
-
|
|
794
|
-
export { }
|
|
1
|
+
export { StateContainer } from './core/StateContainer';
|
|
2
|
+
export type { HydrationStatus, StateContainerConfig, SystemEvent, SystemEventPayloads, } from './core/StateContainer';
|
|
3
|
+
export { Cubit } from './core/Cubit';
|
|
4
|
+
export { acquire, borrow, borrowSafe, ensure, release, clear, clearAll, register, hasInstance, getRefCount, getAll, forEach, getRegistry, setRegistry, getStats, } from './registry';
|
|
5
|
+
export { globalRegistry } from './core/StateContainerRegistry';
|
|
6
|
+
export type { LifecycleEvent, LifecycleListener, InstanceEntry, } from './core/StateContainerRegistry';
|
|
7
|
+
export { blac, type BlacOptions } from './decorators';
|
|
8
|
+
export { getPluginManager } from './core/StateContainerRegistry';
|
|
9
|
+
export type { BlacPlugin, BlacPluginWithInit, PluginContext, PluginConfig, InstanceMetadata, } from './plugin/BlacPlugin';
|
|
10
|
+
export { PluginManager } from './plugin/PluginManager';
|
|
11
|
+
export { watch, instance, type WatchFn, type BlocRef } from './watch';
|
|
12
|
+
export { tracked, createTrackedContext, TrackedContext, type TrackedResult, type TrackedOptions, } from './tracking/tracked';
|
|
13
|
+
export type { StateContainerConstructor, ExtractState, ExtractStateMutable, ExtractConstructorArgs, BlocInstanceType, BlocConstructor, InstanceReadonlyState, InstanceState, StateContainerInstance, } from './types/utilities';
|
|
14
|
+
export type { Brand, BrandedId, InstanceId } from './types/branded';
|
|
15
|
+
export { instanceId } from './types/branded';
|
|
16
|
+
export { isIsolatedClass } from './utils/static-props';
|
|
17
|
+
export { generateIsolatedKey } from './utils/idGenerator';
|