initialState is the starting state of a Fish, before it receives its first event.
The object you pass as
initialState will never be modified by the Pond. It will be cloned whenever
needed. To observe the current state, always use
Coming up with an initial state can be tricky.
Often you model entities that have a lot of mandatory information to them. In a traditional database, you
would mark the corresponding column as
NOT NULL. In an event-based system like ActyxOS, you will
translate this into a "Creation Event" with a type that contains a field for each piece of mandatory
For the Fish representing this Process, you will want to reference it by id, and have all the information as part of its state.
There is no reason why the Fish of an unknown process should be created: The starting point is a
unique identifier that becomes known only from the
ProcessCreated event. Still, filling the
mandatory fields in the initial state is a problem.
One solution to this is to use a union type marking the different situations.
The mandatory fields are now mandatory in the correct place, but the Fish’s public API is bad:
Observers must handle states differently based on
We can fix the public API for observers by exposing a dedicated observation function: