simplify addServer/pingHistory & placeholder generation prior to optimizations

This commit is contained in:
Nick Krecklow
2020-05-08 02:39:30 -05:00
parent a3624d38ff
commit e45f8b6639
5 changed files with 29 additions and 39 deletions

View File

@ -102,26 +102,29 @@ export class App {
.reduce((sum, current) => sum + current, 0)
}
addServer = (serverId, pings, timestampPoints) => {
addServer = (serverId, payload, timestampPoints) => {
// Even if the backend has never pinged the server, the frontend is promised a placeholder object.
// result = undefined
// error = defined with "Waiting" description
// info = safely defined with configured data
const latestPing = pings[pings.length - 1]
const serverRegistration = this.serverRegistry.createServerRegistration(serverId)
serverRegistration.initServerStatus(latestPing)
serverRegistration.initServerStatus(payload)
// Push the historical data into the graph
// This will trim and format the data so it is ready for the graph to render once init
serverRegistration.addGraphPoints(pings, timestampPoints)
// pingHistory is only defined when the backend has previous ping data
// undefined pingHistory means this is a placeholder ping generated by the backend
if (typeof payload.pingHistory !== 'undefined') {
// Push the historical data into the graph
// This will trim and format the data so it is ready for the graph to render once init
serverRegistration.addGraphPoints(payload.pingHistory, timestampPoints)
}
// Create the plot instance internally with the restructured and cleaned data
serverRegistration.buildPlotInstance()
// Handle the last known state (if any) as an incoming update
// This triggers the main update pipeline and enables centralized update handling
serverRegistration.updateServerStatus(latestPing, true, this.publicConfig.minecraftVersions)
serverRegistration.updateServerStatus(payload, this.publicConfig.minecraftVersions)
// Allow the ServerRegistration to bind any DOM events with app instance context
serverRegistration.initEventListeners()