Skuld.Effects.EventAccumulator.IEvent protocol (skuld v0.1.26)
View SourceProtocol for tagging events for grouping.
This protocol is provided for consumers of the event log who want to group events by type. The accumulator itself does not use this protocol - it simply accumulates all events in a list.
Example
alias Skuld.Effects.EventAccumulator.IEvent
# Get events grouped by tag
{result, events} = comp |> EventAccumulator.with_handler(output: &{&1, &2}) |> Comp.run!()
events_by_tag = Enum.group_by(events, &IEvent.tag/1)Default Behavior
By default (via the Any implementation), structs are tagged
by their module name:
IEvent.tag(%MyApp.UserCreated{user_id: 1})
#=> MyApp.UserCreatedCustom Implementation
You can implement the protocol for custom grouping:
defimpl Skuld.Effects.EventAccumulator.IEvent, for: MyApp.DomainEvent do
def tag(%{aggregate_type: type}), do: type
end
Summary
Functions
Returns the tag for grouping this event.
Types
@type t() :: term()
All the types that implement this protocol.