Skip to content

Commit

Permalink
remove self.children
Browse files Browse the repository at this point in the history
  • Loading branch information
Rathoz committed Oct 14, 2024
1 parent 9202034 commit 791406f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 25 deletions.
10 changes: 3 additions & 7 deletions components/widget/widget.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ local Widget = Class.new(function(self, props)
self.props = Table.copy(props) or {}
self.props.children = self.props.children or {}
self.context = {} -- Populated by the parent
---@deprecated Widget v1 backwards compability
self.children = self.children or self.props.children
end)

---Asserts the existence of a value and copies it
Expand Down Expand Up @@ -54,10 +52,8 @@ function Widget:tryMake(injector)
-- Widget v1 backwards compability
renderComponent = function()
local processedChildren = self:tryChildren(injector)
if self.render == Widget.render then
local ret = self:make(processedChildren)
return ret ~= nil and ret or ''
end
local ret = self:make(processedChildren)
return ret ~= nil and ret or ''
end
else
renderComponent = function()
Expand Down Expand Up @@ -92,7 +88,7 @@ end
---@param injector WidgetInjector?
---@return string[]
function Widget:tryChildren(injector)
local children = self.children
local children = self.props.children
if self.makeChildren then
children = self:makeChildren(injector) or {}
end
Expand Down
19 changes: 3 additions & 16 deletions components/widget/widget_builder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,11 @@ local Widget = Lua.import('Module:Widget')

---@class BuilderWidget: Widget
---@operator call({builder: function}): BuilderWidget
---@field builder fun(): Widget[]
local Builder = Class.new(
Widget,
function(self, input)
self.builder = input.builder
end
)
local Builder = Class.new(Widget)

---@param children string[]
---@return string
function Builder:make(children)
return table.concat(children)
end

---@param injector WidgetInjector?
---@return Widget[]?
function Builder:makeChildren(injector)
return self.builder()
function Builder:render()
return self.props.builder()
end

return Builder
4 changes: 2 additions & 2 deletions components/widget/widget_customizable.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ end
---@return Widget[]?
function Customizable:makeChildren(injector)
if injector == nil then
return self.children
return self.props.children
end
return injector:parse(self.id, self.children)
return injector:parse(self.id, self.props.children)
end

return Customizable

0 comments on commit 791406f

Please sign in to comment.