Sha256: 54c53037a0366a6d39402f233bef043b90da587968df3c1d5c3e3a015307cd37
Contents?: true
Size: 972 Bytes
Versions: 11
Compression:
Stored size: 972 Bytes
Contents
module Mittsu module EventDispatcher Event = Struct.new(:type, :target) def add_event_listener(type, listener) @_listeners ||= {} @_listeners[type] ||= [] if !@_listeners[type].include? listener @_listeners[type] << (listener) end end def has_event_listener(type, listener) return false if @_listeners.nil? return false if @_listeners[type].nil? @_listeners[type].include? listener end def remove_event_listener(type, listener) return if @_listeners.nil? listener_array = @_listeners[type] if listener_array listener_array.delete(listener) end end 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 end end
Version data entries
11 entries across 11 versions & 1 rubygems