Cqrs.DomainEvent (cqrs_tools v0.2.18) View Source

Defines a new domain event struct

Options

  • :from optional - a struct to derive fields from.
  • :with optional - a list of atom field names to add.
  • :drop optional - a list of atom field names to remove from any field derived from the struct in the :from option.
  • :version optional - a version value. Defaults to 1

Example

defmodule DeleteUser do
  use Cqrs.Command

  field :id, :integer

  def handle_dispatch(command, _opts) do
    {:ok, :no_impl}
  end
end

defmodule UserDeleted do
  use Cqrs.DomainEvent,
    from: DeleteUser,
    with: [:from],
    version: 2
end

iex> cmd = DeleteUser.new!(id: 668)
...> event = UserDeleted.new(cmd, from: "chris")
...> %{id: event.id, from: event.from, version: event.version}
%{id: 668, from: "chris", version: 2}