Class: React::NativeConstantWrapper

Inherits:
Object
  • Object
show all
Includes:
Native::Wrapper
Defined in:
lib/react/native_constant_wrapper.rb

Instance Method Summary collapse

Constructor Details

#initialize(native, const_name) ⇒ NativeConstantWrapper

Returns a new instance of NativeConstantWrapper.



5
6
7
8
# File 'lib/react/native_constant_wrapper.rb', line 5

def initialize(native, const_name)
  @native = native
  @const_name = const_name
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/react/native_constant_wrapper.rb', line 10

def method_missing(name, *args, &block)
  # language=JS
  %x{
    var component = null;
    var component_type = typeof #@native[name];
    if (component_type === "function" || component_type === "object") {
      component = #@native[name];
    }
    if (component) {
      return Opal.React.internal_prepare_args_and_render(component, args, block);
    } else {
      #{raise NameError, "No such native Component #@const_name.#{name}"};
    }
  }
end