forked from rojo-rbx/rojo
Plugin: Pipe InstanceMap around, improve debug output, fix session ID bug
This commit is contained in:
@@ -87,7 +87,7 @@ function ApiContext.new(baseUrl)
|
||||
|
||||
local self = {
|
||||
__baseUrl = baseUrl,
|
||||
__serverId = nil,
|
||||
__sessionId = nil,
|
||||
__messageCursor = -1,
|
||||
__connected = true,
|
||||
}
|
||||
@@ -95,6 +95,19 @@ function ApiContext.new(baseUrl)
|
||||
return setmetatable(self, ApiContext)
|
||||
end
|
||||
|
||||
function ApiContext:__fmtDebug(output)
|
||||
output:writeLine("ApiContext {{")
|
||||
output:indent()
|
||||
|
||||
output:writeLine("Connected: {}", self.__connected)
|
||||
output:writeLine("Base URL: {}", self.__baseUrl)
|
||||
output:writeLine("Session ID: {}", self.__sessionId)
|
||||
output:writeLine("Message Cursor: {}", self.__messageCursor)
|
||||
|
||||
output:unindent()
|
||||
output:write("}")
|
||||
end
|
||||
|
||||
function ApiContext:disconnect()
|
||||
self.__connected = false
|
||||
end
|
||||
@@ -117,7 +130,7 @@ function ApiContext:connect()
|
||||
end)
|
||||
:andThen(rejectWrongPlaceId)
|
||||
:andThen(function(body)
|
||||
self.__serverId = body.serverId
|
||||
self.__sessionId = body.sessionId
|
||||
|
||||
return body
|
||||
end)
|
||||
@@ -130,7 +143,7 @@ function ApiContext:read(ids)
|
||||
:andThen(rejectFailedRequests)
|
||||
:andThen(Http.Response.json)
|
||||
:andThen(function(body)
|
||||
if body.serverId ~= self.__serverId then
|
||||
if body.sessionId ~= self.__sessionId then
|
||||
return Promise.reject("Server changed ID")
|
||||
end
|
||||
|
||||
@@ -162,7 +175,7 @@ function ApiContext:retrieveMessages()
|
||||
:andThen(rejectFailedRequests)
|
||||
:andThen(Http.Response.json)
|
||||
:andThen(function(body)
|
||||
if body.serverId ~= self.__serverId then
|
||||
if body.sessionId ~= self.__sessionId then
|
||||
return Promise.reject("Server changed ID")
|
||||
end
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ local ApiContext = require(Plugin.ApiContext)
|
||||
local Assets = require(Plugin.Assets)
|
||||
local Config = require(Plugin.Config)
|
||||
local DevSettings = require(Plugin.DevSettings)
|
||||
local Reconciler = require(Plugin.Reconciler)
|
||||
local ServeSession = require(Plugin.ServeSession)
|
||||
local Version = require(Plugin.Version)
|
||||
local preloadAssets = require(Plugin.preloadAssets)
|
||||
@@ -115,7 +114,6 @@ function App:startSession(address, port)
|
||||
local baseUrl = ("http://%s:%s"):format(address, port)
|
||||
self.serveSession = ServeSession.new({
|
||||
apiContext = ApiContext.new(baseUrl),
|
||||
reconciler = Reconciler.new(),
|
||||
})
|
||||
|
||||
self.serveSession:onStatusChanged(function(status, details)
|
||||
|
||||
@@ -24,12 +24,25 @@ function InstanceMap:__fmtDebug(output)
|
||||
output:writeLine("InstanceMap {{")
|
||||
output:indent()
|
||||
|
||||
-- Collect all of the entries in the InstanceMap and sort them by their
|
||||
-- label, which helps make our output deterministic.
|
||||
local entries = {}
|
||||
for id, instance in pairs(self.fromIds) do
|
||||
output:writeLine("- {}: {}", id, instance:GetFullName())
|
||||
local label = string.format("%s (%s)", instance:GetFullName(), instance.ClassName)
|
||||
|
||||
table.insert(entries, {id, label})
|
||||
end
|
||||
|
||||
table.sort(entries, function(a, b)
|
||||
return a[2] < b[2]
|
||||
end)
|
||||
|
||||
for _, entry in ipairs(entries) do
|
||||
output:writeLine("{}: {}", entry[1], entry[2])
|
||||
end
|
||||
|
||||
output:unindent()
|
||||
output:writeLine("}")
|
||||
output:write("}")
|
||||
end
|
||||
|
||||
function InstanceMap:insert(id, instance)
|
||||
|
||||
@@ -7,7 +7,6 @@ local RbxDom = require(script.Parent.Parent.RbxDom)
|
||||
local t = require(script.Parent.Parent.t)
|
||||
local Log = require(script.Parent.Parent.Log)
|
||||
|
||||
local InstanceMap = require(script.Parent.InstanceMap)
|
||||
local Types = require(script.Parent.Types)
|
||||
local invariant = require(script.Parent.invariant)
|
||||
local getCanonicalProperty = require(script.Parent.getCanonicalProperty)
|
||||
@@ -55,10 +54,10 @@ end
|
||||
local Reconciler = {}
|
||||
Reconciler.__index = Reconciler
|
||||
|
||||
function Reconciler.new()
|
||||
function Reconciler.new(instanceMap)
|
||||
local self = {
|
||||
-- Tracks all of the instances known by the reconciler by ID.
|
||||
__instanceMap = InstanceMap.new(),
|
||||
__instanceMap = instanceMap,
|
||||
}
|
||||
|
||||
return setmetatable(self, Reconciler)
|
||||
|
||||
@@ -2,6 +2,8 @@ local Log = require(script.Parent.Parent.Log)
|
||||
local Fmt = require(script.Parent.Parent.Fmt)
|
||||
local t = require(script.Parent.Parent.t)
|
||||
|
||||
local InstanceMap = require(script.Parent.InstanceMap)
|
||||
local Reconciler = require(script.Parent.Reconciler)
|
||||
local strict = require(script.Parent.strict)
|
||||
|
||||
local Status = strict("Session.Status", {
|
||||
@@ -40,16 +42,19 @@ ServeSession.Status = Status
|
||||
|
||||
local validateServeOptions = t.strictInterface({
|
||||
apiContext = t.table,
|
||||
reconciler = t.table,
|
||||
})
|
||||
|
||||
function ServeSession.new(options)
|
||||
assert(validateServeOptions(options))
|
||||
|
||||
local instanceMap = InstanceMap.new()
|
||||
local reconciler = Reconciler.new(instanceMap)
|
||||
|
||||
local self = {
|
||||
__status = Status.NotStarted,
|
||||
__apiContext = options.apiContext,
|
||||
__reconciler = options.reconciler,
|
||||
__reconciler = reconciler,
|
||||
__instanceMap = instanceMap,
|
||||
__statusChangedCallback = nil,
|
||||
}
|
||||
|
||||
@@ -58,6 +63,17 @@ function ServeSession.new(options)
|
||||
return self
|
||||
end
|
||||
|
||||
function ServeSession:__fmtDebug(output)
|
||||
output:writeLine("ServeSession {{")
|
||||
output:indent()
|
||||
|
||||
output:writeLine("API Context: {:#?}", self.__apiContext)
|
||||
output:writeLine("Instances: {:#?}", self.__instanceMap)
|
||||
|
||||
output:unindent()
|
||||
output:write("}")
|
||||
end
|
||||
|
||||
function ServeSession:onStatusChanged(callback)
|
||||
self.__statusChangedCallback = callback
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user