Chronik v0.1.10 Chronik.Aggregate.Multi View Source
Chronik.Aggregate.Multi
can be used to generate a single commmand
that affects multiple entities.
As can be seen on the test a multiple-entity command can be defined as:
Example
alias Chronik.Aggregate.Multi
def handle_command({:update_name_and_max, name, max}, %Counter{id: id} = state) do
state
|> Multi.new(__MODULE__)
|> Multi.delegate(&(&1.name), &rename(&1, id, name))
|> Multi.delegate(&(&1.max), &update_max(&1, id, max))
|> Multi.run()
end
This command affects both the :name
entity and the :max
entity
in a transaction like manner. The update_max/3
receives the
updated aggregate state.
Link to this section Summary
Functions
Applies val_fun
on a given entity
Create a new state for a multi-entity command
Run a concatenation of entities updates and return the domain events generated
Applies the val_fun
function on the aggregate state
Link to this section Types
monad_state() :: {Chronik.Aggregate.state(), [Chronik.domain_event()], module()}
Link to this section Functions
delegate( ms :: monad_state(), lens :: (... -> any()), validator_fun :: (... -> any()) ) :: monad_state()
Applies val_fun
on a given entity.
The state of the entity is obtained using the lens_fun
function.
new(state :: Chronik.Aggregate.state(), module :: module()) :: monad_state()
Create a new state for a multi-entity command.
Run a concatenation of entities updates and return the domain events generated.
validate(ms :: monad_state(), validator_fun :: (... -> any())) :: monad_state()
Applies the val_fun
function on the aggregate state.