blac

    Plugins

    DevTools

    Inspect live BlaC instances, their state and change history — in an in-app overlay or the Chrome DevTools panel.

    BlaC DevTools lets you inspect live instances, browse each instance’s state and change history, diff any change against the one before it, and follow a global log of created, changed and disposed instances. The same panel runs in an in-app overlay and in a Chrome DevTools tab.

    DevTools is delivered as a plugin: once installed it observes every state container from the outside, so there is nothing to wire up per bloc. Keep it scoped to environment: 'development'.

    Packages

    PackageWhat it does
    @blac/devtools-connectThe agent plugin that records instances, and the client that reads it
    @blac/devtools-uiThe panel UI and the in-app overlay
    BlaC Chrome ExtensionThe same panel as a Chrome DevTools tab

    Setup

    1. Install the agent

    Terminal window
    pnpm add @blac/devtools-connect
    import { getPluginManager } from '@blac/core/plugins';
    import { createDevToolsAgent } from '@blac/devtools-connect';
    getPluginManager().install(createDevToolsAgent(), {
    environment: 'development',
    });

    This is the minimum setup. The agent records recent history for every container but sends nothing — and serializes nothing — until a DevTools client attaches.

    2. Add the in-app overlay (optional)

    Terminal window
    pnpm add @blac/devtools-ui
    import { BlacDevtoolsUi } from '@blac/devtools-ui';
    function App() {
    return (
    <>
    <YourApp />
    <BlacDevtoolsUi />
    </>
    );
    }

    <BlacDevtoolsUi /> renders a panel docked to the bottom of the page, toggled with Alt+D (or by dispatching a blac-devtools-toggle event on window). Drag its top edge to resize. The overlay connects only while it is open, and it renders in a Shadow DOM so it cannot clash with your app’s CSS.

    3. Chrome extension (optional)

    Install the BlaC Chrome Extension from the Chrome Web Store (or build apps/devtools-extension/). A BlaC tab appears in Chrome DevTools. It attaches to the inspected tab’s top frame, follows reloads (keeping the selected instance), and reconnects if the extension’s service worker restarts.

    Agent options

    createDevToolsAgent({
    historySize: 50, // recorded changes kept per instance
    maxDisposed: 100, // disposed instances kept listed
    });

    What you can do

    Inspect instances

    The Instances view lists every container grouped by class, with a text filter, a toggle for disposed instances, and a change counter that flashes when an instance updates. Select one to open the inspector:

    • the args that keyed the instance, so two instances of the same class are easy to tell apart;
    • its current state as a collapsible tree (Maps, Sets, Dates, Errors and other non-JSON values are tagged);
    • its history, newest first, with the paths each change touched.

    State is sent only for the selected instance; everything else sends just metadata, which keeps large apps responsive.

    Diff a change

    Select a history entry to see its state and a Changes list — every path that was added, removed or changed compared with the previous entry, with before and after values.

    Follow the log

    The Log view is a bounded, global stream of created, changed and disposed events. Click an entry to jump to that instance and history entry.

    Keyboard shortcut

    Press Alt+D to toggle the in-app overlay.

    Excluding instances from DevTools

    High-frequency or internal state containers can be hidden:

    import {
    function blac(options: BlacOptions): <T extends new (...args: any[]) => any>(target: T, _context?: ClassDecoratorContext) => T

    Decorator to configure StateContainer classes.

    @example

    Decorator syntax (requires experimentalDecorators or TC39 decorators)

    @blac ― ({ keepAlive: true }) class AuthBloc extends Cubit {}

    @blac ― ({ excludeFromDevTools: true }) class InternalBloc extends Cubit {}

    @blac ―

    ({ keepAlive: true, key: (args) => args.userId }) class UserBloc extends Cubit {}

    @example

    Function syntax (no decorator support needed)

    const AuthBloc = blac({ keepAlive: true })(
    class extends Cubit<AuthState> {}
    );

    blac
    ,
    class Cubit<S extends object = any, Args = void, Deps extends object = Record<string, never>>

    Cubit<S> is a StateContainer<S> that exposes mutation publicly.

    That is the whole difference, and it is a real one: on StateContainer emit / patch / update are protected, so a container mutates itself from its own methods and callers go through the API it chooses to publish. Cubit re-declares the three as public for the cases where a caller legitimately drives state from outside — test helpers, devtools time-travel, benchmarks.

    Reach for StateContainer when business logic should live in the class, and Cubit when the caller owns the transitions.

    Cubit
    } from '@blac/core';
    @
    function blac(options: BlacOptions): <T extends new (...args: any[]) => any>(target: T, _context?: ClassDecoratorContext) => T

    Decorator to configure StateContainer classes.

    @example

    Decorator syntax (requires experimentalDecorators or TC39 decorators)

    @blac ― ({ keepAlive: true }) class AuthBloc extends Cubit {}

    @blac ― ({ excludeFromDevTools: true }) class InternalBloc extends Cubit {}

    @blac ―

    ({ keepAlive: true, key: (args) => args.userId }) class UserBloc extends Cubit {}

    @example

    Function syntax (no decorator support needed)

    const AuthBloc = blac({ keepAlive: true })(
    class extends Cubit<AuthState> {}
    );

    blac
    ({
    BlacOptions.excludeFromDevTools?: true | undefined

    Exclude bloc from DevTools tracking (prevents infinite loops)

    excludeFromDevTools
    : true })
    class
    class AnimationCubit
    AnimationCubit
    extends
    class Cubit<S extends object = any, Args = void, Deps extends object = Record<string, never>>

    Cubit<S> is a StateContainer<S> that exposes mutation publicly.

    That is the whole difference, and it is a real one: on StateContainer emit / patch / update are protected, so a container mutates itself from its own methods and callers go through the API it chooses to publish. Cubit re-declares the three as public for the cases where a caller legitimately drives state from outside — test helpers, devtools time-travel, benchmarks.

    Reach for StateContainer when business logic should live in the class, and Cubit when the caller owns the transitions.

    Cubit
    <{
    frame: number
    frame
    : number }> {
    constructor() {
    super({
    frame: number
    frame
    : 0 });
    }
    }

    The agent skips these instances entirely. excludeFromDevTools is one of the blac() configuration options.

    Writing your own host

    The panel is a plain React component driven by a DevToolsClient; a host only supplies a transport.

    import { DevToolsClient } from '@blac/devtools-connect/client';
    import { Panel } from '@blac/devtools-ui';
    const client = new DevToolsClient(transport); // any ClientTransport
    render(<Panel client={client} />);

    The wire protocol (@blac/devtools-connect/protocol) is versioned: every agent message carries a session and a seq, a client that sees a gap asks for a snapshot, and a protocol mismatch is reported in the panel instead of misbehaving.

    See also