class Volt::Listener

Listeners are returned from on on a class with Eventable included. Listeners can be stopped by calling remove

Attributes

events[R]

Public Class Methods

new(klass, events, callback) click to toggle source
# File lib/volt/reactive/eventable.rb, line 6
def initialize(klass, events, callback)
  @klass    = klass
  @events    = events
  @callback = callback
end

Public Instance Methods

call(*args) click to toggle source
# File lib/volt/reactive/eventable.rb, line 12
def call(*args)
  @callback.call(*args) unless @removed
end
inspect() click to toggle source
# File lib/volt/reactive/eventable.rb, line 34
def inspect
  "<Listener:#{object_id} events=#{@events}>"
end
instance_call(instance, *args) click to toggle source

Call the callback with self set to instance

# File lib/volt/reactive/eventable.rb, line 17
def instance_call(instance, *args)
  instance.instance_exec(*args, &@callback)
end
remove() click to toggle source
# File lib/volt/reactive/eventable.rb, line 21
def remove
  fail 'Listener has already been removed' if @removed
  @removed = true

  @events.each do |event|
    @klass.remove_listener(event, self)
  end

  # Make things easier on the GC
  @klass    = nil
  @callback = nil
end