[XML] Child layouts #75
@@ -183,6 +183,12 @@ end
|
||||
return {
|
||||
basalt = function(basalt)
|
||||
local object = {
|
||||
layout = function(path)
|
||||
return {
|
||||
path = path,
|
||||
}
|
||||
end,
|
||||
|
||||
reactive = function(initialValue)
|
||||
local value = initialValue
|
||||
local observerEffects = {}
|
||||
@@ -207,10 +213,10 @@ return {
|
||||
end,
|
||||
|
||||
untracked = function(getter)
|
||||
local prevEffect = currentEffect
|
||||
local parentEffect = currentEffect
|
||||
currentEffect = nil
|
||||
local value = getter()
|
||||
currentEffect = prevEffect
|
||||
currentEffect = parentEffect
|
||||
return value
|
||||
end,
|
||||
|
||||
@@ -218,10 +224,10 @@ return {
|
||||
local effect = {dependencies = {}}
|
||||
local execute = function()
|
||||
clearEffectDependencies(effect)
|
||||
local prevEffect = currentEffect
|
||||
local parentEffect = currentEffect
|
||||
currentEffect = effect
|
||||
effectFn()
|
||||
currentEffect = prevEffect
|
||||
currentEffect = parentEffect
|
||||
end
|
||||
effect.execute = execute
|
||||
effect.execute()
|
||||
@@ -347,6 +353,25 @@ return {
|
||||
end
|
||||
end
|
||||
|
||||
local function insertChildLayout(self, layout, node, renderContext)
|
||||
local props = {}
|
||||
for _, prop in ipairs(node:properties()) do
|
||||
props[prop.name] = prop.value
|
||||
end
|
||||
local updateFns = {}
|
||||
for prop, expression in pairs(node:reactiveProperties()) do
|
||||
updateFns[prop] = basalt.derived(function()
|
||||
return load("return " .. expression, nil, "t", renderContext.env)()
|
||||
end)
|
||||
end
|
||||
setmetatable(props, {
|
||||
__index = function(_, k)
|
||||
return updateFns[k]()
|
||||
end
|
||||
})
|
||||
self:loadLayout(layout.path, props)
|
||||
end
|
||||
|
||||
local object = {
|
||||
setValuesByXMLData = function(self, data, renderContext)
|
||||
lastXMLReferences = {}
|
||||
@@ -358,8 +383,11 @@ return {
|
||||
for _, childNode in pairs(children) do
|
||||
local tagName = childNode.___name
|
||||
if (tagName ~= "animation") then
|
||||
local layout = renderContext.env[tagName]
|
||||
local objectKey = tagName:gsub("^%l", string.upper)
|
||||
if (_OBJECTS[objectKey] ~= nil) then
|
||||
if (layout ~= nil) then
|
||||
insertChildLayout(self, layout, childNode, renderContext)
|
||||
elseif (_OBJECTS[objectKey] ~= nil) then
|
||||
local addFn = self["add" .. objectKey]
|
||||
addXMLObjectType(childNode, addFn, self, renderContext)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user