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
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/preact/props.rb', line 32
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
|
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/preact/props.rb', line 14
def [](prop)
%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
|
#key?(k) ⇒ Boolean
25
26
27
28
29
30
|
# File 'lib/preact/props.rb', line 25
def key?(k)
%x{
if (typeof #@native.props[k] !== 'undefined') { return true; }
return false;
}
end
|
47
48
49
50
51
|
# File 'lib/preact/props.rb', line 47
def params
return @params if @params
return nil if `typeof #@native.props.params === 'undefined'`
@params = `Opal.Preact.Params.$new(#@native.props.params)`
end
|
43
44
45
|
# File 'lib/preact/props.rb', line 43
def theme
`#@native.props.iso_theme`
end
|
53
54
55
|
# File 'lib/preact/props.rb', line 53
def to_h
`Opal.Hash.$new(#@native.props)`.transform_keys!(&:underscore)
end
|
57
58
59
|
# File 'lib/preact/props.rb', line 57
def to_json
JSON.dump(to_transport)
end
|
61
62
63
|
# File 'lib/preact/props.rb', line 61
def to_n
`#@native.props`
end
|
#to_transport ⇒ Object
65
66
67
|
# File 'lib/preact/props.rb', line 65
def to_transport
{}.merge(to_h)
end
|