Module: Mittsu::EventDispatcher

Included in:
BufferGeometry, Geometry, MTLLoader, Material, OBJLoader, OBJMTLLoader, Object3D, RenderTarget, STLLoader, Texture
Defined in:
lib/mittsu/core/event_dispatcher.rb

Defined Under Namespace

Classes: Event

Instance Method Summary collapse

Instance Method Details

#add_event_listener(type, listener) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/mittsu/core/event_dispatcher.rb', line 5

def add_event_listener(type, listener)
  @_listeners ||= {}
  @_listeners[type] ||= []
  if !@_listeners[type].include? listener
    @_listeners[type] << (listener)
  end
end

#dispatch_event(event = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/mittsu/core/event_dispatcher.rb', line 27

def dispatch_event(event = {})
  return if @_listeners.nil?
  listener_array = @_listeners[event[:type]]
  if listener_array
    evt = Event.new(event[:type], self)
    array = listener_array.dup
    array.each do |l|
      l.call(evt)
    end
  end
end

#has_event_listener(type, listener) ⇒ Object



13
14
15
16
17
# File 'lib/mittsu/core/event_dispatcher.rb', line 13

def has_event_listener(type, listener)
  return false if @_listeners.nil?
  return false if @_listeners[type].nil?
  @_listeners[type].include? listener
end

#remove_event_listener(type, listener) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/mittsu/core/event_dispatcher.rb', line 19

def remove_event_listener(type, listener)
  return if @_listeners.nil?
  listener_array = @_listeners[type]
  if listener_array
    listener_array.delete(listener)
  end
end