Module: RETerm::EventDispatcher

Included in:
Component, Panel, Window
Defined in:
lib/reterm/mixins/event_dispatcher.rb

Overview

Helper mixin defining methods to register event handlers and dispatch events. Events are simply composed parameters which are passed to the callback blocks when dispatched

Instance Method Summary collapse

Instance Method Details

#dispatch(e, h = {}) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/reterm/mixins/event_dispatcher.rb', line 7

def dispatch(e, h={})
  @event_handlers ||= {}
  @event_handlers[e].each { |eh|
    eh.call h
  } if @event_handlers.key?(e)

  nil # return last handler return value or perhaps all ?
end

#handle(e, &bl) ⇒ Object



16
17
18
19
20
# File 'lib/reterm/mixins/event_dispatcher.rb', line 16

def handle(e, &bl)
  @event_handlers    ||= {}
  @event_handlers[e] ||= []
  @event_handlers[e]  << bl
end