@blac/core 2.0.0-rc.1 → 2.0.0-rc.10
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/adapter/framework-adapter.d.ts +33 -0
- package/dist/adapter/index.d.ts +7 -2
- package/dist/constants.d.ts +82 -0
- package/dist/core/Cubit.d.ts +40 -0
- package/dist/core/StateContainer.d.ts +78 -0
- package/dist/core/StateContainerRegistry.d.ts +119 -0
- package/dist/core/Vertex.d.ts +74 -0
- package/dist/decorators/blac.d.ts +31 -0
- package/dist/decorators/index.d.ts +2 -0
- package/dist/index.cjs +1870 -38
- package/dist/index.d.cts +21 -0
- package/dist/index.d.ts +19 -15
- package/dist/index.js +1789 -37
- package/dist/logging/Logger.d.ts +57 -0
- package/dist/plugin/BlacPlugin.d.ts +46 -0
- package/dist/plugin/PluginManager.d.ts +38 -0
- package/dist/registry/index.d.ts +20 -0
- package/dist/test-utils/index.d.ts +43 -0
- package/dist/tracking/dependency-tracker.d.ts +21 -0
- package/dist/tracking/getter-tracker.d.ts +31 -0
- package/dist/tracking/index.d.ts +38 -0
- package/dist/tracking/path-utils.d.ts +39 -0
- package/dist/tracking/proxy-tracker.d.ts +88 -0
- package/dist/types/branded.d.ts +9 -0
- package/dist/types/events.d.ts +13 -0
- package/dist/types/utilities.d.ts +19 -0
- package/dist/utils/equality.d.ts +9 -0
- package/dist/utils/idGenerator.d.ts +76 -0
- package/dist/utils/immutable.d.ts +16 -0
- package/dist/utils/stack-trace.d.ts +19 -0
- package/dist/utils/static-props.d.ts +29 -0
- package/package.json +31 -13
- package/dist/.tsbuildinfo +0 -1
- package/dist/Blac.d.ts +0 -246
- package/dist/Blac.d.ts.map +0 -1
- package/dist/Blac.js +0 -624
- package/dist/Blac.js.map +0 -1
- package/dist/Bloc.d.ts +0 -41
- package/dist/Bloc.d.ts.map +0 -1
- package/dist/Bloc.js +0 -140
- package/dist/Bloc.js.map +0 -1
- package/dist/BlocBase.d.ts +0 -110
- package/dist/BlocBase.d.ts.map +0 -1
- package/dist/BlocBase.js +0 -287
- package/dist/BlocBase.js.map +0 -1
- package/dist/Cubit.d.ts +0 -25
- package/dist/Cubit.d.ts.map +0 -1
- package/dist/Cubit.js +0 -64
- package/dist/Cubit.js.map +0 -1
- package/dist/adapter/BlacAdapter.d.ts +0 -67
- package/dist/adapter/BlacAdapter.d.ts.map +0 -1
- package/dist/adapter/BlacAdapter.js +0 -263
- package/dist/adapter/BlacAdapter.js.map +0 -1
- package/dist/adapter/ProxyFactory.d.ts +0 -50
- package/dist/adapter/ProxyFactory.d.ts.map +0 -1
- package/dist/adapter/ProxyFactory.js +0 -150
- package/dist/adapter/ProxyFactory.js.map +0 -1
- package/dist/adapter/index.d.ts.map +0 -1
- package/dist/adapter/index.js +0 -19
- package/dist/adapter/index.js.map +0 -1
- package/dist/errors/BlacError.d.ts +0 -38
- package/dist/errors/BlacError.d.ts.map +0 -1
- package/dist/errors/BlacError.js +0 -55
- package/dist/errors/BlacError.js.map +0 -1
- package/dist/errors/ErrorManager.d.ts +0 -39
- package/dist/errors/ErrorManager.d.ts.map +0 -1
- package/dist/errors/ErrorManager.js +0 -91
- package/dist/errors/ErrorManager.js.map +0 -1
- package/dist/errors/handleError.d.ts +0 -24
- package/dist/errors/handleError.d.ts.map +0 -1
- package/dist/errors/handleError.js +0 -62
- package/dist/errors/handleError.js.map +0 -1
- package/dist/errors/index.d.ts +0 -5
- package/dist/errors/index.d.ts.map +0 -1
- package/dist/errors/index.js +0 -13
- package/dist/errors/index.js.map +0 -1
- package/dist/events.d.ts +0 -11
- package/dist/events.d.ts.map +0 -1
- package/dist/events.js +0 -17
- package/dist/events.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lifecycle/BlocLifecycle.d.ts +0 -51
- package/dist/lifecycle/BlocLifecycle.d.ts.map +0 -1
- package/dist/lifecycle/BlocLifecycle.js +0 -123
- package/dist/lifecycle/BlocLifecycle.js.map +0 -1
- package/dist/lifecycle/index.d.ts +0 -2
- package/dist/lifecycle/index.d.ts.map +0 -1
- package/dist/lifecycle/index.js +0 -18
- package/dist/lifecycle/index.js.map +0 -1
- package/dist/plugins/BlocPluginRegistry.d.ts +0 -58
- package/dist/plugins/BlocPluginRegistry.d.ts.map +0 -1
- package/dist/plugins/BlocPluginRegistry.js +0 -201
- package/dist/plugins/BlocPluginRegistry.js.map +0 -1
- package/dist/plugins/SystemPluginRegistry.d.ts +0 -79
- package/dist/plugins/SystemPluginRegistry.d.ts.map +0 -1
- package/dist/plugins/SystemPluginRegistry.js +0 -184
- package/dist/plugins/SystemPluginRegistry.js.map +0 -1
- package/dist/plugins/index.d.ts +0 -4
- package/dist/plugins/index.d.ts.map +0 -1
- package/dist/plugins/index.js +0 -26
- package/dist/plugins/index.js.map +0 -1
- package/dist/plugins/types.d.ts +0 -103
- package/dist/plugins/types.d.ts.map +0 -1
- package/dist/plugins/types.js +0 -3
- package/dist/plugins/types.js.map +0 -1
- package/dist/subscription/SubscriptionManager.d.ts +0 -67
- package/dist/subscription/SubscriptionManager.d.ts.map +0 -1
- package/dist/subscription/SubscriptionManager.js +0 -317
- package/dist/subscription/SubscriptionManager.js.map +0 -1
- package/dist/subscription/index.d.ts +0 -3
- package/dist/subscription/index.d.ts.map +0 -1
- package/dist/subscription/index.js +0 -19
- package/dist/subscription/index.js.map +0 -1
- package/dist/subscription/types.d.ts +0 -65
- package/dist/subscription/types.d.ts.map +0 -1
- package/dist/subscription/types.js +0 -3
- package/dist/subscription/types.js.map +0 -1
- package/dist/testing.d.ts +0 -33
- package/dist/testing.d.ts.map +0 -1
- package/dist/testing.js +0 -68
- package/dist/testing.js.map +0 -1
- package/dist/types.d.ts +0 -57
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -3
- package/dist/types.js.map +0 -1
- package/dist/utils/BatchingManager.d.ts +0 -28
- package/dist/utils/BatchingManager.d.ts.map +0 -1
- package/dist/utils/BatchingManager.js +0 -48
- package/dist/utils/BatchingManager.js.map +0 -1
- package/dist/utils/RerenderLogger.d.ts +0 -60
- package/dist/utils/RerenderLogger.d.ts.map +0 -1
- package/dist/utils/RerenderLogger.js +0 -205
- package/dist/utils/RerenderLogger.js.map +0 -1
- package/dist/utils/generateInstanceId.d.ts +0 -11
- package/dist/utils/generateInstanceId.d.ts.map +0 -1
- package/dist/utils/generateInstanceId.js +0 -50
- package/dist/utils/generateInstanceId.js.map +0 -1
- package/dist/utils/shallowEqual.d.ts +0 -9
- package/dist/utils/shallowEqual.d.ts.map +0 -1
- package/dist/utils/shallowEqual.js +0 -35
- package/dist/utils/shallowEqual.js.map +0 -1
- package/dist/utils/uuid.d.ts +0 -10
- package/dist/utils/uuid.d.ts.map +0 -1
- package/dist/utils/uuid.js +0 -24
- package/dist/utils/uuid.js.map +0 -1
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { StateContainer } from '../core/StateContainer';
|
|
2
|
+
import type { TrackerState, GetterTrackerState } from '../tracking';
|
|
3
|
+
import type { ExtractState } from '../types/utilities';
|
|
4
|
+
export interface AdapterState<TBloc extends StateContainer<any, any>> {
|
|
5
|
+
tracker: TrackerState<ExtractState<TBloc>> | null;
|
|
6
|
+
manualDepsCache: unknown[] | null;
|
|
7
|
+
getterTracker: GetterTrackerState | null;
|
|
8
|
+
proxiedBloc: TBloc | null;
|
|
9
|
+
}
|
|
10
|
+
export interface ManualDepsConfig<TBloc extends StateContainer<any, any>> {
|
|
11
|
+
dependencies: (state: any, bloc: TBloc) => unknown[];
|
|
12
|
+
}
|
|
13
|
+
export type SubscriptionCallback = () => void;
|
|
14
|
+
export type SubscribeFunction = (callback: SubscriptionCallback) => () => void;
|
|
15
|
+
export type SnapshotFunction<TState> = () => TState;
|
|
16
|
+
export declare class ExternalDependencyManager {
|
|
17
|
+
private subscriptions;
|
|
18
|
+
private previousDeps;
|
|
19
|
+
private areDependenciesEqual;
|
|
20
|
+
updateSubscriptions(getterTracker: GetterTrackerState | null, rawInstance: StateContainer<any, any>, onGetterChange: () => void): boolean;
|
|
21
|
+
cleanup(): void;
|
|
22
|
+
}
|
|
23
|
+
export declare function createAutoTrackSubscribe<TBloc extends StateContainer<any, any>>(instance: TBloc, adapterState: AdapterState<TBloc>): SubscribeFunction;
|
|
24
|
+
export declare function createManualDepsSubscribe<TBloc extends StateContainer<any, any>>(instance: TBloc, adapterState: AdapterState<TBloc>, config: ManualDepsConfig<TBloc>): SubscribeFunction;
|
|
25
|
+
export declare function createNoTrackSubscribe<TBloc extends StateContainer<any, any>>(instance: TBloc): SubscribeFunction;
|
|
26
|
+
export declare function createAutoTrackSnapshot<TBloc extends StateContainer<any, any>>(instance: TBloc, adapterState: AdapterState<TBloc>): SnapshotFunction<ExtractState<TBloc>>;
|
|
27
|
+
export declare function createManualDepsSnapshot<TBloc extends StateContainer<any, any>>(instance: TBloc, adapterState: AdapterState<TBloc>, config: ManualDepsConfig<TBloc>): SnapshotFunction<ExtractState<TBloc>>;
|
|
28
|
+
export declare function createNoTrackSnapshot<TBloc extends StateContainer<any, any>>(instance: TBloc): SnapshotFunction<ExtractState<TBloc>>;
|
|
29
|
+
export declare function initAutoTrackState<TBloc extends StateContainer<any, any>>(instance: TBloc): AdapterState<TBloc>;
|
|
30
|
+
export declare function initManualDepsState<TBloc extends StateContainer<any, any>>(instance: TBloc): AdapterState<TBloc>;
|
|
31
|
+
export declare function initNoTrackState<TBloc extends StateContainer<any, any>>(instance: TBloc): AdapterState<TBloc>;
|
|
32
|
+
export declare function disableGetterTracking<TBloc extends StateContainer<any, any>>(adapterState: AdapterState<TBloc>, rawInstance: TBloc): void;
|
|
33
|
+
//# sourceMappingURL=framework-adapter.d.ts.map
|
package/dist/adapter/index.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Framework Adapter
|
|
3
|
+
*
|
|
4
|
+
* Reusable utilities for integrating BlaC with any reactive framework.
|
|
5
|
+
* Use these to build integrations for React, Vue, Solid, Svelte, Angular, etc.
|
|
6
|
+
*/
|
|
7
|
+
export { type AdapterState, type ManualDepsConfig, type SubscriptionCallback, type SubscribeFunction, type SnapshotFunction, ExternalDependencyManager, createAutoTrackSubscribe, createManualDepsSubscribe, createNoTrackSubscribe, createAutoTrackSnapshot, createManualDepsSnapshot, createNoTrackSnapshot, initAutoTrackState, initManualDepsState, initNoTrackState, disableGetterTracking, } from './framework-adapter';
|
|
3
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default configuration constants for BlaC
|
|
3
|
+
*
|
|
4
|
+
* Centralized location for all magic numbers and default values.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Default configuration constants for BlaC
|
|
8
|
+
*/
|
|
9
|
+
export declare const BLAC_DEFAULTS: {
|
|
10
|
+
/**
|
|
11
|
+
* Default instance key for shared instances
|
|
12
|
+
*/
|
|
13
|
+
readonly DEFAULT_INSTANCE_KEY: "default";
|
|
14
|
+
/**
|
|
15
|
+
* Maximum getter nesting depth (prevents infinite recursion)
|
|
16
|
+
*/
|
|
17
|
+
readonly MAX_GETTER_DEPTH: 10;
|
|
18
|
+
/**
|
|
19
|
+
* Default cleanup interval for subscriptions (30 seconds)
|
|
20
|
+
*/
|
|
21
|
+
readonly CLEANUP_INTERVAL_MS: 30000;
|
|
22
|
+
/**
|
|
23
|
+
* Cleanup interval for weak reference stage (10 seconds)
|
|
24
|
+
*/
|
|
25
|
+
readonly WEAKREF_CLEANUP_INTERVAL_MS: 10000;
|
|
26
|
+
/**
|
|
27
|
+
* Default maximum subscriptions per container
|
|
28
|
+
*/
|
|
29
|
+
readonly MAX_SUBSCRIPTIONS: 1000;
|
|
30
|
+
/**
|
|
31
|
+
* Maximum subscriptions for high-performance mode
|
|
32
|
+
*/
|
|
33
|
+
readonly MAX_SUBSCRIPTIONS_HIGH_PERF: 10000;
|
|
34
|
+
/**
|
|
35
|
+
* Default timeout for pipeline execution (5 seconds)
|
|
36
|
+
*/
|
|
37
|
+
readonly PIPELINE_TIMEOUT_MS: 5000;
|
|
38
|
+
/**
|
|
39
|
+
* Cleanup interval for high-performance mode (5 seconds)
|
|
40
|
+
*/
|
|
41
|
+
readonly CLEANUP_INTERVAL_HIGH_PERF_MS: 5000;
|
|
42
|
+
/**
|
|
43
|
+
* Maximum number of stages in a pipeline
|
|
44
|
+
*/
|
|
45
|
+
readonly MAX_PIPELINE_STAGES: 30;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Static property names for StateContainer classes
|
|
49
|
+
* Used for feature flags and configuration on bloc classes
|
|
50
|
+
*/
|
|
51
|
+
export declare const BLAC_STATIC_PROPS: {
|
|
52
|
+
/**
|
|
53
|
+
* Mark a bloc as isolated (each component gets its own instance)
|
|
54
|
+
*/
|
|
55
|
+
readonly ISOLATED: "isolated";
|
|
56
|
+
/**
|
|
57
|
+
* Mark a bloc to never be auto-disposed (kept alive permanently)
|
|
58
|
+
*/
|
|
59
|
+
readonly KEEP_ALIVE: "keepAlive";
|
|
60
|
+
/**
|
|
61
|
+
* Exclude a bloc from DevTools reporting (prevents infinite loops)
|
|
62
|
+
*/
|
|
63
|
+
readonly EXCLUDE_FROM_DEVTOOLS: "__excludeFromDevTools";
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* ID generation patterns and constants
|
|
67
|
+
*/
|
|
68
|
+
export declare const BLAC_ID_PATTERNS: {
|
|
69
|
+
/**
|
|
70
|
+
* Prefix for isolated instance keys
|
|
71
|
+
*/
|
|
72
|
+
readonly ISOLATED_PREFIX: "isolated-";
|
|
73
|
+
/**
|
|
74
|
+
* Length of generated ID portion (9 characters from base36)
|
|
75
|
+
*/
|
|
76
|
+
readonly ID_LENGTH: 9;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Standard error message prefix
|
|
80
|
+
*/
|
|
81
|
+
export declare const BLAC_ERROR_PREFIX: "[BlaC]";
|
|
82
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { StateContainer } from './StateContainer';
|
|
2
|
+
export declare abstract class Cubit<S, P = undefined> extends StateContainer<S, P> {
|
|
3
|
+
constructor(initialState: S);
|
|
4
|
+
emit(newState: S): void;
|
|
5
|
+
update(updater: (current: S) => S): void;
|
|
6
|
+
patch: S extends object ? (partial: Partial<S>) => void : never;
|
|
7
|
+
}
|
|
8
|
+
export declare class CounterCubit extends Cubit<number> {
|
|
9
|
+
constructor();
|
|
10
|
+
increment: () => void;
|
|
11
|
+
decrement: () => void;
|
|
12
|
+
reset: () => void;
|
|
13
|
+
addAmount: (amount: number) => void;
|
|
14
|
+
}
|
|
15
|
+
export interface TodoState {
|
|
16
|
+
todos: Array<{
|
|
17
|
+
id: string;
|
|
18
|
+
text: string;
|
|
19
|
+
done: boolean;
|
|
20
|
+
}>;
|
|
21
|
+
filter: 'all' | 'active' | 'completed';
|
|
22
|
+
isLoading: boolean;
|
|
23
|
+
}
|
|
24
|
+
export declare class TodoCubit extends Cubit<TodoState> {
|
|
25
|
+
static keepAlive: boolean;
|
|
26
|
+
private nextId;
|
|
27
|
+
constructor();
|
|
28
|
+
addTodo: (text: string) => void;
|
|
29
|
+
toggleTodo: (id: string) => void;
|
|
30
|
+
removeTodo: (id: string) => void;
|
|
31
|
+
setFilter: (filter: TodoState["filter"]) => void;
|
|
32
|
+
setLoading: (isLoading: boolean) => void;
|
|
33
|
+
get visibleTodos(): {
|
|
34
|
+
id: string;
|
|
35
|
+
text: string;
|
|
36
|
+
done: boolean;
|
|
37
|
+
}[];
|
|
38
|
+
get activeTodoCount(): number;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=Cubit.d.ts.map
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { StateContainerRegistry } from './StateContainerRegistry';
|
|
2
|
+
export interface StateContainerConfig {
|
|
3
|
+
name?: string;
|
|
4
|
+
debug?: boolean;
|
|
5
|
+
instanceId?: string;
|
|
6
|
+
}
|
|
7
|
+
type StateListener<S> = (state: S) => void;
|
|
8
|
+
export type SystemEvent = 'propsUpdated' | 'stateChanged' | 'dispose';
|
|
9
|
+
export interface SystemEventPayloads<S, P> {
|
|
10
|
+
propsUpdated: {
|
|
11
|
+
props: P;
|
|
12
|
+
previousProps: P | undefined;
|
|
13
|
+
};
|
|
14
|
+
stateChanged: {
|
|
15
|
+
state: S;
|
|
16
|
+
previousState: S;
|
|
17
|
+
};
|
|
18
|
+
dispose: void;
|
|
19
|
+
}
|
|
20
|
+
type SystemEventHandler<S, P, E extends SystemEvent> = (payload: SystemEventPayloads<S, P>[E]) => void;
|
|
21
|
+
export declare abstract class StateContainer<S, P = undefined> {
|
|
22
|
+
static __excludeFromDevTools: boolean;
|
|
23
|
+
protected static _registry: StateContainerRegistry;
|
|
24
|
+
static getRegistry(): StateContainerRegistry;
|
|
25
|
+
static setRegistry(registry: StateContainerRegistry): void;
|
|
26
|
+
static register<T extends StateContainer<any>>(this: new (...args: any[]) => T, isolated?: boolean): void;
|
|
27
|
+
static resolve<T extends StateContainer<any>>(this: new (...args: any[]) => T, instanceKey?: string, constructorArgs?: any): T;
|
|
28
|
+
static get<T extends StateContainer<any>>(this: new (...args: any[]) => T, instanceKey?: string): T;
|
|
29
|
+
static getSafe<T extends StateContainer<any>>(this: new (...args: any[]) => T, instanceKey?: string): {
|
|
30
|
+
error: Error;
|
|
31
|
+
instance: null;
|
|
32
|
+
} | {
|
|
33
|
+
error: null;
|
|
34
|
+
instance: T;
|
|
35
|
+
};
|
|
36
|
+
static connect<T extends StateContainer<any>>(this: new (...args: any[]) => T, instanceKey?: string, constructorArgs?: any): T;
|
|
37
|
+
static release<T extends StateContainer<any>>(this: new (...args: any[]) => T, instanceKey?: string, forceDispose?: boolean): void;
|
|
38
|
+
static getAll<T extends StateContainer<any>>(this: new (...args: any[]) => T): T[];
|
|
39
|
+
static forEach<T extends StateContainer<any>>(this: new (...args: any[]) => T, callback: (instance: T) => void): void;
|
|
40
|
+
static clear<T extends StateContainer<any>>(this: new (...args: any[]) => T): void;
|
|
41
|
+
static clearAllInstances(): void;
|
|
42
|
+
static getStats(): {
|
|
43
|
+
registeredTypes: number;
|
|
44
|
+
totalInstances: number;
|
|
45
|
+
typeBreakdown: Record<string, number>;
|
|
46
|
+
};
|
|
47
|
+
static getRefCount<T extends StateContainer<any>>(this: new (...args: any[]) => T, instanceKey?: string): number;
|
|
48
|
+
static hasInstance<T extends StateContainer<any>>(this: new (...args: any[]) => T, instanceKey?: string): boolean;
|
|
49
|
+
private _state;
|
|
50
|
+
private readonly listeners;
|
|
51
|
+
private _disposed;
|
|
52
|
+
private config;
|
|
53
|
+
private _props;
|
|
54
|
+
private readonly systemEventHandlers;
|
|
55
|
+
name: string;
|
|
56
|
+
debug: boolean;
|
|
57
|
+
instanceId: string;
|
|
58
|
+
createdAt: number;
|
|
59
|
+
get props(): P | undefined;
|
|
60
|
+
constructor(initialState: S);
|
|
61
|
+
initConfig(config: StateContainerConfig): void;
|
|
62
|
+
get state(): S;
|
|
63
|
+
get isDisposed(): boolean;
|
|
64
|
+
subscribe(listener: StateListener<S>): () => void;
|
|
65
|
+
dispose(): void;
|
|
66
|
+
protected emit(newState: S): void;
|
|
67
|
+
static enableStackTrace: boolean;
|
|
68
|
+
private captureStackTrace;
|
|
69
|
+
private formatStackLine;
|
|
70
|
+
private cleanFilePath;
|
|
71
|
+
lastUpdateTimestamp: number;
|
|
72
|
+
protected update(updater: (current: S) => S): void;
|
|
73
|
+
protected onSystemEvent: <E extends SystemEvent>(event: E, handler: SystemEventHandler<S, P, E>) => (() => void);
|
|
74
|
+
private emitSystemEvent;
|
|
75
|
+
updateProps(newProps: P): void;
|
|
76
|
+
}
|
|
77
|
+
export {};
|
|
78
|
+
//# sourceMappingURL=StateContainer.d.ts.map
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import type { StateContainer } from './StateContainer';
|
|
2
|
+
import type { Vertex } from './Vertex';
|
|
3
|
+
export interface InstanceEntry<T = any> {
|
|
4
|
+
instance: T;
|
|
5
|
+
refCount: number;
|
|
6
|
+
}
|
|
7
|
+
export type LifecycleEvent = 'created' | 'stateChanged' | 'eventAdded' | 'disposed';
|
|
8
|
+
export 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;
|
|
9
|
+
export declare class StateContainerRegistry {
|
|
10
|
+
private readonly instancesByConstructor;
|
|
11
|
+
private readonly types;
|
|
12
|
+
private readonly typeConfigs;
|
|
13
|
+
private readonly listeners;
|
|
14
|
+
registerType<T extends StateContainer<any>>(constructor: new (...args: any[]) => T): void;
|
|
15
|
+
register<T extends StateContainer<any>>(constructor: new (...args: any[]) => T, isolated?: boolean): void;
|
|
16
|
+
private ensureInstancesMap;
|
|
17
|
+
/**
|
|
18
|
+
* Get the instances Map for a specific class (public API for stats/debugging)
|
|
19
|
+
*/
|
|
20
|
+
getInstancesMap<T extends StateContainer<any>>(Type: new (...args: any[]) => T): Map<string, InstanceEntry>;
|
|
21
|
+
/**
|
|
22
|
+
* Resolve an instance with ref counting (ownership semantics)
|
|
23
|
+
*/
|
|
24
|
+
resolve<T extends StateContainer<any>>(Type: new (...args: any[]) => T, instanceKey?: string, constructorArgs?: any): T;
|
|
25
|
+
/**
|
|
26
|
+
* Get an existing instance without ref counting (borrowing semantics)
|
|
27
|
+
* @throws Error if instance doesn't exist
|
|
28
|
+
*/
|
|
29
|
+
get<T extends StateContainer<any>>(Type: new (...args: any[]) => T, instanceKey?: string): T;
|
|
30
|
+
/**
|
|
31
|
+
* Safely get an existing instance (borrowing semantics with error handling)
|
|
32
|
+
* Returns discriminated union for type-safe conditional access
|
|
33
|
+
*/
|
|
34
|
+
getSafe<T extends StateContainer<any>>(Type: new (...args: any[]) => T, instanceKey?: string): {
|
|
35
|
+
error: Error;
|
|
36
|
+
instance: null;
|
|
37
|
+
} | {
|
|
38
|
+
error: null;
|
|
39
|
+
instance: T;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Connect to an instance with borrowing semantics (for B2B communication)
|
|
43
|
+
* Gets existing instance OR creates it if it doesn't exist, without incrementing ref count.
|
|
44
|
+
* Tracks cross-bloc dependency for reactive updates.
|
|
45
|
+
*
|
|
46
|
+
* Use this in bloc-to-bloc communication when you need to ensure an instance exists
|
|
47
|
+
* but don't want to claim ownership (no ref count increment).
|
|
48
|
+
*
|
|
49
|
+
* @param Type - The bloc class constructor
|
|
50
|
+
* @param instanceKey - Optional instance key (defaults to 'default')
|
|
51
|
+
* @param constructorArgs - Constructor arguments (only used if creating new instance)
|
|
52
|
+
* @returns The bloc instance
|
|
53
|
+
*/
|
|
54
|
+
connect<T extends StateContainer<any>>(Type: new (...args: any[]) => T, instanceKey?: string, constructorArgs?: any): T;
|
|
55
|
+
/**
|
|
56
|
+
* Release a reference to an instance
|
|
57
|
+
*/
|
|
58
|
+
release<T extends StateContainer<any>>(Type: new (...args: any[]) => T, instanceKey?: string, forceDispose?: boolean): void;
|
|
59
|
+
/**
|
|
60
|
+
* Get all instances of a specific type
|
|
61
|
+
*/
|
|
62
|
+
getAll<T extends StateContainer<any>>(Type: new (...args: any[]) => T): T[];
|
|
63
|
+
/**
|
|
64
|
+
* Safely iterate over all instances of a type
|
|
65
|
+
*/
|
|
66
|
+
forEach<T extends StateContainer<any>>(Type: new (...args: any[]) => T, callback: (instance: T) => void): void;
|
|
67
|
+
/**
|
|
68
|
+
* Clear all instances of a specific type
|
|
69
|
+
*/
|
|
70
|
+
clear<T extends StateContainer<any>>(Type: new (...args: any[]) => T): void;
|
|
71
|
+
/**
|
|
72
|
+
* Get reference count for an instance
|
|
73
|
+
*/
|
|
74
|
+
getRefCount<T extends StateContainer<any>>(Type: new (...args: any[]) => T, instanceKey?: string): number;
|
|
75
|
+
/**
|
|
76
|
+
* Check if an instance exists
|
|
77
|
+
*/
|
|
78
|
+
hasInstance<T extends StateContainer<any>>(Type: new (...args: any[]) => T, instanceKey?: string): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Clear all instances from all types (for testing)
|
|
81
|
+
*
|
|
82
|
+
* Iterates all registered types and clears their instances.
|
|
83
|
+
* Also clears type tracking to reset the registry state.
|
|
84
|
+
*/
|
|
85
|
+
clearAll(): void;
|
|
86
|
+
/**
|
|
87
|
+
* Get registry statistics (for debugging)
|
|
88
|
+
*/
|
|
89
|
+
getStats(): {
|
|
90
|
+
registeredTypes: number;
|
|
91
|
+
totalInstances: number;
|
|
92
|
+
typeBreakdown: Record<string, number>;
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Get all registered types (for plugin system)
|
|
96
|
+
*/
|
|
97
|
+
getTypes(): Array<new (...args: any[]) => StateContainer<any>>;
|
|
98
|
+
/**
|
|
99
|
+
* Subscribe to lifecycle events
|
|
100
|
+
* @param event - The lifecycle event to listen for
|
|
101
|
+
* @param listener - The listener function to call when the event occurs
|
|
102
|
+
* @returns Unsubscribe function
|
|
103
|
+
*/
|
|
104
|
+
on<E extends LifecycleEvent>(event: E, listener: LifecycleListener<E>): () => void;
|
|
105
|
+
/**
|
|
106
|
+
* Emit lifecycle event to all listeners
|
|
107
|
+
* @internal - Called by StateContainer/Vertex lifecycle methods
|
|
108
|
+
*/
|
|
109
|
+
emit(event: LifecycleEvent, ...args: any[]): void;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Global default registry instance
|
|
113
|
+
*/
|
|
114
|
+
export declare const globalRegistry: StateContainerRegistry;
|
|
115
|
+
/**
|
|
116
|
+
* Get the global plugin manager
|
|
117
|
+
*/
|
|
118
|
+
export declare function getPluginManager(): any;
|
|
119
|
+
//# sourceMappingURL=StateContainerRegistry.d.ts.map
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { StateContainer } from './StateContainer';
|
|
2
|
+
import { BaseEvent } from '../types/events';
|
|
3
|
+
export type EventHandler<E extends BaseEvent, S> = (event: E, emit: (state: S) => void) => void;
|
|
4
|
+
export type EventConstructor<T extends BaseEvent = BaseEvent> = new (...args: never[]) => T;
|
|
5
|
+
export declare abstract class Vertex<S, E extends BaseEvent = BaseEvent, P = undefined> extends StateContainer<S, P> {
|
|
6
|
+
private eventHandlers;
|
|
7
|
+
private isProcessing;
|
|
8
|
+
private eventQueue;
|
|
9
|
+
constructor(initialState: S);
|
|
10
|
+
protected on: <T extends E>(EventClass: EventConstructor<T>, handler: EventHandler<T, S>) => void;
|
|
11
|
+
add: (event: E) => void;
|
|
12
|
+
private processEvent;
|
|
13
|
+
private handleEvent;
|
|
14
|
+
protected onEventError(_event: E, _error: Error): void;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Example: Counter Events
|
|
18
|
+
*/
|
|
19
|
+
export declare class IncrementEvent implements BaseEvent {
|
|
20
|
+
readonly amount: number;
|
|
21
|
+
readonly type = "increment";
|
|
22
|
+
readonly timestamp: number;
|
|
23
|
+
constructor(amount?: number);
|
|
24
|
+
}
|
|
25
|
+
export declare class DecrementEvent implements BaseEvent {
|
|
26
|
+
readonly amount: number;
|
|
27
|
+
readonly type = "decrement";
|
|
28
|
+
readonly timestamp: number;
|
|
29
|
+
constructor(amount?: number);
|
|
30
|
+
}
|
|
31
|
+
export declare class ResetEvent implements BaseEvent {
|
|
32
|
+
readonly type = "reset";
|
|
33
|
+
readonly timestamp: number;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Example: Counter Vertex
|
|
37
|
+
* Demonstrates proper typing and event handling
|
|
38
|
+
*/
|
|
39
|
+
export declare class CounterVertex extends Vertex<number> {
|
|
40
|
+
constructor();
|
|
41
|
+
increment: (amount?: number) => void;
|
|
42
|
+
decrement: (amount?: number) => void;
|
|
43
|
+
reset: () => void;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Auth State and Events for testing async handlers
|
|
47
|
+
*/
|
|
48
|
+
export interface AuthState {
|
|
49
|
+
isAuthenticated: boolean;
|
|
50
|
+
isLoading: boolean;
|
|
51
|
+
user: {
|
|
52
|
+
id: string;
|
|
53
|
+
name: string;
|
|
54
|
+
email: string;
|
|
55
|
+
} | null;
|
|
56
|
+
error: string | null;
|
|
57
|
+
}
|
|
58
|
+
export declare class LoginEvent implements BaseEvent {
|
|
59
|
+
readonly email: string;
|
|
60
|
+
readonly password: string;
|
|
61
|
+
readonly type = "login";
|
|
62
|
+
readonly timestamp: number;
|
|
63
|
+
constructor(email: string, password: string);
|
|
64
|
+
}
|
|
65
|
+
export declare class LogoutEvent implements BaseEvent {
|
|
66
|
+
readonly type = "logout";
|
|
67
|
+
readonly timestamp: number;
|
|
68
|
+
}
|
|
69
|
+
export declare class AuthVertex extends Vertex<AuthState> {
|
|
70
|
+
constructor();
|
|
71
|
+
login: (email: string, password: string) => void;
|
|
72
|
+
logout: () => void;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=Vertex.d.ts.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export type BlacOptions = {
|
|
2
|
+
isolated: true;
|
|
3
|
+
} | {
|
|
4
|
+
keepAlive: true;
|
|
5
|
+
} | {
|
|
6
|
+
excludeFromDevTools: true;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Decorator to configure StateContainer classes.
|
|
10
|
+
*
|
|
11
|
+
* @example Decorator syntax (requires experimentalDecorators or TC39 decorators)
|
|
12
|
+
* ```typescript
|
|
13
|
+
* @blac({ isolated: true })
|
|
14
|
+
* class FormBloc extends Cubit<FormState> {}
|
|
15
|
+
*
|
|
16
|
+
* @blac({ keepAlive: true })
|
|
17
|
+
* class AuthBloc extends Cubit<AuthState> {}
|
|
18
|
+
*
|
|
19
|
+
* @blac({ excludeFromDevTools: true })
|
|
20
|
+
* class InternalBloc extends Cubit<InternalState> {}
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @example Function syntax (no decorator support needed)
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const FormBloc = blac({ isolated: true })(
|
|
26
|
+
* class extends Cubit<FormState> {}
|
|
27
|
+
* );
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare function blac(options: BlacOptions): <T extends new (...args: any[]) => any>(target: T, _context?: ClassDecoratorContext) => T;
|
|
31
|
+
//# sourceMappingURL=blac.d.ts.map
|