Module: TerminalLayout::EventEmitter
- Included in:
- Box, RenderObject, Renderer
- Defined in:
- lib/terminal_layout/event_emitter.rb
Instance Method Summary collapse
- #_callbacks ⇒ Object
- #emit(type, *args) ⇒ Object
- #on(type, *args, &blk) ⇒ Object
- #unsubscribe ⇒ Object
Instance Method Details
#_callbacks ⇒ Object
3 4 5 |
# File 'lib/terminal_layout/event_emitter.rb', line 3 def _callbacks @_callbacks ||= Hash.new { |h, k| h[k] = [] } end |
#emit(type, *args) ⇒ Object
16 17 18 19 20 |
# File 'lib/terminal_layout/event_emitter.rb', line 16 def emit(type, *args) _callbacks[type].each do |blk| blk.call(*args) end end |
#on(type, *args, &blk) ⇒ Object
7 8 9 10 |
# File 'lib/terminal_layout/event_emitter.rb', line 7 def on(type, *args, &blk) _callbacks[type] << blk self end |
#unsubscribe ⇒ Object
12 13 14 |
# File 'lib/terminal_layout/event_emitter.rb', line 12 def unsubscribe _callbacks.clear end |