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
-
#handlers_for_event(event) ⇒ Object
Get all handlers from self for the passed event (overriding Onfire#local_event_handlers).
-
#respond_to_event(type, options = {}) ⇒ Object
Same as #responds_to_event but executed on the widget instance, only.
-
#trigger(*args) ⇒ Object
Fire an event of
type
and let it bubble up.
Instance Attribute Details
#page_updates ⇒ Object
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, ={}) # DISCUSS: do we need the :once option? how could we avoid re-adding? = .reverse_merge(:once => true, :with => type, :on => ) handler = InvokeEventHandler.new(:widget_id => [:on], :state => [:with]) return if [:once] and event_table.all_handlers_for(type, [:from]).include?(handler) on(type, :call => handler, :from => [: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 |