module Apotomo::EventMethods
Event-related methods and onfire bridge for Widget
.
Attributes
page_updates[W]
Public Instance Methods
handlers_for_event(event)
click to toggle source
Get all handlers from self for the passed event (overriding Onfire#local_event_handlers).
# 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
page_updates()
click to toggle source
# File lib/apotomo/widget/event_methods.rb, line 30 def page_updates @page_updates ||= [] end
respond_to_event(type, options={})
click to toggle source
Same as responds_to_event but executed on the widget instance, only.
# 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)
click to toggle source
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
# File lib/apotomo/widget/event_methods.rb, line 99 def trigger(*args) fire(*args) end
Protected Instance Methods
event_for(*args)
click to toggle source
# File lib/apotomo/widget/event_methods.rb, line 109 def event_for(*args) # defined in Onfire: we want Apotomo::Event. Event.new(*args) end