forked from rojo-rbx/rojo
Add conditionally-enabled typechecking using t
This commit is contained in:
@@ -1,10 +1,27 @@
|
|||||||
local Config = require(script.Parent.Config)
|
local Config = require(script.Parent.Config)
|
||||||
|
|
||||||
|
local Environment = {
|
||||||
|
User = "User",
|
||||||
|
Dev = "Dev",
|
||||||
|
Test = "Test",
|
||||||
|
}
|
||||||
|
|
||||||
local VALUES = {
|
local VALUES = {
|
||||||
LogLevel = {
|
LogLevel = {
|
||||||
type = "IntValue",
|
type = "IntValue",
|
||||||
defaultUserValue = 2,
|
values = {
|
||||||
defaultDevValue = 3,
|
[Environment.User] = 2,
|
||||||
|
[Environment.Dev] = 3,
|
||||||
|
[Environment.Test] = 3,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
TypecheckingEnabled = {
|
||||||
|
type = "BoolValue",
|
||||||
|
values = {
|
||||||
|
[Environment.User] = false,
|
||||||
|
[Environment.Dev] = true,
|
||||||
|
[Environment.Test] = true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,7 +59,9 @@ local function setStoredValue(name, kind, value)
|
|||||||
object.Value = value
|
object.Value = value
|
||||||
end
|
end
|
||||||
|
|
||||||
local function createAllValues()
|
local function createAllValues(environment)
|
||||||
|
assert(Environment[environment] ~= nil, "Invalid environment")
|
||||||
|
|
||||||
valueContainer = getValueContainer()
|
valueContainer = getValueContainer()
|
||||||
|
|
||||||
if valueContainer == nil then
|
if valueContainer == nil then
|
||||||
@@ -52,20 +71,57 @@ local function createAllValues()
|
|||||||
end
|
end
|
||||||
|
|
||||||
for name, value in pairs(VALUES) do
|
for name, value in pairs(VALUES) do
|
||||||
setStoredValue(name, value.type, value.defaultDevValue)
|
setStoredValue(name, value.type, value.values[environment])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
_G[("ROJO_%s_DEV_CREATE"):format(Config.codename:upper())] = createAllValues
|
local function getValue(name)
|
||||||
|
assert(VALUES[name] ~= nil, "Invalid DevSettings name")
|
||||||
|
|
||||||
|
local stored = getStoredValue(name)
|
||||||
|
|
||||||
|
if stored ~= nil then
|
||||||
|
return stored
|
||||||
|
end
|
||||||
|
|
||||||
|
return VALUES[name].values[Environment.User]
|
||||||
|
end
|
||||||
|
|
||||||
local DevSettings = {}
|
local DevSettings = {}
|
||||||
|
|
||||||
|
function DevSettings:createDevSettings()
|
||||||
|
createAllValues(Environment.Dev)
|
||||||
|
end
|
||||||
|
|
||||||
|
function DevSettings:createTestSettings()
|
||||||
|
createAllValues(Environment.Test)
|
||||||
|
end
|
||||||
|
|
||||||
|
function DevSettings:hasChangedValues()
|
||||||
|
return valueContainer ~= nil
|
||||||
|
end
|
||||||
|
|
||||||
|
function DevSettings:resetValues()
|
||||||
|
if valueContainer then
|
||||||
|
valueContainer:Destroy()
|
||||||
|
valueContainer = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function DevSettings:isEnabled()
|
function DevSettings:isEnabled()
|
||||||
return valueContainer ~= nil
|
return valueContainer ~= nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function DevSettings:getLogLevel()
|
function DevSettings:getLogLevel()
|
||||||
return getStoredValue("LogLevel") or VALUES.LogLevel.defaultUserValue
|
return getValue("LogLevel")
|
||||||
|
end
|
||||||
|
|
||||||
|
function DevSettings:shouldTypecheck()
|
||||||
|
return getValue("TypecheckingEnabled")
|
||||||
|
end
|
||||||
|
|
||||||
|
function _G.ROJO_DEV_CREATE()
|
||||||
|
DevSettings:createDevSettings()
|
||||||
end
|
end
|
||||||
|
|
||||||
return DevSettings
|
return DevSettings
|
||||||
@@ -1,7 +1,10 @@
|
|||||||
|
local t = require(script.Parent.Parent.t)
|
||||||
|
|
||||||
local InstanceMap = require(script.Parent.InstanceMap)
|
local InstanceMap = require(script.Parent.InstanceMap)
|
||||||
local Logging = require(script.Parent.Logging)
|
local Logging = require(script.Parent.Logging)
|
||||||
local setCanonicalProperty = require(script.Parent.setCanonicalProperty)
|
local setCanonicalProperty = require(script.Parent.setCanonicalProperty)
|
||||||
local rojoValueToRobloxValue = require(script.Parent.rojoValueToRobloxValue)
|
local rojoValueToRobloxValue = require(script.Parent.rojoValueToRobloxValue)
|
||||||
|
local Types = require(script.Parent.Types)
|
||||||
|
|
||||||
local Reconciler = {}
|
local Reconciler = {}
|
||||||
Reconciler.__index = Reconciler
|
Reconciler.__index = Reconciler
|
||||||
@@ -24,11 +27,18 @@ function Reconciler:applyUpdate(requestedIds, virtualInstancesById)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local reconcileSchema = Types.ifEnabled(t.tuple(
|
||||||
|
t.map(t.string, Types.VirtualInstance),
|
||||||
|
t.string,
|
||||||
|
t.Instance
|
||||||
|
))
|
||||||
--[[
|
--[[
|
||||||
Update an existing instance, including its properties and children, to match
|
Update an existing instance, including its properties and children, to match
|
||||||
the given information.
|
the given information.
|
||||||
]]
|
]]
|
||||||
function Reconciler:reconcile(virtualInstancesById, id, instance)
|
function Reconciler:reconcile(virtualInstancesById, id, instance)
|
||||||
|
assert(reconcileSchema(virtualInstancesById, id, instance))
|
||||||
|
|
||||||
local virtualInstance = virtualInstancesById[id]
|
local virtualInstance = virtualInstancesById[id]
|
||||||
|
|
||||||
-- If an instance changes ClassName, we assume it's very different. That's
|
-- If an instance changes ClassName, we assume it's very different. That's
|
||||||
@@ -121,7 +131,15 @@ function Reconciler:__shouldClearUnknownChildren(virtualInstance)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local reifySchema = Types.ifEnabled(t.tuple(
|
||||||
|
t.map(t.string, Types.VirtualInstance),
|
||||||
|
t.string,
|
||||||
|
t.Instance
|
||||||
|
))
|
||||||
|
|
||||||
function Reconciler:__reify(virtualInstancesById, id, parent)
|
function Reconciler:__reify(virtualInstancesById, id, parent)
|
||||||
|
assert(reifySchema(virtualInstancesById, id, parent))
|
||||||
|
|
||||||
local virtualInstance = virtualInstancesById[id]
|
local virtualInstance = virtualInstancesById[id]
|
||||||
|
|
||||||
local instance = Instance.new(virtualInstance.ClassName)
|
local instance = Instance.new(virtualInstance.ClassName)
|
||||||
@@ -142,7 +160,15 @@ function Reconciler:__reify(virtualInstancesById, id, parent)
|
|||||||
return instance
|
return instance
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local applyUpdatePieceSchema = Types.ifEnabled(t.tuple(
|
||||||
|
t.string,
|
||||||
|
t.map(t.string, t.boolean),
|
||||||
|
t.map(t.string, Types.VirtualInstance)
|
||||||
|
))
|
||||||
|
|
||||||
function Reconciler:__applyUpdatePiece(id, visitedIds, virtualInstancesById)
|
function Reconciler:__applyUpdatePiece(id, visitedIds, virtualInstancesById)
|
||||||
|
assert(applyUpdatePieceSchema(id, visitedIds, virtualInstancesById))
|
||||||
|
|
||||||
if visitedIds[id] then
|
if visitedIds[id] then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|||||||
36
plugin/src/Types.lua
Normal file
36
plugin/src/Types.lua
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
local t = require(script.Parent.Parent.t)
|
||||||
|
|
||||||
|
local DevSettings = require(script.Parent.DevSettings)
|
||||||
|
|
||||||
|
local VirtualValue = t.interface({
|
||||||
|
Type = t.string,
|
||||||
|
Value = t.optional(t.any),
|
||||||
|
})
|
||||||
|
|
||||||
|
local VirtualMetadata = t.interface({
|
||||||
|
ignoreUnknownInstances = t.optional(t.boolean),
|
||||||
|
})
|
||||||
|
|
||||||
|
local VirtualInstance = t.interface({
|
||||||
|
Name = t.string,
|
||||||
|
ClassName = t.string,
|
||||||
|
Properties = t.map(t.string, VirtualValue),
|
||||||
|
Metadata = t.optional(VirtualMetadata)
|
||||||
|
})
|
||||||
|
|
||||||
|
local function ifEnabled(innerCheck)
|
||||||
|
return function(...)
|
||||||
|
if DevSettings:shouldTypecheck() then
|
||||||
|
return innerCheck(...)
|
||||||
|
else
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return {
|
||||||
|
ifEnabled = ifEnabled,
|
||||||
|
VirtualInstance = VirtualInstance,
|
||||||
|
VirtualMetadata = VirtualMetadata,
|
||||||
|
VirtualValue = VirtualValue,
|
||||||
|
}
|
||||||
@@ -1,2 +1,19 @@
|
|||||||
local TestEZ = require(game.ReplicatedStorage.TestEZ)
|
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||||
TestEZ.TestBootstrap:run({game.ReplicatedStorage.Rojo.Plugin})
|
|
||||||
|
local TestEZ = require(ReplicatedStorage.TestEZ)
|
||||||
|
|
||||||
|
local Rojo = ReplicatedStorage.Rojo
|
||||||
|
|
||||||
|
local DevSettings = require(Rojo.Plugin.DevSettings)
|
||||||
|
|
||||||
|
local setDevSettings = not DevSettings:hasChangedValues()
|
||||||
|
|
||||||
|
if setDevSettings then
|
||||||
|
DevSettings:createTestSettings()
|
||||||
|
end
|
||||||
|
|
||||||
|
TestEZ.TestBootstrap:run({Rojo.Plugin})
|
||||||
|
|
||||||
|
if setDevSettings then
|
||||||
|
DevSettings:resetValues()
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user