lib/volt/reactive/events.rb
# Add a listener for an event
Add a listener for an event
Add a listener for an event
def on(event, scope_provider=nil, &block)
    event = event.to_sym
    @has_listeners = true
    new_listener = Listener.new(self, event, scope_provider, block)
    @listeners ||= {}
    @listeners[event] ||= []
    @listeners[event] << new_listener
    first_for_event = @listeners[event].size == 1
    first = first_for_event && @listeners.size == 1
    event_chain.add_event(event) if first_for_event
    if self.respond_to?(:event_added)
      self.event_added(event, scope_provider, first, first_for_event)
    end
    return new_listener
  end
def on ( event , scope_provider = nil , & block ) event = event . to_sym @has_listeners = true new_listener = Listener . new ( self , event , scope_provider , block ) @listeners ||= { } @listeners [ event ] ||= [ ] @listeners [ event ] << new_listener first_for_event = @listeners [ event ] . size == 1 first = first_for_event && @listeners . size == 1 event_chain . add_event ( event ) if first_for_event if self . respond_to? ( :event_added ) self . event_added ( event , scope_provider , first , first_for_event ) end return new_listener end
Add a listener for an event
Add a listener for an event
# When events get added, we need to notify event chains so they # can update and chain any new events. # Let the included class know that an event was registered. (if it cares) # call event added passing the event, the scope, and a boolean if it # is the first time this event has been added.
event
scope_provider
block