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

Commit

Permalink
Add symbol for element status (#49)
Browse files Browse the repository at this point in the history
* add symbol for element status (Core.Element)
* remove isElement from createElement table
* rename element.type to element.component
  • Loading branch information
AmaranthineCodices authored and LPGhatguy committed Mar 18, 2018
1 parent 86a1ce3 commit c5e84b7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
7 changes: 5 additions & 2 deletions lib/Core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -71,8 +74,8 @@ function Core.createElement(elementType, props, children)
end

local element = {
isElement = true,
type = elementType,
component = elementType,
type = Core.Element,
props = props,
}

Expand Down
18 changes: 9 additions & 9 deletions lib/Reconciler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ local function isPortal(element)
return false
end

return element.type == Core.Portal
return element.component == Core.Portal
end

local Reconciler = {}
Expand All @@ -52,7 +52,7 @@ local function isPrimitiveElement(element)
return false
end

return type(element.type) == "string"
return type(element.component) == "string"
end

--[[
Expand All @@ -63,7 +63,7 @@ local function isFunctionalElement(element)
return false
end

return type(element.type) == "function"
return type(element.component) == "function"
end

--[[
Expand All @@ -74,7 +74,7 @@ local function isStatefulElement(element)
return false
end

return type(element.type) == "table"
return type(element.component) == "table"
end

--[[
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c5e84b7

Please sign in to comment.