Fix child iterator

This commit is contained in:
Gabriel Tofvesson 2024-10-09 23:12:09 +02:00
parent 655ac6f4b2
commit 705ad20481

View File

@ -6,13 +6,14 @@ local Children = Prop:new{ defaultState = {}, uid = "CHILDREN" }
function Children:with(elementType)
local propSelf = self
function elementType:_iterateChildren(opts)
local func, tbl, start = ipairs(propSelf:getState(self))
local tbl = propSelf:with(self)
local start, finish = ((opts and opts.from) or 1) - 1, (opts and opts.to) or #tbl
return function(t, i)
if i == (opts and opts.to) then
return nil, nil
end
return func(t, i)
end, tbl, (opts and opts.from) or start
if i > finish then
return nil, nil
end
return i + 1, t[i + 1]
end, tbl, start
end
function elementType:childCount()
@ -20,7 +21,7 @@ function Children:with(elementType)
end
function elementType:_childAt(index)
return propSelf:getState()[elementType:_validChildIndex(index)]
return propSelf:getState(self)[elementType:_validChildIndex(index)]
end
function elementType:_validChildIndex(from)