Class: Mayu::Component::Base
- Inherits:
-
Object
- Object
- Mayu::Component::Base
show all
- Extended by:
- T::Helpers, T::Sig
- Defined in:
- lib/mayu/component/base.rb
Constant Summary
collapse
- INLINE_CSS_ASSETS =
T.let([], T::Array[String])
Class Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(wrapper) ⇒ Base
Returns a new instance of Base.
77
78
79
|
# File 'lib/mayu/component/base.rb', line 77
def initialize(wrapper)
@__wrapper = wrapper
end
|
Class Attribute Details
.__mayu_resource ⇒ Object
52
53
54
|
# File 'lib/mayu/component/base.rb', line 52
def __mayu_resource
@__mayu_resource
end
|
Class Method Details
.__mayu_resource! ⇒ Object
57
58
59
|
# File 'lib/mayu/component/base.rb', line 57
def __mayu_resource!
@__mayu_resource or raise "__mayu_resource is not set"
end
|
.__mayu_resource? ⇒ Boolean
62
63
64
|
# File 'lib/mayu/component/base.rb', line 62
def __mayu_resource?
!!@__mayu_resource
end
|
.assets ⇒ Object
123
124
125
126
127
|
# File 'lib/mayu/component/base.rb', line 123
def self.assets
[self.stylesheet&.assets, const_get(:INLINE_CSS_ASSETS)].flatten
.compact
.map(&:filename)
end
|
.get_derived_state_from_props(props, state) ⇒ Object
72
73
74
|
# File 'lib/mayu/component/base.rb', line 72
def self.get_derived_state_from_props(props, state)
nil
end
|
.get_initial_state(**props) ⇒ Object
34
35
36
|
# File 'lib/mayu/component/base.rb', line 34
def self.get_initial_state(**props)
{}
end
|
.initialize ⇒ Object
42
43
44
45
|
# File 'lib/mayu/component/base.rb', line 42
def initialize
@__mayu_resource = T.let(nil, T.nilable(Resources::Resource))
end
|
.setup_component(styles:, assets:) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/mayu/component/base.rb', line 18
def self.setup_component(styles:, assets:)
T.unsafe(
class << self
self
end
).undef_method(T.must(__method__))
const_set(
:MAYU,
{ styles: styles.freeze, assets: assets.freeze }.freeze
)
self
end
|
.stylesheet ⇒ Object
131
|
# File 'lib/mayu/component/base.rb', line 131
def self.stylesheet = nil
|
.stylesheet! ⇒ Object
133
134
135
|
# File 'lib/mayu/component/base.rb', line 133
def self.stylesheet! =
stylesheet ||
raise(RuntimeError, "There is no stylesheet for this component!")
|
Instance Method Details
#async(&blk) ⇒ Object
144
|
# File 'lib/mayu/component/base.rb', line 144
def async(&blk) = @__wrapper.async(&blk)
|
#children ⇒ Object
174
|
# File 'lib/mayu/component/base.rb', line 174
def children = props[:children]
|
#did_update(prev_props, prev_state) ⇒ Object
117
118
|
# File 'lib/mayu/component/base.rb', line 117
def did_update(prev_props, prev_state)
end
|
#handler(name, *args, **kwargs) ⇒ Object
155
156
157
|
# File 'lib/mayu/component/base.rb', line 155
def handler(name, *args, **kwargs)
HandlerRef.new(self, name, args, kwargs)
end
|
#mayu ⇒ Object
Also known as:
helpers
160
|
# File 'lib/mayu/component/base.rb', line 160
def mayu = @__wrapper.helpers
|
#mount ⇒ Object
89
90
|
# File 'lib/mayu/component/base.rb', line 89
def mount
end
|
#props ⇒ Object
84
|
# File 'lib/mayu/component/base.rb', line 84
def props = mayu.props
|
#render ⇒ Object
147
148
|
# File 'lib/mayu/component/base.rb', line 147
def render
end
|
#should_update?(next_props, next_state) ⇒ Boolean
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/mayu/component/base.rb', line 101
def should_update?(next_props, next_state)
case
when props != next_props
true
when state != next_state
true
else
false
end
end
|
#state ⇒ Object
82
|
# File 'lib/mayu/component/base.rb', line 82
def state = mayu.state
|
#styles ⇒ Object
141
|
# File 'lib/mayu/component/base.rb', line 141
def styles = self.class.styles
|
#unmount ⇒ Object
93
94
|
# File 'lib/mayu/component/base.rb', line 93
def unmount
end
|
#update(state = nil, &blk) ⇒ Object
169
170
171
|
# File 'lib/mayu/component/base.rb', line 169
def update(state = nil, &blk)
@__wrapper.update(state, &blk)
end
|
#vnode_id ⇒ Object
86
|
# File 'lib/mayu/component/base.rb', line 86
def vnode_id = @__wrapper.vnode_id
|