Types
All of these types live in src/core/types.ts and form the foundation of the library’s type system.
| Type | Description |
|---|---|
Handler<T> |
(payload: T) => void — signature of an event handler. |
EventMap |
Record<string, unknown> — generic constraint for user-defined events. |
TabusMessage<T> |
Shape of the internal message: { tabId, event, payload }. |
InternalEvents |
{ "tab:join": { tabId }, "tab:leave": { tabId } } — automatically emitted lifecycle events. |
FullEventMap<T> |
Combines the user’s events (T) with InternalEvents; used in the signatures of on() / off(). |
TabusOptions |
{ throttle?: number; trailing?: boolean } — see Options. |
Handler<T>
Section titled “Handler<T>”type Handler<T = unknown> = (payload: T) => void;The signature any function passed to on() or off() must satisfy.
EventMap
Section titled “EventMap”type EventMap = Record<string, unknown>;Generic constraint that the event type you pass to Tabus<Events> must satisfy. Any object with string keys works:
type MyEvents = { data: { value: number }; reset: void;};TabusMessage<T>
Section titled “TabusMessage<T>”interface TabusMessage<T = unknown> { tabId: string; event: string; payload: T;}Shape of the internal message that travels through the transport. It’s the type received by send() and by listeners registered with onMessage() on ITransport.
InternalEvents
Section titled “InternalEvents”type InternalEvents = { "tab:join": { tabId: string }; "tab:leave": { tabId: string };};The two lifecycle events that Tabus emits automatically. See Lifecycle events.
FullEventMap<T>
Section titled “FullEventMap<T>”type FullEventMap<T extends EventMap> = T & InternalEvents;Combines your custom events with InternalEvents. It’s the actual type used by the signatures of on() and off(), so you can always subscribe to "tab:join" / "tab:leave" in addition to your own events, without declaring them yourself.
Next step
Section titled “Next step”- Tabus class: where these types are used in practice.
- Exports: what’s publicly exported from the package.
