hanami / events

[Experimental] Events framework for Hanami
MIT License
43 stars 7 forks source link

[FIX #6] Implement subscribe_to method and Subscriber module #33

Closed smakagon closed 7 years ago

smakagon commented 7 years ago
require 'hanami/events'

$event_bus =  Hanami::Events.initialize(:memory)

class Foo
  include Hanami::Events::Mixin

  subscribe_to $event_bus, 'user.created'

  def call(payload)
    puts payload
  end
end

$event_bus.broadcast('user.created', user_id: 1)

Global variable is just an example, probably in app it would be good to have container that would return event bus.

One problem I have with current implementation, that call method will not see logger passed during initialization of event bus.