Skip to main content

Events

A fish consumes events, but emitting events is not coupled to fishes.

Events can be emitted directly using the Actyx Event Service, or using the Actyx Pond. Actyx Pond provides two main APIs for emitting events: pond.emit and pond.run (we'll learn how to use state effects later).

Events are tagged with an arbitrary number of tags, each tag being just a non-empty string:

pond.emit(
// We add the pure 'chatRoom' tag as well, to allow finding all chat events
Tags('chatRoom', 'chatRoom:lobby', 'sender', 'sender:Alf'),
{ type: 'messageAdded', message: 'Hello!' },
)

This event will be tagged with four tags: chatRoom, chatRoom:lobby, sender and sender:Alf. We already see that we can add some structure to the tags by using prefixes. ActyxOS however does not treat the : specially. The Actyx Pond contains some convenience functions based on the convention shown above.

Obviously, within the context of Actyx Pond, events usually go together with some business logic implemented in fishes. In this example we consider a fish that models a chat room. The main action that can be performed on such a room is to add a new message. The straight-forward definition given above will emit such an event according to the following event type:

type ChatRoomEvent = { type: 'messageAdded'; message: string }
note

All necessary imports (like Tags) are available from the @actyx/pond module.

We'll see in the next section about local state, how to construct a fish to make use of the emitted event.