mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-24 22:56:02 +00:00
Add typechecks to reconciler and improve robustness a touch
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
local RouteMap = require(script.Parent.RouteMap)
|
local RouteMap = require(script.Parent.RouteMap)
|
||||||
|
|
||||||
local function classEqual(a, b)
|
local function classEqual(a, b)
|
||||||
|
assert(typeof(a) == "string")
|
||||||
|
assert(typeof(b) == "string")
|
||||||
|
|
||||||
if a == "*" or b == "*" then
|
if a == "*" or b == "*" then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
@@ -9,6 +12,9 @@ local function classEqual(a, b)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function applyProperties(target, properties)
|
local function applyProperties(target, properties)
|
||||||
|
assert(typeof(target) == "Instance")
|
||||||
|
assert(typeof(properties) == "table")
|
||||||
|
|
||||||
for key, property in pairs(properties) do
|
for key, property in pairs(properties) do
|
||||||
-- TODO: Transform property value based on property.Type
|
-- TODO: Transform property value based on property.Type
|
||||||
-- Right now, we assume that 'value' is primitive!
|
-- Right now, we assume that 'value' is primitive!
|
||||||
@@ -22,18 +28,19 @@ end
|
|||||||
* Changing parent threw an error
|
* Changing parent threw an error
|
||||||
]]
|
]]
|
||||||
local function reparent(rbx, parent)
|
local function reparent(rbx, parent)
|
||||||
if rbx then
|
assert(typeof(rbx) == "Instance")
|
||||||
if rbx.Parent == parent then
|
assert(typeof(parent) == "Instance")
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
-- It's possible that 'rbx' is a service or some other object that we
|
if rbx.Parent == parent then
|
||||||
-- can't change the parent of. That's the only reason why Parent would
|
return
|
||||||
-- fail except for rbx being previously destroyed!
|
|
||||||
pcall(function()
|
|
||||||
rbx.Parent = parent
|
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Setting `Parent` can fail if:
|
||||||
|
-- * The object has been destroyed
|
||||||
|
-- * The object is a service and cannot be reparented
|
||||||
|
pcall(function()
|
||||||
|
rbx.Parent = parent
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
@@ -98,7 +105,11 @@ function Reconciler:_reconcileChildren(rbx, item)
|
|||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
reparent(self:reconcile(rbxChild, itemChild), rbx)
|
local newRbxChild = self:reconcile(rbxChild, itemChild)
|
||||||
|
|
||||||
|
if newRbxChild ~= nil then
|
||||||
|
newRbxChild.Parent = rbx
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Reconcile any children that were deleted
|
-- Reconcile any children that were deleted
|
||||||
@@ -109,7 +120,11 @@ function Reconciler:_reconcileChildren(rbx, item)
|
|||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
reparent(self:reconcile(rbxChild, itemChild), rbx)
|
local newRbxChild = self:reconcile(rbxChild, itemChild)
|
||||||
|
|
||||||
|
if newRbxChild ~= nil then
|
||||||
|
newRbxChild.Parent = rbx
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user