Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
Co-authored-by: Szymon Fiedler <[email protected]>
Co-authored-by: Piotr Jurewicz <[email protected]>
  • Loading branch information
3 people committed Nov 22, 2023
1 parent 9538026 commit 0c1cc52
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions examples/decider/lib/project_management/command_handler.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
module ProjectManagement
class CommandHandler
def initialize(event_store) = @event_store = event_store
def initialize(event_store)
@event_store = event_store
@decider = Issue
end


def handle(cmd)
state, version =
@event_store
.read
.stream(stream_name(cmd.id))
.reduce(
[Issue.initial_state(cmd.id), -1]
[@decider.initial_state(cmd.id), -1]
) do |(state, version), event|
[Issue.evolve(state, event), version + 1]
[@decider.evolve(state, event), version + 1]
end

case result = Issue.decide(cmd, state)
case result = @decider.decide(cmd, state)
when StandardError
raise Error
else
Expand Down

0 comments on commit 0c1cc52

Please sign in to comment.