Class: Preact::Component::Props

Inherits:
Object
  • Object
show all
Defined in:
lib/preact/component/props.rb

Instance Method Summary collapse

Constructor Details

#initialize(native) ⇒ Props



4
5
6
# File 'lib/preact/component/props.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
17
# File 'lib/preact/component/props.rb', line 8

def method_missing(prop, *args, &block)
  %x{
    const p = #@native.props;
    if (typeof p[prop] === 'undefined') {
      prop = Opal.Preact.lower_camelize(prop);
      if (typeof p[prop] === 'undefined') { return nil; }
    }
    return p[prop];
  }
end

Instance Method Details

#childrenObject



19
20
21
# File 'lib/preact/component/props.rb', line 19

def children
  @native.JS[:props].JS[:children]
end

#isomorfeus_storeObject



23
24
25
26
# File 'lib/preact/component/props.rb', line 23

def isomorfeus_store
  # TODO

  @native.JS[:props].JS[:isomorfeus_store]
end

#paramsObject



32
33
34
35
36
# File 'lib/preact/component/props.rb', line 32

def params
  return @params if @params
  return nil if `typeof #@native.props.params === 'undefined'`
  @params = ::Preact::Component::Params.new(`#@native.props.params`)
end

#themeObject



28
29
30
# File 'lib/preact/component/props.rb', line 28

def theme
  `#@native.props.iso_theme`
end

#to_hObject



38
39
40
# File 'lib/preact/component/props.rb', line 38

def to_h
  `Opal.Hash.$new(#@native.props)`.transform_keys!(&:underscore)
end

#to_jsonObject



42
43
44
# File 'lib/preact/component/props.rb', line 42

def to_json
  JSON.dump(to_transport)
end

#to_nObject



46
47
48
# File 'lib/preact/component/props.rb', line 46

def to_n
  @native.JS[:props]
end

#to_transportObject



50
51
52
# File 'lib/preact/component/props.rb', line 50

def to_transport
  {}.merge(to_h)
end