plugin: Miscellaneous cleanup

This commit is contained in:
Lucien Greathouse
2020-03-18 23:15:03 -07:00
parent 3b433e53be
commit 5768d8e4a4
5 changed files with 30 additions and 17 deletions

View File

@@ -5,6 +5,7 @@ local Log = require(script.Parent.Parent.Log)
keep track of every instance we know about. keep track of every instance we know about.
TODO: Track ancestry to catch when stuff moves? TODO: Track ancestry to catch when stuff moves?
TODO: Ability to pause change tracking for preventing feedback.
]] ]]
local InstanceMap = {} local InstanceMap = {}
InstanceMap.__index = InstanceMap InstanceMap.__index = InstanceMap

25
plugin/src/PatchSet.lua Normal file
View File

@@ -0,0 +1,25 @@
--[[
Methods to operate on either a patch created by the hydrate method, or a
patch returned from the API.
]]
local t = require(script.Parent.Parent.t)
local Types = require(script.Parent.Types)
local PatchSet = {}
PatchSet.validate = t.interface({
removed = t.array(t.union(Types.RbxId, t.Instance)),
added = t.map(Types.RbxId, Types.ApiInstance),
updated = t.array(Types.ApiInstanceUpdate),
})
--[[
Invert the given PatchSet using the given instance map.
]]
function PatchSet.invert(patchSet, instanceMap)
error("not yet implemented", 2)
end
return PatchSet

View File

@@ -5,24 +5,12 @@
local RbxDom = require(script.Parent.Parent.RbxDom) local RbxDom = require(script.Parent.Parent.RbxDom)
local t = require(script.Parent.Parent.t) local t = require(script.Parent.Parent.t)
local Log = require(script.Parent.Parent.Log)
local Types = require(script.Parent.Types) local Types = require(script.Parent.Types)
local invariant = require(script.Parent.invariant) local invariant = require(script.Parent.invariant)
local getCanonicalProperty = require(script.Parent.getCanonicalProperty) local getCanonicalProperty = require(script.Parent.getCanonicalProperty)
local setCanonicalProperty = require(script.Parent.setCanonicalProperty) local setCanonicalProperty = require(script.Parent.setCanonicalProperty)
local PatchSet = require(script.Parent.PatchSet)
--[[
This interface represents either a patch created by the hydrate method, or a
patch returned from the API.
This type should be a subset of Types.ApiInstanceUpdate.
]]
local IPatch = t.interface({
removed = t.array(t.union(Types.RbxId, t.Instance)),
added = t.map(Types.RbxId, Types.ApiInstance),
updated = t.array(Types.ApiInstanceUpdate),
})
--[[ --[[
Attempt to safely set the parent of an instance. Attempt to safely set the parent of an instance.
@@ -86,7 +74,7 @@ end
editable by scripts. editable by scripts.
]] ]]
local applyPatchSchema = Types.ifEnabled(t.tuple( local applyPatchSchema = Types.ifEnabled(t.tuple(
IPatch PatchSet.validate
)) ))
function Reconciler:applyPatch(patch) function Reconciler:applyPatch(patch)
assert(applyPatchSchema(patch)) assert(applyPatchSchema(patch))
@@ -287,7 +275,7 @@ local hydrateSchema = Types.ifEnabled(t.tuple(
t.map(Types.RbxId, Types.VirtualInstance), t.map(Types.RbxId, Types.VirtualInstance),
Types.RbxId, Types.RbxId,
t.Instance, t.Instance,
IPatch PatchSet.validate
)) ))
function Reconciler:__hydrateInternal(apiInstances, id, instance, hydratePatch) function Reconciler:__hydrateInternal(apiInstances, id, instance, hydratePatch)
assert(hydrateSchema(apiInstances, id, instance, hydratePatch)) assert(hydrateSchema(apiInstances, id, instance, hydratePatch))

View File

@@ -4,7 +4,6 @@ local Log = require(script.Parent.Parent.Log)
local Fmt = require(script.Parent.Parent.Fmt) local Fmt = require(script.Parent.Parent.Fmt)
local t = require(script.Parent.Parent.t) local t = require(script.Parent.Parent.t)
local DevSettings = require(script.Parent.DevSettings)
local InstanceMap = require(script.Parent.InstanceMap) local InstanceMap = require(script.Parent.InstanceMap)
local Reconciler = require(script.Parent.Reconciler) local Reconciler = require(script.Parent.Reconciler)
local strict = require(script.Parent.strict) local strict = require(script.Parent.strict)

View File

@@ -1,7 +1,7 @@
local RbxDom = require(script.Parent.Parent.RbxDom) local RbxDom = require(script.Parent.Parent.RbxDom)
--[[ --[[
Attempts to set a property on the given instance. Attempts to read a property from the given instance.
]] ]]
local function getCanonincalProperty(instance, propertyName) local function getCanonincalProperty(instance, propertyName)
local descriptor = RbxDom.findCanonicalPropertyDescriptor(instance.ClassName, propertyName) local descriptor = RbxDom.findCanonicalPropertyDescriptor(instance.ClassName, propertyName)