Skip to content

Commit

Permalink
Fix Ref reification (#462)
Browse files Browse the repository at this point in the history
* Update ApiValue type to use new value format

* Use new value format for Ref reification
  • Loading branch information
kennethloeffler authored Aug 5, 2021
1 parent 5d62bf9 commit e1f9eae
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
14 changes: 7 additions & 7 deletions plugin/src/Reconciler/reify.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function reifyInner(instanceMap, virtualInstances, id, parentInstance, unapplied
for propertyName, virtualValue in pairs(virtualInstance.Properties) do
-- Because refs may refer to instances that we haven't constructed yet,
-- we defer applying any ref properties until all instances are created.
if virtualValue.Type == "Ref" then
if next(virtualValue) == "Ref" then
table.insert(deferredRefs, {
id = id,
instance = instance,
Expand Down Expand Up @@ -136,23 +136,23 @@ function applyDeferredRefs(instanceMap, deferredRefs, unappliedPatch)
end

for _, entry in ipairs(deferredRefs) do
local virtualValue = entry.virtualValue
local _, refId = next(entry.virtualValue)

if virtualValue.Value == nil then
if refId == nil then
continue
end

local targetInstance = instanceMap.fromIds[virtualValue.Value]
local targetInstance = instanceMap.fromIds[refId]
if targetInstance == nil then
markFailed(entry.id, entry.propertyName, virtualValue)
markFailed(entry.id, entry.propertyName, entry.virtualValue)
continue
end

local ok = setProperty(entry.instance, entry.propertyName, targetInstance)
if not ok then
markFailed(entry.id, entry.propertyName, virtualValue)
markFailed(entry.id, entry.propertyName, entry.virtualValue)
end
end
end

return reify
return reify
7 changes: 2 additions & 5 deletions plugin/src/Types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ local strict = require(script.Parent.strict)

local RbxId = t.string

local ApiValue = t.interface({
Type = t.string,
Value = t.optional(t.any),
})
local ApiValue = t.keys(t.string)

local ApiInstanceMetadata = t.interface({
ignoreUnknownInstances = t.optional(t.boolean),
Expand Down Expand Up @@ -96,4 +93,4 @@ return strict("Types", {
VirtualInstance = ApiInstance,
VirtualMetadata = ApiInstanceMetadata,
VirtualValue = ApiValue,
})
})

0 comments on commit e1f9eae

Please sign in to comment.