@wimaengine/event provides listener-driven state, buffered event batches, and ECS wiring for typed event payloads.
Installation
npm i @wimaengine/event
Capability Highlights
Signalgives the package a small listener-based mutable value primitive for fan-out on state change.CEventwraps each payload in a stable event record so consumers read.datainstead of raw values.Events<T>separates writes from reads, letting systems queue payloads during a write pass and inspect the last cleared batch during a read pass.EventPluginregisters event payload types, installs per-eventEvents<T>resources, and can auto-clear them at the end of each update cycle.registerEventTypes()seeds both the payload constructor and theEvents<T>type-id into the reflection/type registry.
Core Concepts
Signal
Signal stores a value and notifies every registered listener whenever setValue() changes that value. addListener() and removeListener() manage subscriptions directly, which keeps it lightweight and predictable for engine-internal state propagation.
CEvent
CEvent<T> is the package’s event record. It wraps payloads in a data field, keeping the event shape stable across the rest of the package and any ECS systems that consume it.
Events
Events<T> is the buffered event store. write() appends new CEvent instances to a write buffer, while clear() rotates that buffer into the readable batch and resets the writer side. each(), readFirst(), readLast(), and count() all work against the current read buffer, so consumers observe a stable batch until the next clear.
EventPlugin and Systems
EventPlugin<T> is the ECS integration layer. During registration it declares the payload constructor with the app, schedules registerEventTypes(event) at startup inside CoreSystems.Start, installs a typed Events<T> resource in the world, and, when autoClearEvent is enabled, schedules makeEventClear(typeId) for AppSchedule.Update in CoreSystems.End. The helper systems keep the reflection registry and the per-event buffer in sync with the runtime lifecycle.
Exported Surface
coreexportsSignal,CEvent, andEvents.typedefexports theEventReader<T>callback type used by read-side consumers.systemsexportsregisterEventTypes()andmakeEventClear().pluginexportsEventPlugin.- The package root re-exports the
srcsurface, and the manifest also exposes./srcfor source-level imports.
Notes
- The package is ECS-oriented rather than a standalone message bus.
Events.clear()is a batch-rotation step, not a destructive wipe of already-published reads.registerEventTypes()uses empty structural metadata for payload constructors and treats theEvents<T>resource as opaque in the reflection registry.- The
./srcsubpath is part of the public package contract, so README language should stay compatible with both root and source imports.
