Module: UI::Eventable

Included in:
Button, TextInput
Defined in:
flow/ui/eventable.rb

Overview

Simple placeholder implementation will need to be rewrite/improved

Instance Method Summary (collapse)

Instance Method Details

- (Object) __events__



25
26
27
# File 'flow/ui/eventable.rb', line 25

def __events__
  @__events__ ||= {}
end

- (Object) on(event, action = nil, &block)



5
6
7
8
9
10
11
# File 'flow/ui/eventable.rb', line 5

def on(event, action = nil, &block)
  if action
    __events__[event.to_sym] ||= action
  elsif block
    __events__[event.to_sym] ||= block
  end
end

- (Object) trigger(event, *args)



13
14
15
16
17
18
19
20
21
22
23
# File 'flow/ui/eventable.rb', line 13

def trigger(event, *args)
  # if no listner found we will do nothing
  return unless registered_event = __events__.fetch(event, nil)

  case registered_event
    when String, Symbol
      self.send(registered_event, *args)
    else
      registered_event.call(*args)
  end
end