envato / event_sourcery

A library for building event sourced applications in Ruby
MIT License
84 stars 10 forks source link

AggregateRoot#apply_event accepts hash #69

Closed orien closed 8 years ago

orien commented 8 years ago

In a way consistent with Reactor#emit_event, wouldn't it be great if apply_event could accept a hash of event attributes? Then our aggregate mutators would be even simpler:

    class Soul
      include EventSourcery::Command::AggregateRoot

      def sell(payload)
        apply_event(type: :soul_sold, body: payload)
      end

      private

      def apply_soul_sold(_)
      end
    end

Compared to the current requirements where the aggregate must instantiate an Event:

      def sell(payload)
        apply_event(
          EventSourcery::Event.new(type: :soul_sold, body: payload)
        )
      end