mirror of
https://github.com/littensy/charm.git
synced 2026-10-20 17:51:37 +00:00
fix(charm-sync): preserve global patch list order for nil patches
Resolves #67
This commit is contained in:
parent
c31e5c5a34
commit
2fc3be34d0
2 changed files with 24 additions and 3 deletions
|
|
@ -125,8 +125,8 @@ local function diffGlobalUpdateBuffer(): { any }
|
||||||
local patchCount = #globalUpdates
|
local patchCount = #globalUpdates
|
||||||
local patches = table.create(patchCount)
|
local patches = table.create(patchCount)
|
||||||
|
|
||||||
for _, update in globalUpdates do
|
for index, update in globalUpdates do
|
||||||
table.insert(patches, patch.diff(update.oldValue, update.newValue))
|
patches[index] = patch.diff(update.oldValue, update.newValue)
|
||||||
end
|
end
|
||||||
|
|
||||||
return patches
|
return patches
|
||||||
|
|
@ -146,7 +146,7 @@ local function selectFromGlobalPatchList(client: any, globalPatches: { any }): {
|
||||||
for index, update in globalUpdates do
|
for index, update in globalUpdates do
|
||||||
local patchData = globalPatches[index]
|
local patchData = globalPatches[index]
|
||||||
|
|
||||||
if not patchData then
|
if patchData == nil then
|
||||||
continue
|
continue
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -403,6 +403,27 @@ test.describe("historical", function()
|
||||||
server.flush()
|
server.flush()
|
||||||
assert(#payloads == 0, "Expected no payloads to be sent for unchanged state")
|
assert(#payloads == 0, "Expected no payloads to be sent for unchanged state")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
test("should maintain patch list order for stale update", function()
|
||||||
|
local a = Charm.atom({ x = 1 })
|
||||||
|
local b = Charm.atom({ y = 1 })
|
||||||
|
local payloads
|
||||||
|
|
||||||
|
server.connect(function(_client, _payloads)
|
||||||
|
payloads = _payloads
|
||||||
|
end)
|
||||||
|
|
||||||
|
server.addSignalsToClient("client", { a = a, b = b })
|
||||||
|
server.flush()
|
||||||
|
|
||||||
|
payloads = nil
|
||||||
|
a({ x = 1 }) -- new table, same contents: diff is nil
|
||||||
|
b({ y = 2 })
|
||||||
|
server.flush()
|
||||||
|
assert(payloads, "Expected payloads to be sent")
|
||||||
|
assert(payloads[1].type == "patch", "Expected payload to be patch")
|
||||||
|
assert(payloads[1].data.b.y == 2, "Expected payload to contain atom 'b'")
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
test("addSignalsToClient should ignore tracking context", function()
|
test("addSignalsToClient should ignore tracking context", function()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue