Module: TerminalLayout::EventEmitter

Included in:
Box, RenderObject, TerminalRenderer
Defined in:
lib/terminal_layout.rb

Instance Method Summary collapse

Instance Method Details

#_callbacksObject



10
11
12
# File 'lib/terminal_layout.rb', line 10

def _callbacks
  @_callbacks ||= Hash.new { |h, k| h[k] = [] }
end

#emit(type, *args) ⇒ Object



23
24
25
26
27
# File 'lib/terminal_layout.rb', line 23

def emit(type, *args)
  _callbacks[type].each do |blk|
    blk.call(*args)
  end
end

#on(type, *args, &blk) ⇒ Object



14
15
16
17
# File 'lib/terminal_layout.rb', line 14

def on(type, *args, &blk)
  _callbacks[type] << blk
  self
end

#unsubscribeObject



19
20
21
# File 'lib/terminal_layout.rb', line 19

def unsubscribe
  _callbacks.clear
end