feat: use alien-signals

This commit is contained in:
littensy 2025-05-03 18:24:39 -07:00
parent d7a1f62c3c
commit 861ee5acd7
76 changed files with 3112 additions and 1862 deletions

View file

@ -1,46 +1,48 @@
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerScriptService = game:GetService("ServerScriptService")
local Charm = require(ReplicatedStorage.DevPackages.Charm)
local atom = Charm.atom
local ReactCharm = require(ReplicatedStorage.DevPackages.ReactCharm)
local useAtom = ReactCharm.useAtom
local renderHook = require(script.Parent.Parent.utils.renderHook)
local suite = require(ServerScriptService.Tests.suite)
return function()
it("tracks atom state", function()
local state = atom(0)
local hook = renderHook(function()
return useAtom(state)
end)
expect(hook.result).to.equal(0)
state(1)
expect(hook.result).to.equal(1)
end)
local atom = Charm.atom
local useAtom = ReactCharm.useAtom
local test = suite.test
it("accepts a selector", function()
local state = atom(0)
local hook = renderHook(function()
return useAtom(function()
return 2 * state()
end)
end)
expect(hook.result).to.equal(0)
state(1)
expect(hook.result).to.equal(2)
test("tracks atom state", function()
local state = atom(0)
local hook = renderHook(function()
return useAtom(state)
end)
assert(hook.result == 0)
state(1)
assert(hook.result == 1)
end)
it("tracks dependencies", function()
local state = atom(0)
local hook = renderHook(function()
return useAtom(state, { state })
test("accepts a selector", function()
local state = atom(0)
local hook = renderHook(function()
return useAtom(function()
return 2 * state()
end)
expect(hook.result).to.equal(0)
state(1)
expect(hook.result).to.equal(1)
state = atom(0)
hook.rerender()
expect(hook.result).to.equal(0)
state(1)
expect(hook.result).to.equal(1)
end)
end
assert(hook.result == 0)
state(1)
assert(hook.result == 2)
end)
test("tracks dependencies", function()
local state = atom(0)
local hook = renderHook(function()
return useAtom(state, { state })
end)
assert(hook.result == 0)
state(1)
assert(hook.result == 1)
state = atom(0)
hook.rerender()
assert(hook.result == 0)
state(1)
assert(hook.result == 1)
end)