feat(sync): add flatten() function (#43)

This commit is contained in:
richard 2025-01-25 16:11:34 -08:00 • committed by GitHub
parent 63388761f8
commit 8063ea3142
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 89 additions and 0 deletions

View file

@ -0,0 +1,24 @@
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Charm = require(ReplicatedStorage.DevPackages.Charm)
local atom = Charm.atom
local CharmSync = require(ReplicatedStorage.DevPackages.CharmSync)
local flatten = CharmSync.flatten
return function()
it("flattens atoms", function()
local input = {
a = atom(0),
b = { c = atom(0) },
d = { e = { f = atom(0) } },
}
local result = flatten(input)
expect(result.a).to.equal(input.a)
expect(result["b/c"]).to.equal(input.b.c)
expect(result["d/e/f"]).to.equal(input.d.e.f)
expect(result.b).to.never.be.ok()
expect(result.d).to.never.be.ok()
end)
end