mirror of
https://github.com/littensy/charm.git
synced 2026-10-21 11:44:08 +00:00
refactor: update charm sync api
This commit is contained in:
parent
1e0b10aef6
commit
32788b19e1
13 changed files with 359 additions and 335 deletions
25
packages/charm-sync/src/__tests__/utils.spec.luau
Normal file
25
packages/charm-sync/src/__tests__/utils.spec.luau
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
local Charm = require("../../Charm")
|
||||
local suite = require("../../../../test/suite")
|
||||
local utils = require("../utils")
|
||||
|
||||
local atom = Charm.atom
|
||||
local test = suite.test
|
||||
|
||||
test("should flatten atoms", function()
|
||||
local getF, setF = Charm.signal(0)
|
||||
local input = {
|
||||
a = atom(0),
|
||||
b = { c = atom(0) },
|
||||
d = { e = { f = utils.signalToAtom(getF, setF) } },
|
||||
}
|
||||
local result = utils.flattenState(input)
|
||||
|
||||
assert(result.a == input.a, "should flatten the first level")
|
||||
assert(result["b/c"] == input.b.c, "should flatten the second level")
|
||||
assert(result["d/e/f"] == input.d.e.f, "should flatten the third level")
|
||||
|
||||
assert(result.b == nil, "should remove the original nested tables")
|
||||
assert(result.d == nil, "should remove the original nested tables")
|
||||
end)
|
||||
|
||||
return {}
|
||||
Loading…
Add table
Add a link
Reference in a new issue