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
# File 'lib/react/component/event_handler.rb', line 8

def event_handler(name, &block)
  event_handlers << name
  %x{
    var fun = 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)};
    }
    if (self.lucid_react_component) { self.lucid_react_component.prototype[name] = fun; }
    else { self.react_component.prototype[name] = fun; }
  }
end

#event_handlersObject



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

def event_handlers
  @event_handlers ||= []
end