You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

@blac/react

Package Overview
Dependencies
Maintainers
1
Versions
75
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@blac/react - npm Package Compare versions

Comparing version
2.0.0-rc.5
to
2.0.0-rc.6
+2
-301
dist/index.d.cts

@@ -0,306 +1,7 @@

import { AnyObject, BlocConstructor, ExtractState, StateContainer } from "@blac/core";
import { RefObject } from "react";
//#region ../blac/src/types/events.d.ts
//#region src/types.d.ts
/**
* Base event interface for type-safe event system
*/
/**
* Base event interface
* Used by Vertex for event-driven state management
*/
interface BaseEvent {
readonly type: string;
readonly timestamp: number;
readonly source?: string;
}
//#endregion
//#region ../blac/src/core/Vertex.d.ts
/**
* Event handler signature (synchronous only)
*/
type EventHandler<E$1 extends BaseEvent, S$1> = (event: E$1, emit: (state: S$1) => void) => void;
/**
* Type-safe event constructor
*/
type EventConstructor<T$1 extends BaseEvent = BaseEvent> = new (...args: never[]) => T$1;
/**
* Vertex is an event-driven state container (Bloc pattern)
*
* Includes its own simple event system since events are only needed
* for the Vertex pattern, not for the base StateContainer.
*/
declare abstract class Vertex<S$1, E$1 extends BaseEvent = BaseEvent> extends StateContainer<S$1> {
private eventHandlers;
private isProcessing;
private eventQueue;
/**
* Create a new Vertex
* @param initialState Initial state value
* @param config Configuration options
*/
constructor(initialState: S$1, config?: StateContainerConfig);
/**
* Register an event handler
* Arrow function to maintain correct 'this' binding
*/
protected on: <T extends E$1>(EventClass: EventConstructor<T>, handler: EventHandler<T, S$1>) => void;
/**
* Add an event to be processed
* Arrow function to maintain correct 'this' binding in React
*/
add: (event: E$1) => void;
/**
* Process an event (synchronously)
*/
private processEvent;
/**
* Handle a single event (synchronously)
*/
private handleEvent;
/**
* Hook for handling event processing errors
*/
protected onEventError(event: E$1, error: Error): void;
}
//#endregion
//#region ../blac/src/core/StateContainerRegistry.d.ts
/**
* Lifecycle events that can be observed
*/
type LifecycleEvent = 'created' | 'stateChanged' | 'eventAdded' | 'disposed';
/**
* Listener function types for each lifecycle event
*/
type LifecycleListener<E$1 extends LifecycleEvent> = E$1 extends 'created' ? (container: StateContainer<any>) => void : E$1 extends 'stateChanged' ? (container: StateContainer<any>, previousState: any, currentState: any) => void : E$1 extends 'eventAdded' ? (container: Vertex<any, any>, event: any) => void : E$1 extends 'disposed' ? (container: StateContainer<any>) => void : never;
/**
* Registry for managing StateContainer instances
*/
declare class StateContainerRegistry {
private readonly instances;
private readonly types;
private readonly listeners;
/**
* Register a type with isolation mode
*/
register<T extends StateContainer<any>>(constructor: new (...args: any[]) => T, isolated?: boolean): void;
/**
* Get or create a StateContainer instance
* For isolated: always creates new
* For shared: singleton per key
*/
getOrCreate<T extends StateContainer<any>>(constructor: new (...args: any[]) => T, key?: string, ...args: any[]): T;
/**
* Release a reference to an instance
* Disposes when ref count reaches zero (unless static keepAlive is true)
*/
release<T extends StateContainer<any>>(constructor: new (...args: any[]) => T, key?: string, forceDispose?: boolean): void;
/**
* Get all instances of a type (shared only, isolated aren't tracked)
*/
getAll<T extends StateContainer<any>>(constructor: new (...args: any[]) => T): T[];
/**
* Clear all instances of a type
*/
clear<T extends StateContainer<any>>(constructor: new (...args: any[]) => T): void;
/**
* Clear all instances from all types (for testing)
*/
clearAll(): void;
/**
* Get registry statistics (for debugging)
*/
getStats(): {
registeredTypes: number;
totalInstances: number;
typeBreakdown: Record<string, number>;
};
/**
* Get reference count for an instance
*/
getRefCount<T extends StateContainer<any>>(constructor: new (...args: any[]) => T, key?: string): number;
/**
* Check if an instance exists
*/
hasInstance<T extends StateContainer<any>>(constructor: new (...args: any[]) => T, key?: string): boolean;
/**
* Subscribe to lifecycle events
* @param event - The lifecycle event to listen for
* @param listener - The listener function to call when the event occurs
* @returns Unsubscribe function
*/
on<E extends LifecycleEvent>(event: E, listener: LifecycleListener<E>): () => void;
/**
* Emit lifecycle event to all listeners
* @internal - Called by StateContainer/Vertex lifecycle methods
*/
emit(event: LifecycleEvent, ...args: any[]): void;
}
//#endregion
//#region ../blac/src/core/StateContainer.d.ts
/**
* Configuration options for StateContainer
*/
interface StateContainerConfig {
/** Container name for debugging */
name?: string;
/** Enable debug logging */
debug?: boolean;
/** Custom instance identifier */
instanceId?: string;
}
/**
* Listener function for state changes
*/
type StateListener<S$1> = (state: S$1) => void;
/**
* Base abstract class for all state containers
*/
declare abstract class StateContainer<S$1> {
protected static _registry: StateContainerRegistry;
/**
* Set a custom registry (mainly for testing)
*/
static setRegistry(registry: StateContainerRegistry): void;
/**
* Register a type as isolated or shared
*/
static register<T extends StateContainer<any>>(this: new (...args: any[]) => T, isolated?: boolean): void;
/**
* Get or create an instance
* @param key - Optional instance key for shared instances
* @param args - Constructor arguments
*/
static getOrCreate<T extends StateContainer<any>>(this: new (...args: any[]) => T, key?: string, ...args: any[]): T;
/**
* Release a reference to an instance
* @param key - Optional instance key
* @param forceDispose - Force dispose regardless of ref count or keepAlive
*/
static release<T extends StateContainer<any>>(this: new (...args: any[]) => T, key?: string, forceDispose?: boolean): void;
/**
* Get all instances of this type
*/
static getAll<T extends StateContainer<any>>(this: new (...args: any[]) => T): T[];
/**
* Clear all instances of this type
*/
static clear<T extends StateContainer<any>>(this: new (...args: any[]) => T): void;
/**
* Clear all instances from all types (for testing)
*/
static clearAllInstances(): void;
/**
* Get registry statistics (for debugging)
*/
static getStats(): {
registeredTypes: number;
totalInstances: number;
typeBreakdown: Record<string, number>;
};
/**
* Get reference count for an instance
* @param key - Optional instance key
*/
static getRefCount<T extends StateContainer<any>>(this: new (...args: any[]) => T, key?: string): number;
/**
* Check if an instance exists
* @param key - Optional instance key
*/
static hasInstance<T extends StateContainer<any>>(this: new (...args: any[]) => T, key?: string): boolean;
private _state;
private readonly listeners;
private _disposed;
private readonly config;
readonly name: string;
readonly debug: boolean;
readonly instanceId: string;
/**
* Create a new StateContainer
*/
constructor(initialState: S$1, config?: StateContainerConfig);
/**
* Get the current state
*/
get state(): S$1;
/**
* Check if disposed
*/
get isDisposed(): boolean;
/**
* Subscribe to state changes
* @returns Unsubscribe function
*/
subscribe(listener: StateListener<S$1>): () => void;
/**
* Dispose the container
*/
dispose(): void;
/**
* Emit a new state (with change detection)
*/
protected emit(newState: S$1): void;
/**
* Update state using a function
*/
protected update(updater: (current: S$1) => S$1): void;
/**
* Optional disposal hook for subclasses
*/
protected onDispose?(): void;
/**
* Optional state change hook for subclasses
*/
protected onStateChange?(newState: S$1, previousState: S$1): void;
}
//#endregion
//#region ../blac/src/types/branded.d.ts
/**
* Branded types for type-safe IDs
* These types ensure that IDs can't be accidentally mixed up
*/
/**
* Helper type for cases where any object type is acceptable
* Used sparingly only where type cannot be more specific
* eslint-disable-next-line @typescript-eslint/no-explicit-any
*/
type AnyObject = any;
//#endregion
//#region ../blac/src/types/utilities.d.ts
/**
* Extract state type from StateContainer
*
* @example
* ```ts
* class CounterBloc extends Cubit<number> { ... }
* type State = ExtractState<CounterBloc>; // number
* ```
*/
type ExtractState<T$1> = T$1 extends StateContainer<infer S> ? S : never;
/**
* Bloc constructor type - represents a class constructor for StateContainer subclasses
* Includes static methods from StateContainer for instance management
*
* Note: Uses `any` for state type to support variance - the actual Bloc instance
* will have the correct specific types inferred at usage sites.
*
* @example
* ```ts
* function createBloc<TBloc extends StateContainer<any>>(
* BlocClass: BlocConstructor<TBloc>
* ): TBloc {
* return BlocClass.getOrCreate();
* }
* ```
*/
type BlocConstructor<TBloc extends StateContainer<any>> = (new (...args: any[]) => TBloc) & {
getOrCreate?(instanceKey?: string, ...args: any[]): TBloc;
release?(instanceKey?: string): void;
isolated?: boolean;
keepAlive?: boolean;
};
//#endregion
//#region src/types.d.ts
/**
* Configuration options for the useBloc hook

@@ -307,0 +8,0 @@ *

import { RefObject } from "react";
import { AnyObject, BlocConstructor, ExtractState, StateContainer } from "@blac/core";
//#region ../blac/src/types/events.d.ts
//#region src/types.d.ts
/**
* Base event interface for type-safe event system
*/
/**
* Base event interface
* Used by Vertex for event-driven state management
*/
interface BaseEvent {
readonly type: string;
readonly timestamp: number;
readonly source?: string;
}
//#endregion
//#region ../blac/src/core/Vertex.d.ts
/**
* Event handler signature (synchronous only)
*/
type EventHandler<E$1 extends BaseEvent, S$1> = (event: E$1, emit: (state: S$1) => void) => void;
/**
* Type-safe event constructor
*/
type EventConstructor<T$1 extends BaseEvent = BaseEvent> = new (...args: never[]) => T$1;
/**
* Vertex is an event-driven state container (Bloc pattern)
*
* Includes its own simple event system since events are only needed
* for the Vertex pattern, not for the base StateContainer.
*/
declare abstract class Vertex<S$1, E$1 extends BaseEvent = BaseEvent> extends StateContainer<S$1> {
private eventHandlers;
private isProcessing;
private eventQueue;
/**
* Create a new Vertex
* @param initialState Initial state value
* @param config Configuration options
*/
constructor(initialState: S$1, config?: StateContainerConfig);
/**
* Register an event handler
* Arrow function to maintain correct 'this' binding
*/
protected on: <T extends E$1>(EventClass: EventConstructor<T>, handler: EventHandler<T, S$1>) => void;
/**
* Add an event to be processed
* Arrow function to maintain correct 'this' binding in React
*/
add: (event: E$1) => void;
/**
* Process an event (synchronously)
*/
private processEvent;
/**
* Handle a single event (synchronously)
*/
private handleEvent;
/**
* Hook for handling event processing errors
*/
protected onEventError(event: E$1, error: Error): void;
}
//#endregion
//#region ../blac/src/core/StateContainerRegistry.d.ts
/**
* Lifecycle events that can be observed
*/
type LifecycleEvent = 'created' | 'stateChanged' | 'eventAdded' | 'disposed';
/**
* Listener function types for each lifecycle event
*/
type LifecycleListener<E$1 extends LifecycleEvent> = E$1 extends 'created' ? (container: StateContainer<any>) => void : E$1 extends 'stateChanged' ? (container: StateContainer<any>, previousState: any, currentState: any) => void : E$1 extends 'eventAdded' ? (container: Vertex<any, any>, event: any) => void : E$1 extends 'disposed' ? (container: StateContainer<any>) => void : never;
/**
* Registry for managing StateContainer instances
*/
declare class StateContainerRegistry {
private readonly instances;
private readonly types;
private readonly listeners;
/**
* Register a type with isolation mode
*/
register<T extends StateContainer<any>>(constructor: new (...args: any[]) => T, isolated?: boolean): void;
/**
* Get or create a StateContainer instance
* For isolated: always creates new
* For shared: singleton per key
*/
getOrCreate<T extends StateContainer<any>>(constructor: new (...args: any[]) => T, key?: string, ...args: any[]): T;
/**
* Release a reference to an instance
* Disposes when ref count reaches zero (unless static keepAlive is true)
*/
release<T extends StateContainer<any>>(constructor: new (...args: any[]) => T, key?: string, forceDispose?: boolean): void;
/**
* Get all instances of a type (shared only, isolated aren't tracked)
*/
getAll<T extends StateContainer<any>>(constructor: new (...args: any[]) => T): T[];
/**
* Clear all instances of a type
*/
clear<T extends StateContainer<any>>(constructor: new (...args: any[]) => T): void;
/**
* Clear all instances from all types (for testing)
*/
clearAll(): void;
/**
* Get registry statistics (for debugging)
*/
getStats(): {
registeredTypes: number;
totalInstances: number;
typeBreakdown: Record<string, number>;
};
/**
* Get reference count for an instance
*/
getRefCount<T extends StateContainer<any>>(constructor: new (...args: any[]) => T, key?: string): number;
/**
* Check if an instance exists
*/
hasInstance<T extends StateContainer<any>>(constructor: new (...args: any[]) => T, key?: string): boolean;
/**
* Subscribe to lifecycle events
* @param event - The lifecycle event to listen for
* @param listener - The listener function to call when the event occurs
* @returns Unsubscribe function
*/
on<E extends LifecycleEvent>(event: E, listener: LifecycleListener<E>): () => void;
/**
* Emit lifecycle event to all listeners
* @internal - Called by StateContainer/Vertex lifecycle methods
*/
emit(event: LifecycleEvent, ...args: any[]): void;
}
//#endregion
//#region ../blac/src/core/StateContainer.d.ts
/**
* Configuration options for StateContainer
*/
interface StateContainerConfig {
/** Container name for debugging */
name?: string;
/** Enable debug logging */
debug?: boolean;
/** Custom instance identifier */
instanceId?: string;
}
/**
* Listener function for state changes
*/
type StateListener<S$1> = (state: S$1) => void;
/**
* Base abstract class for all state containers
*/
declare abstract class StateContainer<S$1> {
protected static _registry: StateContainerRegistry;
/**
* Set a custom registry (mainly for testing)
*/
static setRegistry(registry: StateContainerRegistry): void;
/**
* Register a type as isolated or shared
*/
static register<T extends StateContainer<any>>(this: new (...args: any[]) => T, isolated?: boolean): void;
/**
* Get or create an instance
* @param key - Optional instance key for shared instances
* @param args - Constructor arguments
*/
static getOrCreate<T extends StateContainer<any>>(this: new (...args: any[]) => T, key?: string, ...args: any[]): T;
/**
* Release a reference to an instance
* @param key - Optional instance key
* @param forceDispose - Force dispose regardless of ref count or keepAlive
*/
static release<T extends StateContainer<any>>(this: new (...args: any[]) => T, key?: string, forceDispose?: boolean): void;
/**
* Get all instances of this type
*/
static getAll<T extends StateContainer<any>>(this: new (...args: any[]) => T): T[];
/**
* Clear all instances of this type
*/
static clear<T extends StateContainer<any>>(this: new (...args: any[]) => T): void;
/**
* Clear all instances from all types (for testing)
*/
static clearAllInstances(): void;
/**
* Get registry statistics (for debugging)
*/
static getStats(): {
registeredTypes: number;
totalInstances: number;
typeBreakdown: Record<string, number>;
};
/**
* Get reference count for an instance
* @param key - Optional instance key
*/
static getRefCount<T extends StateContainer<any>>(this: new (...args: any[]) => T, key?: string): number;
/**
* Check if an instance exists
* @param key - Optional instance key
*/
static hasInstance<T extends StateContainer<any>>(this: new (...args: any[]) => T, key?: string): boolean;
private _state;
private readonly listeners;
private _disposed;
private readonly config;
readonly name: string;
readonly debug: boolean;
readonly instanceId: string;
/**
* Create a new StateContainer
*/
constructor(initialState: S$1, config?: StateContainerConfig);
/**
* Get the current state
*/
get state(): S$1;
/**
* Check if disposed
*/
get isDisposed(): boolean;
/**
* Subscribe to state changes
* @returns Unsubscribe function
*/
subscribe(listener: StateListener<S$1>): () => void;
/**
* Dispose the container
*/
dispose(): void;
/**
* Emit a new state (with change detection)
*/
protected emit(newState: S$1): void;
/**
* Update state using a function
*/
protected update(updater: (current: S$1) => S$1): void;
/**
* Optional disposal hook for subclasses
*/
protected onDispose?(): void;
/**
* Optional state change hook for subclasses
*/
protected onStateChange?(newState: S$1, previousState: S$1): void;
}
//#endregion
//#region ../blac/src/types/branded.d.ts
/**
* Branded types for type-safe IDs
* These types ensure that IDs can't be accidentally mixed up
*/
/**
* Helper type for cases where any object type is acceptable
* Used sparingly only where type cannot be more specific
* eslint-disable-next-line @typescript-eslint/no-explicit-any
*/
type AnyObject = any;
//#endregion
//#region ../blac/src/types/utilities.d.ts
/**
* Extract state type from StateContainer
*
* @example
* ```ts
* class CounterBloc extends Cubit<number> { ... }
* type State = ExtractState<CounterBloc>; // number
* ```
*/
type ExtractState<T$1> = T$1 extends StateContainer<infer S> ? S : never;
/**
* Bloc constructor type - represents a class constructor for StateContainer subclasses
* Includes static methods from StateContainer for instance management
*
* Note: Uses `any` for state type to support variance - the actual Bloc instance
* will have the correct specific types inferred at usage sites.
*
* @example
* ```ts
* function createBloc<TBloc extends StateContainer<any>>(
* BlocClass: BlocConstructor<TBloc>
* ): TBloc {
* return BlocClass.getOrCreate();
* }
* ```
*/
type BlocConstructor<TBloc extends StateContainer<any>> = (new (...args: any[]) => TBloc) & {
getOrCreate?(instanceKey?: string, ...args: any[]): TBloc;
release?(instanceKey?: string): void;
isolated?: boolean;
keepAlive?: boolean;
};
//#endregion
//#region src/types.d.ts
/**
* Configuration options for the useBloc hook

@@ -307,0 +8,0 @@ *

+3
-3
{
"name": "@blac/react",
"version": "2.0.0-rc.5",
"version": "2.0.0-rc.6",
"license": "MIT",

@@ -39,3 +39,3 @@ "author": "Brendan Mullins <jsnanigans@gmail.com>",

"react": "^18.0.0 || ^19.0.0",
"@blac/core": "2.0.0-rc.5"
"@blac/core": "2.0.0-rc.6"
},

@@ -69,3 +69,3 @@ "peerDependenciesMeta": {

"vitest": "^3.2.4",
"@blac/core": "2.0.0-rc.5"
"@blac/core": "2.0.0-rc.6"
},

@@ -72,0 +72,0 @@ "scripts": {