Skip to main content
zerotal

Documentation


Documentation / @zerotal/broadcasting / TypedBroadcastEvent

Interface: TypedBroadcastEvent<M, Ch, Ev>

Defined in: broadcasting/src/TypedBroadcastManager.ts:88

Implement on an event class to make it a typed broadcast event. The type parameters enforce that the event name and payload match the channel map.

Example

class PostCreated implements TypedBroadcastEvent<Channels, 'posts', 'PostCreated'> {
  constructor(private post: Post) {}

  broadcastOn()   { return 'posts' as const; }
  broadcastAs()   { return 'PostCreated' as const; }
  broadcastWith() { return { id: this.post.id, title: this.post.title }; }
}

Extends

Type Parameters

M

M extends BroadcastChannelMap

Ch

Ch extends keyof M & string

Ev

Ev extends EventsOf<M, Ch> = EventsOf<M, Ch>

Methods

broadcastOn()

broadcastOn(): Ch | Ch[]

Defined in: broadcasting/src/TypedBroadcastManager.ts:93

Channel name(s) to broadcast on. Use channel(), privateChannel(), or presenceChannel().

Returns

Ch | Ch[]

Overrides

BroadcastEvent.broadcastOn


broadcastAs()

broadcastAs(): Ev

Defined in: broadcasting/src/TypedBroadcastManager.ts:94

Optional — defaults to the class constructor name.

Returns

Ev

Overrides

BroadcastEvent.broadcastAs


broadcastWith()

broadcastWith(): PayloadOf<M, Ch, Ev>

Defined in: broadcasting/src/TypedBroadcastManager.ts:95

Data to include in the broadcast payload. Defaults to {}.

Returns

PayloadOf<M, Ch, Ev>

Overrides

BroadcastEvent.broadcastWith