forked from rojo-rbx/rojo
* Implement ChangeBatcher * Use ChangeBatcher for two-way sync * Pause updates during patch application * I can English good * Break after encountering a nil Parent change This prevents __flush from erroring out when an instance's Parent is changed to nil and it has other property changes in the same batch. * Update rbx_dom_lua * Don't connect changed listeners in a running game #468 made me realize how bad of an idea this is in general... * Update TestEZ and fix sibling Ref reification test * Add ChangeBatcher tests * Test instance unpausing by breaking functionality out to __cycle * Break up the module a bit and improve tests * Shuffle requires around and edit comment * Break out more stuff, rename createChangePatch -> createPatchSet * Make ChangeBatcher responsible for unpausing all paused instances This somewhat improves the situation (of course, it would preferrable to not have to hack around this problem with Source at all). It also sets us up nicely if we come across any other properties that do anything similar. * Remove old reference to pausedBatchInstances * Use RenderStepped instead of Heartbeat and trash multi-frame pauses I probably should have done this in the first place... ChangeBatcher still needs to unpause instances, but we don't need to hold pauses for any longer than one cycle. * Remove useless branch * if not next(x) -> if next(x) == nil * Add InstanceMap:unpauseAllInstances, use it in ChangeBatcher * Move IsRunning check to InstanceMap:__maybeFireInstanceChanged
41 lines
1.1 KiB
Lua
41 lines
1.1 KiB
Lua
--[[
|
|
Take an InstanceMap and a dictionary mapping instances to sets of property
|
|
names. Populate a patch with the encoded values of all the given properties
|
|
on all the given instances (or, if any changes set Parent to nil, removals
|
|
of instances) and return the patch.
|
|
]]
|
|
|
|
local Log = require(script.Parent.Parent.Parent.Log)
|
|
|
|
local PatchSet = require(script.Parent.Parent.PatchSet)
|
|
|
|
local encodePatchUpdate = require(script.Parent.encodePatchUpdate)
|
|
|
|
return function(instanceMap, propertyChanges)
|
|
local patch = PatchSet.newEmpty()
|
|
|
|
for instance, properties in pairs(propertyChanges) do
|
|
local instanceId = instanceMap.fromInstances[instance]
|
|
|
|
if instanceId == nil then
|
|
Log.warn("Ignoring change for instance {:?} as it is unknown to Rojo", instance)
|
|
continue
|
|
end
|
|
|
|
if properties.Parent then
|
|
if instance.Parent == nil then
|
|
table.insert(patch.removed, instanceId)
|
|
else
|
|
Log.warn("Cannot sync non-nil Parent property changes yet")
|
|
end
|
|
else
|
|
local update = encodePatchUpdate(instance, instanceId, properties)
|
|
table.insert(patch.updated, update)
|
|
end
|
|
|
|
propertyChanges[instance] = nil
|
|
end
|
|
|
|
return patch
|
|
end
|