lib/volt/reactive/events.rb
# Add a listener for an event
Add a listener for an event
Add a listener for an event
def trigger!(event, filter=nil, *args)
    are_reactive = reactive?
    event = event.to_sym
    if @listeners && @listeners[event]
      @listeners[event].dup.each do |listener|
        if (!filter || (!are_reactive && listener.scope_provider.reactive?) || filter.call(listener.scope))
          listener.call(filter, *args)
        end
      end
    end
    nil
  end
def trigger! ( event , filter = nil , * args ) are_reactive = reactive? event = event . to_sym if @listeners && @listeners [ event ] @listeners [ event ] . dup . each do | listener | if ( ! filter || ( ! are_reactive && listener . scope_provider . reactive? ) || filter . call ( listener . scope ) ) listener . call ( filter , * args ) end end end nil end
Add a listener for an event
Add a listener for an event
# puts "TRIGGER: #{event} on #{self.inspect}" if event == :added # TODO: We have to dup here because one trigger might remove another # Call the event on each listener # If there is no listener, that means another event trigger removed it. # If there is no filter, call # if we aren't reactive, we should pass to all of our reactive listeners, since they # just proxy us. # If the filter exists, check it
event
filter
args