Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

Commit

Permalink
Wrapped versions of both updating with children and updating with ren…
Browse files Browse the repository at this point in the history
…der results
  • Loading branch information
ZoteTheMighty committed Dec 6, 2018
1 parent 0a427c6 commit 799e654
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/RobloxRenderer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ function RobloxRenderer.mountHostNode(reconciler, virtualNode)

local children = element.props[Children]

reconciler.updateVirtualNodeChildren(virtualNode, virtualNode.hostObject, children)
reconciler.updateVirtualNodeWithChildren(virtualNode, virtualNode.hostObject, children)

instance.Parent = hostParent
virtualNode.hostObject = instance
Expand Down Expand Up @@ -199,7 +199,7 @@ function RobloxRenderer.updateHostNode(reconciler, virtualNode, newElement)
end
end

reconciler.updateVirtualNodeChildren(virtualNode, virtualNode.hostObject, newElement.props[Children])
reconciler.updateVirtualNodeWithChildren(virtualNode, virtualNode.hostObject, newElement.props[Children])

-- Resume event firing now that everything's updated successfully
if virtualNode.eventManager ~= nil then
Expand Down
14 changes: 9 additions & 5 deletions lib/createReconciler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ local function createReconciler(renderer)
Utility to update the children of a virtual node based on zero or more
updated children given as elements.
]]
local function updateVirtualNodeChildren(virtualNode, hostParent, newChildElements)
local function updateChildren(virtualNode, hostParent, newChildElements)
assert(Type.of(virtualNode) == Type.VirtualNode)

local removeKeys = {}
Expand Down Expand Up @@ -89,13 +89,17 @@ local function createReconciler(renderer)
end
end

local function updateVirtualNodeWithChildren(virtualNode, hostParent, newChildElements)
updateChildren(virtualNode, hostParent, newChildElements)
end

local function updateVirtualNodeWithRenderResult(virtualNode, hostParent, renderResult)
if renderResult == nil
or typeof(renderResult) == "boolean"
or Type.of(renderResult) == Type.Element
or Type.of(renderResult) == Type.Fragment
then
updateVirtualNodeChildren(virtualNode, hostParent, renderResult)
updateChildren(virtualNode, hostParent, renderResult)
else
-- TODO: Better error message
Logging.error(("%s\n%s"):format(
Expand Down Expand Up @@ -156,7 +160,7 @@ local function createReconciler(renderer)

local children = newElement.props[Children]

updateVirtualNodeChildren(virtualNode, targetHostParent, children)
updateVirtualNodeWithChildren(virtualNode, targetHostParent, children)

return virtualNode
end
Expand Down Expand Up @@ -264,7 +268,7 @@ local function createReconciler(renderer)

assert(renderer.isHostObject(targetHostParent))

updateVirtualNodeChildren(virtualNode, targetHostParent, children)
updateVirtualNodeWithChildren(virtualNode, targetHostParent, children)
end

--[[
Expand Down Expand Up @@ -369,7 +373,7 @@ local function createReconciler(renderer)
mountVirtualNode = mountVirtualNode,
unmountVirtualNode = unmountVirtualNode,
updateVirtualNode = updateVirtualNode,
updateVirtualNodeChildren = updateVirtualNodeChildren,
updateVirtualNodeWithChildren = updateVirtualNodeWithChildren,
updateVirtualNodeWithRenderResult = updateVirtualNodeWithRenderResult,
}

Expand Down

0 comments on commit 799e654

Please sign in to comment.