Class: Mayu::VDOM::Descriptor
- Inherits:
-
T::Struct
- Object
- T::Struct
- Mayu::VDOM::Descriptor
show all
- Extended by:
- T::Sig
- Includes:
- Interfaces::Descriptor
- Defined in:
- lib/mayu/vdom/descriptor.rb
Defined Under Namespace
Classes: FactoryImpl
Constant Summary
collapse
- Factory =
T.let(FactoryImpl.new, FactoryImpl)
Interfaces::Descriptor::COMMENT, Interfaces::Descriptor::TEXT
Class Method Summary
collapse
Instance Method Summary
collapse
#children, #comment?, #element?, #has_children?, #hash, #itself, #key, #props, #slot, #text, #text?, #then, #type
Class Method Details
.[](type, *children, **props) ⇒ Object
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/mayu/vdom/descriptor.rb', line 88
def self.[](type, *children, **props)
type = T.let(SpecialElements.for_type(type), Component::ElementType)
children = Children.new(children, parent_type: type)
props = props.merge(children:)
key = props.delete(:key)
slot = props.delete(:slot)&.to_s
new(type:, key:, slot:, props:)
end
|
Instance Method Details
#component_class ⇒ Object
120
121
122
123
124
125
126
|
# File 'lib/mayu/vdom/descriptor.rb', line 120
def component_class
if Component.component_class?(@type)
T.cast(@type, T.class_of(Component::Base))
else
raise "#{@type.inspect} is not a component class"
end
end
|
#eql?(other) ⇒ Boolean
114
|
# File 'lib/mayu/vdom/descriptor.rb', line 114
def eql?(other) = self.class === other && same?(other)
|
#marshal_load(a) ⇒ Object
105
106
107
108
|
# File 'lib/mayu/vdom/descriptor.rb', line 105
def marshal_load(a)
@type, @props, @key, @slot = a
freeze
end
|
#same?(other) ⇒ Boolean
136
137
138
139
140
141
142
143
144
145
146
147
148
|
# File 'lib/mayu/vdom/descriptor.rb', line 136
def same?(other)
if key == other.key && type == other.type
if type == :input
props[:type] == other.props[:type]
else
true
end
else
false
end
end
|
#to_s ⇒ Object
129
130
131
132
133
|
# File 'lib/mayu/vdom/descriptor.rb', line 129
def to_s
return text if text?
return "" if
"#<Descriptor type=#{type.inspect}>"
end
|