Broadcast
Broadcast even class. Allows for emitting events across contexts.
Constructors
new Broadcast()
new Broadcast(
config
?):Broadcast
Broadcast class constructor.
Parameters
config?
Returns
Methods
deleteEvent()
deleteEvent(
type
):void
Delete an even and unregister all callbacks associated with it.
Parameters
type
string
The event to delete.
Returns
void
destroy()
destroy():
void
Destroy the BroadcastChannel. After calling this, no further messages will be received.
Returns
void
emit()
emit<
T
>(type
,payload
):void
Emit an event to all listening contexts.
Type Parameters
• T
The type of the Payload data.
Parameters
type
string
The event type.
payload
T
The event payload.
Returns
void
Example
bus.emit(
EVENTS.LAYER_CLICK,
{
worldSpace: pickInfo.coordinate,
screenSpace: pickInfo.pixel,
index: pickInfo.index,
object: pickInfo.object,
},
);
getEvents()
getEvents():
string
[]
Get a list of all available events.
Returns
string
[]
off()
off<
T
>(type
,callback
):void
Unregister all callbacks for the specified event type.
Type Parameters
• T
The type of the Payload data.
Parameters
type
string
The event type.
callback
(data
) => void
Returns
void
on()
on<
T
>(type
,callback
): () =>void
Register a callback to be executed when a message of the specified event type is received.
Type Parameters
• T
The type of the Payload data.
Parameters
type
string
The event type.
callback
(data
) => void
The callback function.
Returns
Function
Returns
void
Example
bus.on(EVENTS.MAP_CLICK, (e) => {
if (!e.payload.picked) {
setSelected(null);
}
});
once()
once<
T
>(type
,callback
): () =>void
Register a callback to be executed only once for a specified event type.
Type Parameters
• T
The type of the Payload data.
Parameters
type
string
The event type.
callback
(data
) => void
The callback function.
Returns
Function
Returns
void
getInstance()
static
getInstance(config
?):Broadcast
Get the singleton instance of Broadcaster.
Parameters
config?
Optional custom configuration.