Skip to content

Core Overview ​

@wirestate/core contains the framework-agnostic part of Wirestate.

Use it to define services, construct scoped containers, run lifecycle hooks, and communicate through container-local events, commands, and queries.

The core package does not choose a reactivity system. A service can hold plain values, immutable data, external stores, or reactive objects created by another package.

Install ​

bash
npm install @wirestate/core

Basic Shape ​

ts
import { Container, Injectable } from "@wirestate/core";

@Injectable()
class CounterService {
  public count: number = 0;

  public increment(): void {
    this.count += 1;
  }
}

const container: Container = new Container({
  bindings: [CounterService],
});

const counter = container.get(CounterService);

counter.increment();

What Belongs in Core ​

  • Service classes and dependency injection.
  • Root and child containers.
  • Lifecycle hooks for service activation, service deactivation, provider provision, and provider deprovision.
  • Composable, opt-in messaging buses: a container registers only the plugins for the buses it uses, and a service injects the specific bus it needs.
  • Events for broadcast notifications.
  • Commands for one-handler write operations.
  • Queries for one-handler read operations.
  • Provision-scoped message handlers: @OnEvent, @OnCommand, and @OnQuery subscribe at provision and unsubscribe at deprovision.
  • Optional development-time inspection through the @wirestate/core/devtools subpath (DevToolsPlugin).
  • Binding inspection helpers that resolve a binding's token, type, and scope without repeating descriptor defaults.
  • The development-only @wirestate/core/hot runtime used by @wirestate/dev. Applications normally configure the bundler plugin instead of calling this entry directly.

API Reference ​

Container, WireStatus, EventBus, CommandBus, QueryBus, EventsPlugin, CommandsPlugin, QueriesPlugin, getBindingToken, getBindingType, and getBindingScope.