Module: React::Component::EventHandler

Defined in:
lib/react/component/event_handler.rb

Instance Method Summary collapse

Instance Method Details

#event_handler(name, &block) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/react/component/event_handler.rb', line 8

def event_handler(name, &block)
  event_handlers << name
  %x{
    self.react_component.prototype[name] = function(event, info) {
      if (typeof event === "object") {
        #{ruby_event = ::React::SyntheticEvent.new(`event`)};
      } else {
        #{ruby_event = `event`};
      }
      #{`this.__ruby_instance`.instance_exec(ruby_event, `info`, &block)};
    }
  }
end

#event_handlersObject



4
5
6
# File 'lib/react/component/event_handler.rb', line 4

def event_handlers
  @event_handlers ||= []
end