-
Notifications
You must be signed in to change notification settings - Fork 2
EventMachine Concepts
dsriseah edited this page Dec 3, 2024
·
1 revision
The EventMachine class implements a basic pub/sub. It's loosely modeled on the NodeJS EventEmitter class
. Note that this is not the same as a UI event, which contains UI-related context that is not necessary.
// non-working example demonstrating WIP syntax
import { EventMachine } from 'class-event-machine.ts'
import type { EventHandler } from 'class-event-machine.ts'
// define emitter
const EM = new EventMachine('input');
function Subscribe(evtName:string, handler:EventHandler) {
EM.on(evtName, handler);
}
// emit a random event
EM.emit('foo', { text: 'bar' });
export {
Subscribe // subscribe to events from module
}