Merge branch 'master' of https://github.com/Pyroxenium/Basalt
This commit is contained in:
@@ -167,6 +167,15 @@ local function registerFunctionEvent(self, data, event, renderContext)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function registerFunctionEvents(self, data, events, renderContext)
|
||||||
|
for _, event in pairs(events) do
|
||||||
|
local expression = data:reactiveProperties()[event]
|
||||||
|
if (expression ~= nil) then
|
||||||
|
registerFunctionEvent(self, expression .. "()", self[event], renderContext)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local currentEffect = nil
|
local currentEffect = nil
|
||||||
|
|
||||||
local clearEffectDependencies = function(effect)
|
local clearEffectDependencies = function(effect)
|
||||||
@@ -183,6 +192,12 @@ end
|
|||||||
return {
|
return {
|
||||||
basalt = function(basalt)
|
basalt = function(basalt)
|
||||||
local object = {
|
local object = {
|
||||||
|
layout = function(path)
|
||||||
|
return {
|
||||||
|
path = path,
|
||||||
|
}
|
||||||
|
end,
|
||||||
|
|
||||||
reactive = function(initialValue)
|
reactive = function(initialValue)
|
||||||
local value = initialValue
|
local value = initialValue
|
||||||
local observerEffects = {}
|
local observerEffects = {}
|
||||||
@@ -207,10 +222,10 @@ return {
|
|||||||
end,
|
end,
|
||||||
|
|
||||||
untracked = function(getter)
|
untracked = function(getter)
|
||||||
local prevEffect = currentEffect
|
local parentEffect = currentEffect
|
||||||
currentEffect = nil
|
currentEffect = nil
|
||||||
local value = getter()
|
local value = getter()
|
||||||
currentEffect = prevEffect
|
currentEffect = parentEffect
|
||||||
return value
|
return value
|
||||||
end,
|
end,
|
||||||
|
|
||||||
@@ -218,10 +233,10 @@ return {
|
|||||||
local effect = {dependencies = {}}
|
local effect = {dependencies = {}}
|
||||||
local execute = function()
|
local execute = function()
|
||||||
clearEffectDependencies(effect)
|
clearEffectDependencies(effect)
|
||||||
local prevEffect = currentEffect
|
local parentEffect = currentEffect
|
||||||
currentEffect = effect
|
currentEffect = effect
|
||||||
effectFn()
|
effectFn()
|
||||||
currentEffect = prevEffect
|
currentEffect = parentEffect
|
||||||
end
|
end
|
||||||
effect.execute = execute
|
effect.execute = execute
|
||||||
effect.execute()
|
effect.execute()
|
||||||
@@ -278,7 +293,6 @@ return {
|
|||||||
end
|
end
|
||||||
basalt.effect(update)
|
basalt.effect(update)
|
||||||
end
|
end
|
||||||
|
|
||||||
self:updateSpecifiedValuesByXMLData(data, {
|
self:updateSpecifiedValuesByXMLData(data, {
|
||||||
"x",
|
"x",
|
||||||
"y",
|
"y",
|
||||||
@@ -287,14 +301,23 @@ return {
|
|||||||
"background",
|
"background",
|
||||||
"foreground"
|
"foreground"
|
||||||
})
|
})
|
||||||
|
registerFunctionEvents(self, data, {
|
||||||
local events = {"onClick", "onClickUp", "onHover", "onScroll", "onDrag", "onKey", "onKeyUp", "onRelease", "onChar", "onGetFocus", "onLoseFocus", "onResize", "onReposition", "onEvent", "onLeave"}
|
"onClick",
|
||||||
for _,v in pairs(events)do
|
"onClickUp",
|
||||||
if(xmlValue(v, data)~=nil)then
|
"onHover",
|
||||||
registerFunctionEvent(self, xmlValue(v, data), self[v], renderContext)
|
"onScroll",
|
||||||
end
|
"onDrag",
|
||||||
end
|
"onKey",
|
||||||
|
"onKeyUp",
|
||||||
|
"onRelease",
|
||||||
|
"onChar",
|
||||||
|
"onGetFocus",
|
||||||
|
"onLoseFocus",
|
||||||
|
"onResize",
|
||||||
|
"onReposition",
|
||||||
|
"onEvent",
|
||||||
|
"onLeave"
|
||||||
|
}, renderContext)
|
||||||
return self
|
return self
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
@@ -316,9 +339,9 @@ return {
|
|||||||
self:updateSpecifiedValuesByXMLData(data, {
|
self:updateSpecifiedValuesByXMLData(data, {
|
||||||
"value"
|
"value"
|
||||||
})
|
})
|
||||||
if(xmlValue("onChange", data)~=nil)then
|
registerFunctionEvent(self, data, {
|
||||||
registerFunctionEvent(self, xmlValue("onChange", data), self.onChange, renderContext)
|
"onChange"
|
||||||
end
|
}, renderContext)
|
||||||
return self
|
return self
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
@@ -347,6 +370,25 @@ return {
|
|||||||
end
|
end
|
||||||
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 = {
|
local object = {
|
||||||
setValuesByXMLData = function(self, data, renderContext)
|
setValuesByXMLData = function(self, data, renderContext)
|
||||||
lastXMLReferences = {}
|
lastXMLReferences = {}
|
||||||
@@ -358,8 +400,11 @@ return {
|
|||||||
for _, childNode in pairs(children) do
|
for _, childNode in pairs(children) do
|
||||||
local tagName = childNode.___name
|
local tagName = childNode.___name
|
||||||
if (tagName ~= "animation") then
|
if (tagName ~= "animation") then
|
||||||
|
local layout = renderContext.env[tagName]
|
||||||
local objectKey = tagName:gsub("^%l", string.upper)
|
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]
|
local addFn = self["add" .. objectKey]
|
||||||
addXMLObjectType(childNode, addFn, self, renderContext)
|
addXMLObjectType(childNode, addFn, self, renderContext)
|
||||||
end
|
end
|
||||||
@@ -914,10 +959,9 @@ return {
|
|||||||
"start",
|
"start",
|
||||||
"time"
|
"time"
|
||||||
})
|
})
|
||||||
|
registerFunctionEvents(self, data, {
|
||||||
if(xmlValue("onCall", data)~=nil)then
|
"onCall"
|
||||||
registerFunctionEvent(self, xmlValue("onCall", data), self.onCall, renderContext)
|
}, renderContext)
|
||||||
end
|
|
||||||
return self
|
return self
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user