mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-23 22:25:26 +00:00
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 = {
|
local self = {
|
||||||
__baseUrl = baseUrl,
|
__baseUrl = baseUrl,
|
||||||
__serverId = nil,
|
__sessionId = nil,
|
||||||
__messageCursor = -1,
|
__messageCursor = -1,
|
||||||
__connected = true,
|
__connected = true,
|
||||||
}
|
}
|
||||||
@@ -95,6 +95,19 @@ function ApiContext.new(baseUrl)
|
|||||||
return setmetatable(self, ApiContext)
|
return setmetatable(self, ApiContext)
|
||||||
end
|
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()
|
function ApiContext:disconnect()
|
||||||
self.__connected = false
|
self.__connected = false
|
||||||
end
|
end
|
||||||
@@ -117,7 +130,7 @@ function ApiContext:connect()
|
|||||||
end)
|
end)
|
||||||
:andThen(rejectWrongPlaceId)
|
:andThen(rejectWrongPlaceId)
|
||||||
:andThen(function(body)
|
:andThen(function(body)
|
||||||
self.__serverId = body.serverId
|
self.__sessionId = body.sessionId
|
||||||
|
|
||||||
return body
|
return body
|
||||||
end)
|
end)
|
||||||
@@ -130,7 +143,7 @@ function ApiContext:read(ids)
|
|||||||
:andThen(rejectFailedRequests)
|
:andThen(rejectFailedRequests)
|
||||||
:andThen(Http.Response.json)
|
:andThen(Http.Response.json)
|
||||||
:andThen(function(body)
|
:andThen(function(body)
|
||||||
if body.serverId ~= self.__serverId then
|
if body.sessionId ~= self.__sessionId then
|
||||||
return Promise.reject("Server changed ID")
|
return Promise.reject("Server changed ID")
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -162,7 +175,7 @@ function ApiContext:retrieveMessages()
|
|||||||
:andThen(rejectFailedRequests)
|
:andThen(rejectFailedRequests)
|
||||||
:andThen(Http.Response.json)
|
:andThen(Http.Response.json)
|
||||||
:andThen(function(body)
|
:andThen(function(body)
|
||||||
if body.serverId ~= self.__serverId then
|
if body.sessionId ~= self.__sessionId then
|
||||||
return Promise.reject("Server changed ID")
|
return Promise.reject("Server changed ID")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ local ApiContext = require(Plugin.ApiContext)
|
|||||||
local Assets = require(Plugin.Assets)
|
local Assets = require(Plugin.Assets)
|
||||||
local Config = require(Plugin.Config)
|
local Config = require(Plugin.Config)
|
||||||
local DevSettings = require(Plugin.DevSettings)
|
local DevSettings = require(Plugin.DevSettings)
|
||||||
local Reconciler = require(Plugin.Reconciler)
|
|
||||||
local ServeSession = require(Plugin.ServeSession)
|
local ServeSession = require(Plugin.ServeSession)
|
||||||
local Version = require(Plugin.Version)
|
local Version = require(Plugin.Version)
|
||||||
local preloadAssets = require(Plugin.preloadAssets)
|
local preloadAssets = require(Plugin.preloadAssets)
|
||||||
@@ -115,7 +114,6 @@ function App:startSession(address, port)
|
|||||||
local baseUrl = ("http://%s:%s"):format(address, port)
|
local baseUrl = ("http://%s:%s"):format(address, port)
|
||||||
self.serveSession = ServeSession.new({
|
self.serveSession = ServeSession.new({
|
||||||
apiContext = ApiContext.new(baseUrl),
|
apiContext = ApiContext.new(baseUrl),
|
||||||
reconciler = Reconciler.new(),
|
|
||||||
})
|
})
|
||||||
|
|
||||||
self.serveSession:onStatusChanged(function(status, details)
|
self.serveSession:onStatusChanged(function(status, details)
|
||||||
|
|||||||
@@ -24,12 +24,25 @@ function InstanceMap:__fmtDebug(output)
|
|||||||
output:writeLine("InstanceMap {{")
|
output:writeLine("InstanceMap {{")
|
||||||
output:indent()
|
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
|
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
|
end
|
||||||
|
|
||||||
output:unindent()
|
output:unindent()
|
||||||
output:writeLine("}")
|
output:write("}")
|
||||||
end
|
end
|
||||||
|
|
||||||
function InstanceMap:insert(id, instance)
|
function InstanceMap:insert(id, instance)
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ 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 Log = require(script.Parent.Parent.Log)
|
||||||
|
|
||||||
local InstanceMap = require(script.Parent.InstanceMap)
|
|
||||||
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)
|
||||||
@@ -55,10 +54,10 @@ end
|
|||||||
local Reconciler = {}
|
local Reconciler = {}
|
||||||
Reconciler.__index = Reconciler
|
Reconciler.__index = Reconciler
|
||||||
|
|
||||||
function Reconciler.new()
|
function Reconciler.new(instanceMap)
|
||||||
local self = {
|
local self = {
|
||||||
-- Tracks all of the instances known by the reconciler by ID.
|
-- Tracks all of the instances known by the reconciler by ID.
|
||||||
__instanceMap = InstanceMap.new(),
|
__instanceMap = instanceMap,
|
||||||
}
|
}
|
||||||
|
|
||||||
return setmetatable(self, Reconciler)
|
return setmetatable(self, Reconciler)
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ 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 InstanceMap = require(script.Parent.InstanceMap)
|
||||||
|
local Reconciler = require(script.Parent.Reconciler)
|
||||||
local strict = require(script.Parent.strict)
|
local strict = require(script.Parent.strict)
|
||||||
|
|
||||||
local Status = strict("Session.Status", {
|
local Status = strict("Session.Status", {
|
||||||
@@ -40,16 +42,19 @@ ServeSession.Status = Status
|
|||||||
|
|
||||||
local validateServeOptions = t.strictInterface({
|
local validateServeOptions = t.strictInterface({
|
||||||
apiContext = t.table,
|
apiContext = t.table,
|
||||||
reconciler = t.table,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
function ServeSession.new(options)
|
function ServeSession.new(options)
|
||||||
assert(validateServeOptions(options))
|
assert(validateServeOptions(options))
|
||||||
|
|
||||||
|
local instanceMap = InstanceMap.new()
|
||||||
|
local reconciler = Reconciler.new(instanceMap)
|
||||||
|
|
||||||
local self = {
|
local self = {
|
||||||
__status = Status.NotStarted,
|
__status = Status.NotStarted,
|
||||||
__apiContext = options.apiContext,
|
__apiContext = options.apiContext,
|
||||||
__reconciler = options.reconciler,
|
__reconciler = reconciler,
|
||||||
|
__instanceMap = instanceMap,
|
||||||
__statusChangedCallback = nil,
|
__statusChangedCallback = nil,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,6 +63,17 @@ function ServeSession.new(options)
|
|||||||
return self
|
return self
|
||||||
end
|
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)
|
function ServeSession:onStatusChanged(callback)
|
||||||
self.__statusChangedCallback = callback
|
self.__statusChangedCallback = callback
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user