Class: React::VivifyModule

Inherits:
Module
  • Object
show all
Defined in:
lib/react/vivify_module.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(component_name, *args, &block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/react/vivify_module.rb', line 7

def method_missing(component_name, *args, &block)
  # check for ruby component and render it
  # otherwise pass on method missing
  # language=JS
  %x{
    var constant;
    var component = null;
    var modules = self.$to_s().split("::");
    var modules_length = modules.length;
    var module;
    for (var i = modules_length; i > 0; i--) {
      try {
        module = modules.slice(0, i).join('::');
        constant = self.$const_get(module).$const_get(component_name, false);
        if (typeof constant.react_component !== 'undefined') {
          component = constant.react_component;
          break;
        }
      } catch(err) { component = null; }
    }
    if (!component) {
      try {
        constant = Opal.Object.$const_get(component_name);
        if (typeof constant.react_component !== 'undefined') {
          component = constant.react_component;
        }
      } catch(err) { component = null; }
    }
    if (component) {
      return Opal.React.internal_prepare_args_and_render(component, args, block);
    } else {
      return #{_react_component_class_resolution_original_method_missing(component_name, *args, block)};
    }
  }
end

Instance Method Details

#_react_component_class_resolution_original_method_missingObject

this is required for autoloading support, as the component may not be loaded and so its method is not registered. must load it first, done by const_get, and next time the method will be there.



5
# File 'lib/react/vivify_module.rb', line 5

alias _react_component_class_resolution_original_method_missing method_missing