mirror of
https://github.com/littensy/charm.git
synced 2026-10-21 11:44:08 +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
12
packages/vide-charm/src/__tests__/spec.luau
Normal file
12
packages/vide-charm/src/__tests__/spec.luau
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
local suite = require("../../../../test/suite")
|
||||
|
||||
suite.describe("vide-charm", function()
|
||||
if not game then
|
||||
return suite.skip()
|
||||
end
|
||||
suite.describe("useAtom", function()
|
||||
require("./useAtom.spec")
|
||||
end)
|
||||
end)
|
||||
|
||||
return {}
|
||||
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 {}
|
||||
1
packages/vide-charm/src/index.d.ts
vendored
Normal file
1
packages/vide-charm/src/index.d.ts
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
export {};
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
local Charm = require(script.Parent.Charm)
|
||||
local Vide = require(script.Parent.Vide)
|
||||
local Charm = require("./Charm")
|
||||
local Vide = require("./Vide")
|
||||
|
||||
local subscribe = Charm.subscribe
|
||||
local source = Vide.source
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue