refactor!: minimal react api

This commit is contained in:
Richard 2024-05-03 01:02:42 -07:00
parent 047be71eaa
commit f2f7a16599
10 changed files with 59 additions and 144 deletions

View file

@ -0,0 +1,42 @@
local atom = require(script.Parent.Parent.Parent.atom)
local useAtom = require(script.Parent.Parent.Parent.react.useAtom)
local renderHook = require(script.Parent.helpers.renderHook)
return function()
it("tracks atom state", function()
local source = atom(0)
local hook = renderHook(function()
return useAtom(source)
end)
expect(hook.result).to.equal(0)
source(1)
expect(hook.result).to.equal(1)
end)
it("accepts a molecule", function()
local source = atom(0)
local hook = renderHook(function()
return useAtom(function()
return 2 * source()
end)
end)
expect(hook.result).to.equal(0)
source(1)
expect(hook.result).to.equal(2)
end)
it("tracks dependencies", function()
local source = atom(0)
local hook = renderHook(function()
return useAtom(source, { source })
end)
expect(hook.result).to.equal(0)
source(1)
expect(hook.result).to.equal(1)
source = atom(0)
hook.rerender()
expect(hook.result).to.equal(0)
source(1)
expect(hook.result).to.equal(1)
end)
end