In v2 of the calculator, does it make sens for the command tenses to be present?
defmodule EventSourcedCalculator.V2 do
def handle_command(%{value: _val}, %{cmd: :add, value: v}) do
%{event_type: :value_added, value: v}
end
def handle_command(%{value: _val}, %{cmd: :sub, value: v}) do
%{event_type: :value_subtracted, value: v}
end
def handle_command(%{value: _val}, %{cmd: :mul, value: v}) do
%{event_type: :value_multiplied, value: v}
end
def handle_command(%{value: _val}, %{cmd: :div, value: v}) do
%{event_type: :value_divided, value: v}
end
def handle_event(%{value: val},
%{event_type: :value_added, value: v}) do
%{value: val + v}
end
def handle_event(%{value: val},
%{event_type: :value_subtracted, value: v}) do
%{value: val - v}
end
def handle_event(%{value: val},
%{event_type: :value_multiplied, value: v}) do
%{value: val * v}
end
def handle_event(%{value: val},
%{event_type: :value_divided, value: v}) do
%{value: val / v}
end
end
For instance the command to add a value is value_added
, however, making it add_value
does 2 things. Communicates that the value has not been added yet and also allows consumers to more naturally respond to a command to add a value. It makes sense for handlers upon adding the numbers to emit value_added
as an event.
Am I misunderstanding something?