Module: React::Component::Resolution
- Included in:
- Object
- Defined in:
- lib/react/component/resolution.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(component_name, *args, &block) ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/react/component/resolution.rb', line 70
def method_missing(component_name, *args, &block)
%x{
var component = null;
if (typeof Opal.global[component_name] !== "undefined" && (component_name[0] === component_name[0].toUpperCase())) {
component = Opal.global[component_name];
} else {
var modules = self.$to_s().split("::");
var modules_length = modules.length;
var module;
var constant;
for (var i = modules_length; i > 0; i--) {
try {
module = modules.slice(0, i).join('::');
constant = self.$class().$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_resolution_original_method_missing(component_name, *args, block)};
}
}
end
|
Class Method Details
.included(base) ⇒ Object
4
5
6
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/react/component/resolution.rb', line 4
def self.included(base)
base.instance_exec do
alias _react_component_class_resolution_original_const_missing const_missing
def const_missing(const_name)
%x{
if (typeof Opal.global[const_name] !== "undefined" && (const_name[0] === const_name[0].toUpperCase())) {
var new_const = #{React::NativeConstantWrapper.new(`Opal.global[const_name]`, const_name)};
#{Object.const_set(const_name, `new_const`)};
return new_const;
} else {
return #{_react_component_class_resolution_original_const_missing(const_name)};
}
}
end
unless method_defined?(:_react_component_class_resolution_original_method_missing)
alias _react_component_class_resolution_original_method_missing method_missing
end
def method_missing(component_name, *args, &block)
%x{
var modules = self.$to_s().split("::");
var modules_length = modules.length;
var module;
var constant;
var component;
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
end
end
|
Instance Method Details
#_react_component_resolution_original_method_missing ⇒ Object
67
|
# File 'lib/react/component/resolution.rb', line 67
alias _react_component_resolution_original_method_missing method_missing
|