OnePiece.Commanded.Aggregate behaviour (OnePiece.Commanded v0.4.1) View Source

Defines the an OnePiece.Commanded.Aggregate behaviour.

Link to this section Summary

Callbacks

Apply a given event to the aggregate returning the new aggregate state.

Functions

Convert the module into a Aggregate behaviour.

Link to this section Types

Link to this section Callbacks

Specs

apply(aggregate :: t(), event :: event()) :: t()

Apply a given event to the aggregate returning the new aggregate state.

Example

def apply(account, event) do
  account
  |> Map.put(:name, event.name)
  |> Map.put(:description, event.description)
end

Link to this section Functions

Link to this macro

__using__(opts \\ [])

View Source (macro)

Specs

__using__(opts :: []) :: any()

Convert the module into a Aggregate behaviour.

Usage

defmodule Account do
  use OnePiece.Commanded.Aggregate

  @impl OnePiece.Commanded.Aggregate
  def apply(account, event) do
    account
    |> Map.put(:name, event.name)
    |> Map.put(:description, event.description)
  end
end