Module: React::FunctionComponent::Resolution
- Included in:
- Runner
- Defined in:
- lib/react/function_component/resolution.rb
Class Method Summary collapse
Instance Method Summary collapse
- #_react_component_resolution_original_method_missing ⇒ Object
- #method_missing(component_name, *args, &block) ⇒ Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(component_name, *args, &block) ⇒ Object
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 |
# File 'lib/react/function_component/resolution.rb', line 24 def method_missing(component_name, *args, &block) # html tags are defined as methods, so they will not end up here. # first check for native component and render it, we want to be fast for native components # second check for ruby component and render it, they are a bit slower anyway # third pass on method missing %x{ var component = null; if (typeof Opal.global[component_name] == "function") { component = Opal.global[component_name]; } else { try { var constant = self.$class().$const_get(component_name, true); if (typeof constant.react_component == "function") { component = constant.react_component; } } catch(err) { component = null; } } if (component) { var props = null; if (args.length > 0) { var last_arg = args[args.length - 1]; if (typeof last_arg === 'string' || last_arg instanceof String) { if (args.length === 1) { Opal.React.internal_render(component, null, last_arg, null); } else { Opal.React.internal_render(component, args[0], last_arg, null); } } else { Opal.React.internal_render(component, args[0], null, block); } } else { Opal.React.internal_render(component, null, null, 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 |
# File 'lib/react/function_component/resolution.rb', line 4 def self.included(base) base.instance_exec do alias _react_component_resolution_original_const_missing const_missing def const_missing(const_name) %x{ if (typeof Opal.global[const_name] == "object") { 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_resolution_original_const_missing(const_name)}; } } end end end |
Instance Method Details
#_react_component_resolution_original_method_missing ⇒ Object
22 |
# File 'lib/react/function_component/resolution.rb', line 22 alias _react_component_resolution_original_method_missing method_missing |