Class: Preact::Props
Instance Method Summary
collapse
Constructor Details
#initialize(native) ⇒ Props
Returns a new instance of Props.
3
4
5
|
# File 'lib/preact/props.rb', line 3
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
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/preact/props.rb', line 14
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
#==(other_props) ⇒ Object
7
8
9
10
11
12
|
# File 'lib/preact/props.rb', line 7
def ==(other_props)
%x{
if (Opal.Preact.props_are_equal(#@native.props, #{other_props.to_n})) { return true; }
return false;
}
end
|
29
30
31
32
33
|
# File 'lib/preact/props.rb', line 29
def params
return @params if @params
return nil if `typeof #@native.props.params === 'undefined'`
@params = ::Preact::Component::Params.new(`#@native.props.params`)
end
|
25
26
27
|
# File 'lib/preact/props.rb', line 25
def theme
`#@native.props.iso_theme`
end
|
35
36
37
|
# File 'lib/preact/props.rb', line 35
def to_h
`Opal.Hash.$new(#@native.props)`.transform_keys!(&:underscore)
end
|
39
40
41
|
# File 'lib/preact/props.rb', line 39
def to_json
JSON.dump(to_transport)
end
|
43
44
45
|
# File 'lib/preact/props.rb', line 43
def to_n
`#@native.props`
end
|
#to_transport ⇒ Object
47
48
49
|
# File 'lib/preact/props.rb', line 47
def to_transport
{}.merge(to_h)
end
|