Module: Apotomo::EventMethods

Extended by:
ActiveSupport::Concern
Included in:
Widget
Defined in:
lib/apotomo/widget/event_methods.rb

Overview

Event-related methods and onfire bridge for Widget.

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#page_updatesObject


30
31
32
# File 'lib/apotomo/widget/event_methods.rb', line 30

def page_updates
  @page_updates ||= []
end

Instance Method Details

#handlers_for_event(event) ⇒ Object

Get all handlers from self for the passed event (overriding Onfire#local_event_handlers).


104
105
106
# File 'lib/apotomo/widget/event_methods.rb', line 104

def handlers_for_event(event)
  event_table.all_handlers_for(event.type, event.source.name) # we key with widget_id.
end

#respond_to_event(type, options = {}) ⇒ Object

Same as #responds_to_event but executed on the widget instance, only.


77
78
79
80
81
82
83
84
85
86
87
# File 'lib/apotomo/widget/event_methods.rb', line 77

def respond_to_event(type, options={})
  # DISCUSS: do we need the :once option? how could we avoid re-adding?
  options = options.reverse_merge(:once => true,
                                  :with => type,
                                  :on   => widget_id)
  
  handler = InvokeEventHandler.new(:widget_id => options[:on], :state => options[:with])
  return if options[:once] and event_table.all_handlers_for(type, options[:from]).include?(handler)
  
  on(type, :call => handler, :from => options[:from])
end

#trigger(*args) ⇒ Object

Fire an event of type and let it bubble up. You may add arbitrary payload data to the event.

Example:

trigger(:dropped, :area => 59)

which can be queried in a triggered state.

def on_drop(event)
  if event[:area] == 59

99
100
101
# File 'lib/apotomo/widget/event_methods.rb', line 99

def trigger(*args)
  fire(*args)
end