refactor: code quality

This commit is contained in:
Richard 2024-04-20 18:48:09 -07:00
parent f0a7938703
commit 8ca299f671
16 changed files with 82 additions and 101 deletions

View file

@ -1,6 +1,6 @@
local atom = require(script.Parent.Parent.atom)
local batch = require(script.Parent.Parent.batch)
local effect = require(script.Parent.Parent.effect)
local store = require(script.Parent.Parent.store)
local subscribe = require(script.Parent.Parent.subscribe)
return function()
@ -10,7 +10,7 @@ return function()
subscribe(source, function()
value += 1
end)
batch(function()
store.batch(function()
source(2)
source(3)
source(4)
@ -28,7 +28,7 @@ return function()
b()
end)
value = 0 -- effect() will run once initially
batch(function()
store.batch(function()
a(2)
b(2)
a(3)

View file

@ -1,10 +1,10 @@
local atom = require(script.Parent.Parent.atom)
local capture = require(script.Parent.Parent.capture)
local store = require(script.Parent.Parent.store)
return function()
it("captures atoms from a function", function()
local a, b, c = atom(1), atom(1), atom(2)
local captured, result = capture(function()
local captured, result = store.capture(function()
return a() + b()
end)
expect(captured[a]).to.be.ok()
@ -15,7 +15,7 @@ return function()
it("captures an atom by itself", function()
local a = atom(1)
local captured, result = capture(a)
local captured, result = store.capture(a)
expect(captured[a]).to.be.ok()
expect(result).to.equal(1)
end)

View file

@ -42,7 +42,7 @@ return function()
local function listenersDecreased()
local count = 0
for _ in pairs(store.listeners[source]) do
for _ in next, store.listeners[source] do
count += 1
end
max = math.max(max, count)

View file

@ -2,7 +2,7 @@ local validate = require(script.Parent.Parent.Parent.sync.validate)
return function()
it("validates inputs", function()
local cases = {
local cases: { [string]: { value: any, expected: any } } = {
array = { value = { 1, 2, 3 }, expected = true },
array_sparse = { value = { 1, nil :: any, 3 }, expected = true },
array_sparse_invalid = { value = { [1] = 0, [3] = 0 }, expected = false },
@ -15,7 +15,7 @@ return function()
number_nan = { value = 0 / 0, expected = false },
}
for key, case in pairs(cases) do
for key, case in cases do
local success, result = pcall(function()
validate(case.value, key)
end)

View file

@ -1,11 +1,11 @@
local atom = require(script.Parent.Parent.atom)
local capture = require(script.Parent.Parent.capture)
local store = require(script.Parent.Parent.store)
local unwrap = require(script.Parent.Parent.unwrap)
return function()
it("calls an atom without capturing it", function()
local a, b, c = atom(1), atom(1), atom(1)
local captured, result = capture(function()
local captured, result = store.capture(function()
return a() + unwrap(b) + c()
end)
expect(captured[a]).to.be.ok()