Documentation / @zerotal/broadcasting / BroadcastingEvent
Abstract Class: BroadcastingEvent
Defined in: broadcasting/src/BroadcastingEvent.ts:42
Base class for broadcastable events. Extend it, implement broadcastOn(), and you get
sensible defaults plus a static dispatch() that both fires application listeners and
broadcasts the event.
Example
import { BroadcastingEvent, privateChannel } from "@zerotal/broadcasting";
export class OrderShipmentStatusUpdated extends BroadcastingEvent {
constructor(public readonly order: Order) { super(); }
broadcastOn() { return privateChannel(`orders.${this.order.id}`); }
broadcastWith() { return { id: this.order.id, status: this.order.status }; }
broadcastWhen() { return this.order.total > 100; }
}
// Construct + dispatch (runs listeners + broadcasts):
OrderShipmentStatusUpdated.dispatch(order);
// Or broadcast only, excluding the current socket:
broadcast(new OrderShipmentStatusUpdated(order)).toOthers();
Implements
Constructors
Constructor
new BroadcastingEvent():
BroadcastingEvent
Returns
BroadcastingEvent
Methods
dispatch()
staticdispatch<T,A>(this, ...args):T
Defined in: broadcasting/src/BroadcastingEvent.ts:74
Construct the event from the given arguments, fire it on the application event bus (so any
registered listeners run), and broadcast it (gated by broadcastWhen()).
Type Parameters
T
T extends BroadcastingEvent
A
A extends unknown[]
Parameters
this
(...args) => T
args
...A
Returns
T
Example
OrderShipmentStatusUpdated.dispatch(order);
broadcastOn()
abstractbroadcastOn():string|string[]
Defined in: broadcasting/src/BroadcastingEvent.ts:44
Channel name(s) to broadcast on. Use channel()/privateChannel()/presenceChannel().
Returns
string | string[]
Implementation of
broadcastAs()
broadcastAs():
string
Defined in: broadcasting/src/BroadcastingEvent.ts:47
Wire event name. Defaults to the class name.
Returns
string
Implementation of
broadcastWith()
broadcastWith():
object
Defined in: broadcasting/src/BroadcastingEvent.ts:55
Payload to broadcast. Defaults to the event's own enumerable, non-function properties (so constructor-assigned fields are sent automatically). Override for a custom shape.
Returns
object
Implementation of
broadcastWhen()
broadcastWhen():
boolean
Defined in: broadcasting/src/BroadcastingEvent.ts:64
Conditional gate — the event broadcasts only when this returns true. Default: true.
Returns
boolean