Class: React::Component::Styles

Inherits:
Object
  • Object
show all
Defined in:
lib/react/component/styles.rb

Instance Method Summary collapse

Constructor Details

#initialize(native) ⇒ Styles

Returns a new instance of Styles.



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

def initialize(native)
  @native = native
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



8
9
10
11
12
13
14
15
16
# File 'lib/react/component/styles.rb', line 8

def method_missing(prop, *args, &block)
  %x{
    if (!#@native || typeof #@native[prop] === 'undefined') { return #{nil}; }
    let value = #@native[prop];
    if (typeof value === 'string' || typeof value === 'number' || Array.isArray(value)) { return value; }
    if (typeof value === 'function') { return #{Proc.new { `value()` }} }
    return Opal.React.Component.Styles.$new(value);
  }
end

Instance Method Details

#to_hObject



18
19
20
# File 'lib/react/component/styles.rb', line 18

def to_h
  `Opal.Hash.$new(#@native)`
end

#to_nObject



22
23
24
# File 'lib/react/component/styles.rb', line 22

def to_n
  @native
end