Skip to content

Plugins

A plugin is a single object that taps into the registry’s lifecycle — every instance created, every state change, every disposal flows through it. Where system events let one bloc react to its own lifecycle from the inside, a plugin observes all instances from the outside. That makes plugins the right tool for cross-cutting concerns: logging, inspection, persistence — anything you want to apply uniformly without editing each bloc.

BlaC has an official set of plugins for these common needs. All plugins implement the BlacPlugin interface and are installed once, at startup, via getPluginManager().install().

PackagePurposeTypical environment
@blac/logging-pluginConsole logging, instance monitoring, rapid lifecycle detectionDevelopment
@blac/devtools-connectCore plugin for instance tracking and state inspectionDevelopment
@blac/devtools-uiIn-app draggable overlay and panel UI componentsDevelopment
@blac/plugin-persistPersist state to IndexedDB with automatic hydrationAll
import { getPluginManager } from '@blac/core';
getPluginManager().install(myPlugin, {
enabled: true,
environment: 'development', // 'development' | 'production' | 'test' | 'all'
});

The environment option controls when the plugin is active. The check is a runtime comparison against process.env.NODE_ENV (which falls back to 'development') performed inside install(): if the environments don’t match, the plugin is skipped with a log message and never wired up. So environment: 'development' means the plugin does nothing in a production build — but the import still ships unless your bundler tree-shakes it. To keep dev-only plugin code out of the bundle entirely, guard the install() call behind your own import.meta.env.DEV (or equivalent) check.

Install as many plugins as you need. They all receive the same lifecycle callbacks independently.

import { getPluginManager } from '@blac/core';
import { LoggingPlugin } from '@blac/logging-plugin';
import { createDevToolsBrowserPlugin } from '@blac/devtools-connect';
import { createIndexedDbPersistPlugin } from '@blac/plugin-persist';
const pm = getPluginManager();
pm.install(new LoggingPlugin({ level: 'info' }), {
environment: 'development',
});
pm.install(createDevToolsBrowserPlugin(), { environment: 'development' });
pm.install(createIndexedDbPersistPlugin());

See Plugin Authoring for the full BlacPlugin interface, the hook firing model, and the PluginContext API.