An EventMap-shaped type that maps event keys to the event payload types.
Timer semantics:
name. Each instance of CoreElement maintains its own
map of timers.Event semantics:
E.Threading / reentrancy / error handling:
// Strongly-typed events
interface MyEvents { loaded: { ok: boolean }, tick: number }
class MyElement extends CoreElement<MyEvents> {}
const el = new MyElement();
const sub = el.on("loaded", e => console.log(e.ok));
el.fire("loaded", { ok: true });
sub.off(); // convenience to remove listener
// Timers
el.setInterval("poll", 1000, () => el.fire("tick", Date.now()));
el.clearInterval("poll");
An EventMap-shaped type that maps event keys to the event payload types.
Timer semantics:
name. Each instance of CoreElement maintains its own
map of timers.Event semantics:
E.Threading / reentrancy / error handling:
// Strongly-typed events
interface MyEvents { loaded: { ok: boolean }, tick: number }
class MyElement extends CoreElement<MyEvents> {}
const el = new MyElement();
const sub = el.on("loaded", e => console.log(e.ok));
el.fire("loaded", { ok: true });
sub.off(); // convenience to remove listener
// Timers
el.setInterval("poll", 1000, () => el.fire("tick", Date.now()));
el.clearInterval("poll");
Dispatches an event with a given name and payload to all registered listeners. If no listeners are registered for the event name, or if no EventSource has been initialized, this method does nothing.
Removes a previously registered event listener. If the listener was not found or no events were registered, this method does nothing.
Registers an event listener for a specific event name.
The listener will be invoked when an event with the given name is fired.
Returns an object with an off() method, which can be used to conveniently remove this specific listener.
An object containing an off() method to unsubscribe the listener.
Sets an interval that repeatedly executes a callback function after a specified delay. If a timeout with the same name already exists, it will be cleared before the new one is set.
A unique string identifier for this timeout.
The delay in milliseconds before the callback is executed.
The function to execute after the delay.
Sets a timeout that executes a callback function after a specified delay. If a timeout with the same name already exists, it will be cleared before the new one is set.
A unique string identifier for this timeout.
The delay in milliseconds before the callback is executed.
The function to execute after the delay.
CoreElement
A lightweight base class that provides two orthogonal utilities commonly needed by UI or domain objects:
The class is generic over an EventMap
Ewhich maps event name keys to the payload type for that event. This enables compile-time type safety for listeners and fired events.Template parameters: