ESP lets you manage changes to a store's state in a deterministic, event-driven manner.
A central EventBus sits between event publishers and your stores: publishers publish events to the bus, the bus dispatches each event through ordered observation stages so the store can apply the change, and then a frozen immutable snapshot of the store's model is pushed to its observers.
It's lightweight, easy to apply, and designed for complex UI and/or server state — including large composite single-page applications.
ESP is published as a family of packages that share a single version:
- esp-js — the core
EventBusand the immer-basedStoreBuilder - esp-js-di — a standalone IoC / dependency-injection container
- esp-js-ui — application bootstrapping and module loading (
AppBuilder,ModuleBuilder) - esp-js-react — React bindings (
EspApp,RegionView,ConnectableComponent, hooks)
Everything is written in TypeScript and type definitions are included in each npm package.
import { EventBus } from 'esp-js';
const bus = new EventBus();
type Counter = { count: number };
bus.storeBuilder<Counter>('counter', { count: 0 })
.withEventHandler('Increment', (draft, e: { by: number }) => {
draft.count += e.by; // mutate the immer draft directly
})
.build();
bus.getStoreModelObservable<Counter>('counter')
.subscribe(model => console.log(model.count)); // logs: 0 (the current model is replayed on subscribe)
bus.publishEvent('counter', 'Increment', { by: 1 }); // logs: 1This is the ESP monorepo, managed with npm workspaces and Turborepo, built with Vite and tested with Vitest.
npm install # link the workspace packages
npm run build-dev # build all packages in dependency order
npm test # run all package test suites
npm run dev # watch-mode build across all packagesThe examples/example-app directory contains a TodoMVC-style app demonstrating the full stack end to end.
For full documentation see https://esp.github.io/, or browse the source at github.com/esp/esp-js.