From 799e6545c81e28d99f52301e4e08829754931696 Mon Sep 17 00:00:00 2001 From: Paul Doyle Date: Thu, 6 Dec 2018 15:54:56 -0800 Subject: [PATCH] Wrapped versions of both updating with children and updating with render results --- lib/RobloxRenderer.lua | 4 ++-- lib/createReconciler.lua | 14 +++++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/RobloxRenderer.lua b/lib/RobloxRenderer.lua index a6acb88a..47f71a25 100644 --- a/lib/RobloxRenderer.lua +++ b/lib/RobloxRenderer.lua @@ -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 @@ -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 diff --git a/lib/createReconciler.lua b/lib/createReconciler.lua index 389e3247..b6822f03 100644 --- a/lib/createReconciler.lua +++ b/lib/createReconciler.lua @@ -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 = {} @@ -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( @@ -156,7 +160,7 @@ local function createReconciler(renderer) local children = newElement.props[Children] - updateVirtualNodeChildren(virtualNode, targetHostParent, children) + updateVirtualNodeWithChildren(virtualNode, targetHostParent, children) return virtualNode end @@ -264,7 +268,7 @@ local function createReconciler(renderer) assert(renderer.isHostObject(targetHostParent)) - updateVirtualNodeChildren(virtualNode, targetHostParent, children) + updateVirtualNodeWithChildren(virtualNode, targetHostParent, children) end --[[ @@ -369,7 +373,7 @@ local function createReconciler(renderer) mountVirtualNode = mountVirtualNode, unmountVirtualNode = unmountVirtualNode, updateVirtualNode = updateVirtualNode, - updateVirtualNodeChildren = updateVirtualNodeChildren, + updateVirtualNodeWithChildren = updateVirtualNodeWithChildren, updateVirtualNodeWithRenderResult = updateVirtualNodeWithRenderResult, }