Class: Listener

Inherits:
Object show all
Defined in:
lib/volt/reactive/eventable.rb

Instance Method Summary collapse

Constructor Details

#initialize(klass, event, callback) ⇒ Listener

Returns a new instance of Listener.



2
3
4
5
6
# File 'lib/volt/reactive/eventable.rb', line 2

def initialize(klass, event, callback)
  @klass = klass
  @event = event
  @callback = callback
end

Instance Method Details

#call(*args) ⇒ Object



8
9
10
# File 'lib/volt/reactive/eventable.rb', line 8

def call(*args)
  @callback.call(*args) unless @removed
end

#inspectObject



22
23
24
# File 'lib/volt/reactive/eventable.rb', line 22

def inspect
  "<Listener:#{object_id} event=#{@event}>"
end

#removeObject



12
13
14
15
16
17
18
19
20
# File 'lib/volt/reactive/eventable.rb', line 12

def remove
  @removed = true

  @klass.remove_listener(@event, self)

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