Skip to content

Commit

Permalink
StyLua
Browse files Browse the repository at this point in the history
  • Loading branch information
Dekkonot committed Sep 19, 2023
1 parent 08fd714 commit e721e6e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 45 deletions.
2 changes: 1 addition & 1 deletion plugin/src/ApiContext.lua
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ function ApiContext:open(id)
end)
end

function ApiContext:fetch(ids: {string})
function ApiContext:fetch(ids: { string })
local url = ("%s/api/fetch/%s"):format(self.__baseUrl, table.concat(ids, ","))
local requestBody = {
sessionId = self.__sessionId,
Expand Down
87 changes: 43 additions & 44 deletions plugin/src/Reconciler/fetchInstances.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,53 +4,52 @@ local invariant = require(script.Parent.Parent.invariant)
local Log = require(Rojo.Packages.Log)

local function fetchInstances(idList, instanceMap, apiContext)
return apiContext:fetch(idList)
:andThen(function(body: {sessionId: string, path: string})
-- The endpoint `api/fetech/idlist` returns a table that contains
-- `sessionId` and `path`. The value of `path` is the name of a
-- file in the Content folder that may be loaded via `GetObjects`.
local objects = game:GetObjects("rbxasset://" .. body.path)
-- `ReferentMap` is a folder that contains nothing but
-- ObjectValues which will be named after entries in `instanceMap`
-- and have their `Value` property point towards a new Instance
-- that it can be swapped out with. In turn, `reified` is a
-- container for all of the objects pointed to by those instances.
local map = objects[1]:FindFirstChild("ReferentMap")
local reified = objects[1]:FindFirstChild("Reified")
if map == nil then
invariant("The fetch endpoint returned a malformed folder: missing ReferentMap")
end
if reified == nil then
invariant("The fetch endpoint returned a malformed folder: missing Reified")
end
for _, entry in map:GetChildren() do
if entry:IsA("ObjectValue") then
local key, value = entry.Name, entry.Value
if value == nil or not value:IsDescendantOf(reified) then
invariant("ReferentMap contained entry {} that was parented to an outside source", key)
else
-- This could be a problem if Roblox ever supports
-- parallel access to the DataModel but right now,
-- there's no way this results in a data race.
local oldInstance: Instance = instanceMap.fromIds[key]
instanceMap:insert(key, value)
Log.trace("Swapping Instance {} out", key)

local oldParent = oldInstance.Parent
local children = oldInstance:GetChildren()
for _, child in children do
child.Parent = value
end
value.Parent = oldParent
return apiContext:fetch(idList):andThen(function(body: { sessionId: string, path: string })
-- The endpoint `api/fetech/idlist` returns a table that contains
-- `sessionId` and `path`. The value of `path` is the name of a
-- file in the Content folder that may be loaded via `GetObjects`.
local objects = game:GetObjects("rbxasset://" .. body.path)
-- `ReferentMap` is a folder that contains nothing but
-- ObjectValues which will be named after entries in `instanceMap`
-- and have their `Value` property point towards a new Instance
-- that it can be swapped out with. In turn, `reified` is a
-- container for all of the objects pointed to by those instances.
local map = objects[1]:FindFirstChild("ReferentMap")
local reified = objects[1]:FindFirstChild("Reified")
if map == nil then
invariant("The fetch endpoint returned a malformed folder: missing ReferentMap")
end
if reified == nil then
invariant("The fetch endpoint returned a malformed folder: missing Reified")
end
for _, entry in map:GetChildren() do
if entry:IsA("ObjectValue") then
local key, value = entry.Name, entry.Value
if value == nil or not value:IsDescendantOf(reified) then
invariant("ReferentMap contained entry {} that was parented to an outside source", key)
else
-- This could be a problem if Roblox ever supports
-- parallel access to the DataModel but right now,
-- there's no way this results in a data race.
local oldInstance: Instance = instanceMap.fromIds[key]
instanceMap:insert(key, value)
Log.trace("Swapping Instance {} out", key)

-- So long and thanks for all the fish :-)
oldInstance:Destroy()
local oldParent = oldInstance.Parent
local children = oldInstance:GetChildren()
for _, child in children do
child.Parent = value
end
else
invariant("ReferentMap entry `{}` was a `{}` and not an ObjectValue", entry.Name, entry.ClassName)
value.Parent = oldParent

-- So long and thanks for all the fish :-)
oldInstance:Destroy()
end
else
invariant("ReferentMap entry `{}` was a `{}` and not an ObjectValue", entry.Name, entry.ClassName)
end
end)
end
end)
end

return fetchInstances
return fetchInstances

0 comments on commit e721e6e

Please sign in to comment.