mirror of
https://github.com/littensy/charm.git
synced 2026-10-22 12:41:37 +00:00
refactor: improve structure and alien-signals integration
This commit is contained in:
parent
a9c60c701f
commit
95476e93ec
107 changed files with 3660 additions and 815 deletions
37
packages/vide-charm/src/__tests__/useAtom.spec.luau
Normal file
37
packages/vide-charm/src/__tests__/useAtom.spec.luau
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
local Charm = require("../../Charm")
|
||||
local Vide = require("../../Vide")
|
||||
local VideCharm = require("../")
|
||||
local suite = require("../../../../test/suite")
|
||||
|
||||
local atom = Charm.atom
|
||||
local root = Vide.root
|
||||
local useAtom = VideCharm.useAtom
|
||||
local test = suite.test
|
||||
|
||||
test("tracks atom state", function()
|
||||
local state = atom(0)
|
||||
local source
|
||||
local cleanup = root(function()
|
||||
source = useAtom(state)
|
||||
end)
|
||||
assert(source() == 0, "should return 0")
|
||||
state(1)
|
||||
assert(source() == 1, "should return 1")
|
||||
cleanup()
|
||||
end)
|
||||
|
||||
test("accepts a selector", function()
|
||||
local state = atom(0)
|
||||
local source
|
||||
local cleanup = root(function()
|
||||
source = useAtom(function()
|
||||
return 2 * state()
|
||||
end)
|
||||
end)
|
||||
assert(source() == 0, "should return 0")
|
||||
state(1)
|
||||
assert(source() == 2, "should return 2")
|
||||
cleanup()
|
||||
end)
|
||||
|
||||
return {}
|
||||
Loading…
Add table
Add a link
Reference in a new issue