diff --git a/lib/Core.lua b/lib/Core.lua index 209857ce..ed14b9b8 100644 --- a/lib/Core.lua +++ b/lib/Core.lua @@ -23,6 +23,9 @@ Core.Portal = Symbol.named("Portal") -- Marker used to specify that the value is nothing, because nil cannot be stored in tables. Core.None = Symbol.named("None") +-- Marker used to specify that the table it is present within is a component. +Core.Element = Symbol.named("Element") + --[[ Utility to retrieve one child out the children passed to a component. @@ -71,8 +74,8 @@ function Core.createElement(elementType, props, children) end local element = { - isElement = true, - type = elementType, + component = elementType, + type = Core.Element, props = props, } diff --git a/lib/Reconciler.lua b/lib/Reconciler.lua index bd816d5c..3265cd82 100644 --- a/lib/Reconciler.lua +++ b/lib/Reconciler.lua @@ -37,7 +37,7 @@ local function isPortal(element) return false end - return element.type == Core.Portal + return element.component == Core.Portal end local Reconciler = {} @@ -52,7 +52,7 @@ local function isPrimitiveElement(element) return false end - return type(element.type) == "string" + return type(element.component) == "string" end --[[ @@ -63,7 +63,7 @@ local function isFunctionalElement(element) return false end - return type(element.type) == "function" + return type(element.component) == "function" end --[[ @@ -74,7 +74,7 @@ local function isStatefulElement(element) return false end - return type(element.type) == "table" + return type(element.component) == "table" end --[[ @@ -156,7 +156,7 @@ function Reconciler._reifyInternal(element, parent, key, context) if isPrimitiveElement(element) then -- Primitive elements are backed directly by Roblox Instances. - local rbx = Instance.new(element.type) + local rbx = Instance.new(element.component) -- Update Roblox properties for key, value in pairs(element.props) do @@ -208,7 +208,7 @@ function Reconciler._reifyInternal(element, parent, key, context) _context = context, } - local vdom = element.type(element.props) + local vdom = element.component(element.props) if vdom then instanceHandle._reified = Reconciler._reifyInternal(vdom, parent, key, context) end @@ -227,7 +227,7 @@ function Reconciler._reifyInternal(element, parent, key, context) _reified = nil, } - local instance = element.type._new(element.props, context) + local instance = element.component._new(element.props, context) instanceHandle._instance = instance instance:_reify(instanceHandle) @@ -307,7 +307,7 @@ function Reconciler._reconcileInternal(instanceHandle, newElement) -- If the element changes type, we assume its subtree will be substantially -- different. This lets us skip comparisons of a large swath of nodes. - if oldElement.type ~= newElement.type then + if oldElement.component ~= newElement.component then local parent = instanceHandle._parent local key = instanceHandle._key @@ -352,7 +352,7 @@ function Reconciler._reconcileInternal(instanceHandle, newElement) elseif isFunctionalElement(newElement) then instanceHandle._element = newElement - local rendered = newElement.type(newElement.props) + local rendered = newElement.component(newElement.props) local newChild if instanceHandle._reified then