A cross-platform EventEmitter implementation for Node.js and browsers, with an advanced reactive signals system (EventSignal) deeply integrated with React.
Online documentation and Demo ↗
- ✅ Full Node.js
EventEmitterAPI compatibility - 🌐 Works in browsers without polyfills
- 🔒
listenerOncePerEventType— prevent duplicate listeners per event - 📊
emitCounter— count emit calls for monitoring - ⏱️ Enhanced
static once()— Promise-based with filter, timeout, AbortSignal, multiple event names, and bothEventEmitter/EventTargetsupport - 🔄
static on()— async iterator for event streams with value transformation - 🧹
destructor()/Symbol.dispose— safe resource cleanup - 🐛
isDebugTraceListeners— attach call stacks to listeners for debugging
- ⚡ Reactive computed values with automatic dependency tracking
- 🔀 Sync and async computations
- ⚛️ Deep React integration:
use(),useListener(), direct JSX rendering - 🎭 Component type system for polymorphic rendering (
registerReactComponentForComponentType) - 📡 Source emitters — subscribe to external
EventEmitter/EventTargetevents - ⏰ Triggers — clock, emitter, or signal-based recomputation
- 🎯
createMethod— typed action methods bound to signals - 📦
Subscriptionobjects withsuspend()/resume() - 🔮 Promise API and async iteration (
for await...of)
import { EventEmitterX } from '@termi/eventemitterx/modules/events';
import { EventSignal } from '@termi/eventemitterx/modules/EventEmitterEx/EventSignal';
// --- EventEmitterX ---
const emitter = new EventEmitterX();
// Promise-based once with filter and timeout
const [data] = await EventEmitterX.once(emitter, 'data', {
filter: (event, value) => value > 10,
timeout: 5000,
});
// Async iterator
for await (const [tick] of EventEmitterX.on(emitter, 'tick')) {
console.log(tick);
}
// --- EventSignal ---
const counter$ = new EventSignal(0);
const doubled$ = new EventSignal(0, () => counter$.get() * 2);
counter$.set(5);
console.log(doubled$.get()); // 10
// React integration
EventSignal.initReact(React);
function App() {
const count = counter$.use();
return <div>{count}</div>;
}| Document | Description |
|---|---|
| Project Analysis | Full project overview and architecture |
| Module Index | Brief overview of all modules |
| EventEmitterX API | Detailed API reference with examples |
| EventSignal API | Detailed API reference with examples |
| Improvements | Potential improvements and roadmap |
📖 Russian versions (
_RU.md) are available for all documentation files.
A React + Vite application demonstrating EventSignal features: counters, computed values, async data fetching, i18n, component switching, and more.
cd demo/eventSignals-test-app ; pnpm i ; pnpm run devA real-time multiplayer clicker game with Fastify backend, Prisma ORM, and SSE-based updates.
cd demo/clicker ; ./bash/run_dev_backend_frontend.shpnpm installpnpm run build # CJS + ESM
pnpm run build:cjs # CommonJS only
pnpm run build:esm # ES Modules onlyISC