Skip to content

Commit

Permalink
simplify widget
Browse files Browse the repository at this point in the history
  • Loading branch information
Rathoz committed Oct 14, 2024
1 parent 8ae6e79 commit 9633f11
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions components/widget/widget.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ local Table = require('Module:Table')

---@class Widget: BaseClass
---@operator call(table): self
---@field children (Widget|Html|string|number)[] @deprecated
---@field context Widget[]
---@field props table<string, any>
---@field injector WidgetInjector?
Expand All @@ -42,25 +41,25 @@ end
---@param injector WidgetInjector?
---@return string
function Widget:tryMake(injector)
local renderComponent = function()
local function renderComponent()
self.injector = injector
local ret = self:render()
if not Array.isArray(ret) then
ret = {ret}
end

---@cast ret (string|Widget|Html|nil)[]
return Array.reduce(ret, function(acc, val)

return table.concat(Array.map(ret, function(val)
if Class.instanceOf(val, Widget) then
---@cast val Widget
val.context = self:_nextContext()
return acc .. val:tryMake(injector)
return val:tryMake(injector)
end
if val ~= nil then
return acc .. tostring(val)
return tostring(val)
end
return acc
end, '')
return nil
end))
end

return Logic.tryOrElseLog(
Expand Down

0 comments on commit 9633f11

Please sign in to comment.