@blac/preact
Advanced tools
| /** | ||
| * Global configuration for @blac/preact | ||
| */ | ||
| export interface BlacPreactConfig { | ||
| /** Enable automatic property tracking via Proxy (default: true) */ | ||
| autoTrack: boolean; | ||
| } | ||
| /** | ||
| * Configure global defaults for @blac/preact hooks. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { configureBlacPreact } from '@blac/preact'; | ||
| * | ||
| * // Disable auto-tracking globally | ||
| * configureBlacPreact({ | ||
| * autoTrack: false | ||
| * }); | ||
| * ``` | ||
| * | ||
| * @param config - Partial configuration to merge with defaults | ||
| */ | ||
| export declare function configureBlacPreact(config: Partial<BlacPreactConfig>): void; | ||
| /** | ||
| * Get the current global configuration. | ||
| * @internal | ||
| */ | ||
| export declare function getBlacPreactConfig(): BlacPreactConfig; | ||
| /** | ||
| * Reset configuration to defaults (useful for testing). | ||
| * @internal | ||
| */ | ||
| export declare function resetBlacPreactConfig(): void; |
| import type { ExtractState, StateContainerConstructor } from '@blac/core'; | ||
| import { InstanceReadonlyState } from '@blac/core'; | ||
| import type { RefObject } from 'preact'; | ||
| /** | ||
| * Configuration options for useBloc hook | ||
| * @template TBloc - The state container type | ||
| */ | ||
| export interface UseBlocOptions<TBloc extends StateContainerConstructor> { | ||
| /** Custom instance identifier for shared or isolated instances */ | ||
| instanceId?: string | number; | ||
| /** Manual dependency array like useEffect (disables autoTrack) */ | ||
| dependencies?: (state: ExtractState<TBloc>, bloc: InstanceReadonlyState<TBloc>) => unknown[]; | ||
| /** Enable automatic property tracking via Proxy (default: true) */ | ||
| autoTrack?: boolean; | ||
| /** Callback invoked when bloc instance mounts */ | ||
| onMount?: (bloc: InstanceType<TBloc>) => void; | ||
| /** Callback invoked when bloc instance unmounts */ | ||
| onUnmount?: (bloc: InstanceType<TBloc>) => void; | ||
| } | ||
| /** | ||
| * Tuple return type from useBloc hook containing state, bloc instance, and ref | ||
| * - [0] Current state value (with optional state type override) | ||
| * - [1] State container instance (bloc) for calling actions | ||
| * - [2] Ref object for accessing component ref (advanced use cases) | ||
| * | ||
| * @template TBloc - The state container type | ||
| */ | ||
| export type UseBlocReturn<TBloc extends StateContainerConstructor, S = ExtractState<TBloc>> = [S, InstanceReadonlyState<TBloc>, RefObject<ComponentRef>]; | ||
| /** | ||
| * Internal ref structure for component-bloc binding | ||
| * @internal | ||
| */ | ||
| export type ComponentRef = { | ||
| /** Cached bloc instance ID for this component */ | ||
| __blocInstanceId?: string; | ||
| }; |
| import { type ExtractState, type StateContainerConstructor } from '@blac/adapter'; | ||
| import type { UseBlocOptions, UseBlocReturn } from './types'; | ||
| /** | ||
| * Preact hook that connects a component to a state container with automatic re-render on state changes. | ||
| * | ||
| * Supports three tracking modes: | ||
| * - **Auto-tracking** (default): Automatically detects accessed state properties via Proxy | ||
| * - **Manual dependencies**: Explicit dependency array like useEffect | ||
| * - **No tracking**: Returns full state without optimization | ||
| * | ||
| * @template T - The state container constructor type (inferred from BlocClass) | ||
| * @param BlocClass - The state container class to connect to | ||
| * @param options - Configuration options for tracking mode and instance management | ||
| * @returns Tuple with [state, bloc instance, ref] | ||
| * | ||
| * @example Basic usage | ||
| * ```ts | ||
| * const [state, myBloc, ref] = useBloc(MyBloc); | ||
| * ``` | ||
| * | ||
| * @example With manual dependencies | ||
| * ```ts | ||
| * const [state, myBloc] = useBloc(MyBloc, { | ||
| * dependencies: (state) => [state.count] | ||
| * }); | ||
| * ``` | ||
| * | ||
| * @example With isolated instance | ||
| * ```ts | ||
| * const [state, myBloc] = useBloc(MyBloc, { | ||
| * instanceId: 'unique-id' | ||
| * }); | ||
| * ``` | ||
| */ | ||
| export declare function useBloc<T extends StateContainerConstructor = StateContainerConstructor>(BlocClass: T, options?: UseBlocOptions<T>): UseBlocReturn<T, ExtractState<T>>; |
| /** | ||
| * Instance key generation utilities for Preact integration | ||
| */ | ||
| import type { ComponentRef } from '../types'; | ||
| /** | ||
| * Generate an instance key for a bloc | ||
| * | ||
| * Logic: | ||
| * - If user provides instanceId, use it (convert number to string) | ||
| * - If isolated, generate or reuse a unique key for this component | ||
| * - Otherwise, return undefined (use default key) | ||
| * | ||
| * @param componentRef - Preact component reference (persists across remounts) | ||
| * @param isIsolated - Whether the bloc is isolated | ||
| * @param providedId - User-provided instance ID (from options) | ||
| * @returns Instance key string or undefined for default | ||
| */ | ||
| export declare function generateInstanceKey(componentRef: ComponentRef, isIsolated: boolean, providedId?: string | number): string | undefined; |
+8
-93
@@ -1,96 +0,11 @@ | ||
| import type { ExtractState } from '@blac/core'; | ||
| import { ExtractState as ExtractState_2 } from '@blac/adapter'; | ||
| import { InstanceReadonlyState } from '@blac/core'; | ||
| import type { RefObject } from 'preact'; | ||
| import { StateContainerConstructor } from '@blac/adapter'; | ||
| import type { StateContainerConstructor as StateContainerConstructor_2 } from '@blac/core'; | ||
| /** | ||
| * Global configuration for @blac/preact | ||
| */ | ||
| export declare interface BlacPreactConfig { | ||
| /** Enable automatic property tracking via Proxy (default: true) */ | ||
| autoTrack: boolean; | ||
| } | ||
| /* Excluded from this release type: ComponentRef */ | ||
| /** | ||
| * Configure global defaults for @blac/preact hooks. | ||
| * Preact Integration | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { configureBlacPreact } from '@blac/preact'; | ||
| * | ||
| * // Disable auto-tracking globally | ||
| * configureBlacPreact({ | ||
| * autoTrack: false | ||
| * }); | ||
| * ``` | ||
| * | ||
| * @param config - Partial configuration to merge with defaults | ||
| * Clean integration between Preact and StateContainer architecture. | ||
| * Constructor-based API with automatic type inference. | ||
| * Supports concurrent mode via useSyncExternalStore shim. | ||
| */ | ||
| export declare function configureBlacPreact(config: Partial<BlacPreactConfig>): void; | ||
| /** | ||
| * Preact hook that connects a component to a state container with automatic re-render on state changes. | ||
| * | ||
| * Supports three tracking modes: | ||
| * - **Auto-tracking** (default): Automatically detects accessed state properties via Proxy | ||
| * - **Manual dependencies**: Explicit dependency array like useEffect | ||
| * - **No tracking**: Returns full state without optimization | ||
| * | ||
| * @template T - The state container constructor type (inferred from BlocClass) | ||
| * @param BlocClass - The state container class to connect to | ||
| * @param options - Configuration options for tracking mode and instance management | ||
| * @returns Tuple with [state, bloc instance, ref] | ||
| * | ||
| * @example Basic usage | ||
| * ```ts | ||
| * const [state, myBloc, ref] = useBloc(MyBloc); | ||
| * ``` | ||
| * | ||
| * @example With manual dependencies | ||
| * ```ts | ||
| * const [state, myBloc] = useBloc(MyBloc, { | ||
| * dependencies: (state) => [state.count] | ||
| * }); | ||
| * ``` | ||
| * | ||
| * @example With isolated instance | ||
| * ```ts | ||
| * const [state, myBloc] = useBloc(MyBloc, { | ||
| * instanceId: 'unique-id' | ||
| * }); | ||
| * ``` | ||
| */ | ||
| export declare function useBloc<T extends StateContainerConstructor = StateContainerConstructor>(BlocClass: T, options?: UseBlocOptions<T>): UseBlocReturn<T, ExtractState_2<T>>; | ||
| /** | ||
| * Configuration options for useBloc hook | ||
| * @template TBloc - The state container type | ||
| */ | ||
| export declare interface UseBlocOptions<TBloc extends StateContainerConstructor_2> { | ||
| /** Custom instance identifier for shared or isolated instances */ | ||
| instanceId?: string | number; | ||
| /** Manual dependency array like useEffect (disables autoTrack) */ | ||
| dependencies?: (state: ExtractState<TBloc>, bloc: InstanceReadonlyState<TBloc>) => unknown[]; | ||
| /** Enable automatic property tracking via Proxy (default: true) */ | ||
| autoTrack?: boolean; | ||
| /** Callback invoked when bloc instance mounts */ | ||
| onMount?: (bloc: InstanceType<TBloc>) => void; | ||
| /** Callback invoked when bloc instance unmounts */ | ||
| onUnmount?: (bloc: InstanceType<TBloc>) => void; | ||
| } | ||
| /** | ||
| * Tuple return type from useBloc hook containing state, bloc instance, and ref | ||
| * - [0] Current state value (with optional state type override) | ||
| * - [1] State container instance (bloc) for calling actions | ||
| * - [2] Ref object for accessing component ref (advanced use cases) | ||
| * | ||
| * @template TBloc - The state container type | ||
| */ | ||
| export declare type UseBlocReturn<TBloc extends StateContainerConstructor_2, S = ExtractState<TBloc>> = [S, InstanceReadonlyState<TBloc>, RefObject<ComponentRef>]; | ||
| export { } | ||
| export { useBloc } from './useBloc'; | ||
| export { configureBlacPreact } from './config'; | ||
| export type { BlacPreactConfig } from './config'; | ||
| export type { UseBlocOptions, UseBlocReturn } from './types'; |
+8
-93
@@ -1,96 +0,11 @@ | ||
| import type { ExtractState } from '@blac/core'; | ||
| import { ExtractState as ExtractState_2 } from '@blac/adapter'; | ||
| import { InstanceReadonlyState } from '@blac/core'; | ||
| import type { RefObject } from 'preact'; | ||
| import { StateContainerConstructor } from '@blac/adapter'; | ||
| import type { StateContainerConstructor as StateContainerConstructor_2 } from '@blac/core'; | ||
| /** | ||
| * Global configuration for @blac/preact | ||
| */ | ||
| export declare interface BlacPreactConfig { | ||
| /** Enable automatic property tracking via Proxy (default: true) */ | ||
| autoTrack: boolean; | ||
| } | ||
| /* Excluded from this release type: ComponentRef */ | ||
| /** | ||
| * Configure global defaults for @blac/preact hooks. | ||
| * Preact Integration | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { configureBlacPreact } from '@blac/preact'; | ||
| * | ||
| * // Disable auto-tracking globally | ||
| * configureBlacPreact({ | ||
| * autoTrack: false | ||
| * }); | ||
| * ``` | ||
| * | ||
| * @param config - Partial configuration to merge with defaults | ||
| * Clean integration between Preact and StateContainer architecture. | ||
| * Constructor-based API with automatic type inference. | ||
| * Supports concurrent mode via useSyncExternalStore shim. | ||
| */ | ||
| export declare function configureBlacPreact(config: Partial<BlacPreactConfig>): void; | ||
| /** | ||
| * Preact hook that connects a component to a state container with automatic re-render on state changes. | ||
| * | ||
| * Supports three tracking modes: | ||
| * - **Auto-tracking** (default): Automatically detects accessed state properties via Proxy | ||
| * - **Manual dependencies**: Explicit dependency array like useEffect | ||
| * - **No tracking**: Returns full state without optimization | ||
| * | ||
| * @template T - The state container constructor type (inferred from BlocClass) | ||
| * @param BlocClass - The state container class to connect to | ||
| * @param options - Configuration options for tracking mode and instance management | ||
| * @returns Tuple with [state, bloc instance, ref] | ||
| * | ||
| * @example Basic usage | ||
| * ```ts | ||
| * const [state, myBloc, ref] = useBloc(MyBloc); | ||
| * ``` | ||
| * | ||
| * @example With manual dependencies | ||
| * ```ts | ||
| * const [state, myBloc] = useBloc(MyBloc, { | ||
| * dependencies: (state) => [state.count] | ||
| * }); | ||
| * ``` | ||
| * | ||
| * @example With isolated instance | ||
| * ```ts | ||
| * const [state, myBloc] = useBloc(MyBloc, { | ||
| * instanceId: 'unique-id' | ||
| * }); | ||
| * ``` | ||
| */ | ||
| export declare function useBloc<T extends StateContainerConstructor = StateContainerConstructor>(BlocClass: T, options?: UseBlocOptions<T>): UseBlocReturn<T, ExtractState_2<T>>; | ||
| /** | ||
| * Configuration options for useBloc hook | ||
| * @template TBloc - The state container type | ||
| */ | ||
| export declare interface UseBlocOptions<TBloc extends StateContainerConstructor_2> { | ||
| /** Custom instance identifier for shared or isolated instances */ | ||
| instanceId?: string | number; | ||
| /** Manual dependency array like useEffect (disables autoTrack) */ | ||
| dependencies?: (state: ExtractState<TBloc>, bloc: InstanceReadonlyState<TBloc>) => unknown[]; | ||
| /** Enable automatic property tracking via Proxy (default: true) */ | ||
| autoTrack?: boolean; | ||
| /** Callback invoked when bloc instance mounts */ | ||
| onMount?: (bloc: InstanceType<TBloc>) => void; | ||
| /** Callback invoked when bloc instance unmounts */ | ||
| onUnmount?: (bloc: InstanceType<TBloc>) => void; | ||
| } | ||
| /** | ||
| * Tuple return type from useBloc hook containing state, bloc instance, and ref | ||
| * - [0] Current state value (with optional state type override) | ||
| * - [1] State container instance (bloc) for calling actions | ||
| * - [2] Ref object for accessing component ref (advanced use cases) | ||
| * | ||
| * @template TBloc - The state container type | ||
| */ | ||
| export declare type UseBlocReturn<TBloc extends StateContainerConstructor_2, S = ExtractState<TBloc>> = [S, InstanceReadonlyState<TBloc>, RefObject<ComponentRef>]; | ||
| export { } | ||
| export { useBloc } from './useBloc'; | ||
| export { configureBlacPreact } from './config'; | ||
| export type { BlacPreactConfig } from './config'; | ||
| export type { UseBlocOptions, UseBlocReturn } from './types'; |
+7
-12
| { | ||
| "name": "@blac/preact", | ||
| "version": "2.0.4", | ||
| "version": "2.0.5", | ||
| "license": "MIT", | ||
@@ -31,7 +31,3 @@ "author": "Brendan Mullins <jsnanigans@gmail.com>", | ||
| "files": [ | ||
| "dist/index.js", | ||
| "dist/index.cjs", | ||
| "dist/index.d.ts", | ||
| "dist/index.d.cts", | ||
| "dist/*.map", | ||
| "dist", | ||
| "README.md", | ||
@@ -51,3 +47,3 @@ "LICENSE" | ||
| "dependencies": { | ||
| "@blac/adapter": "2.0.4" | ||
| "@blac/adapter": "2.0.5" | ||
| }, | ||
@@ -70,11 +66,9 @@ "peerDependencies": { | ||
| "vite": "^7.1.10", | ||
| "publint": "^0.3.12", | ||
| "vitest": "3.2.4", | ||
| "@blac/core": "2.0.4" | ||
| "@blac/core": "2.0.5" | ||
| }, | ||
| "scripts": { | ||
| "dev": "tsdown --watch", | ||
| "build": "pnpm build:js && pnpm build:types && pnpm build:dts", | ||
| "build:js": "tsdown", | ||
| "build:types": "tsc -p tsconfig.build.json", | ||
| "build:dts": "api-extractor run --local && cp dist/index.d.ts dist/index.d.cts && rm -rf dist/.types", | ||
| "build": "tsdown && tsc -p tsconfig.build.json && cp dist/index.d.ts dist/index.d.cts", | ||
| "clean": "rm -rf dist", | ||
@@ -86,2 +80,3 @@ "format": "prettier --write \".\"", | ||
| "test:watch": "vitest --watch --config vitest.config.ts", | ||
| "verify": "publint", | ||
| "typecheck": "tsc --noEmit", | ||
@@ -88,0 +83,0 @@ "deploy": "pnpm publish --access public" |
13
44.44%457
10.65%38864
-4.86%15
7.14%+ Added
+ Added
- Removed
- Removed
Updated