refactor: finalize updates

This commit is contained in:
Richard 2024-03-25 18:57:22 -07:00
parent 6dfcaa5cfa
commit a857797465
28 changed files with 300 additions and 240 deletions

25
src/capture.luau Normal file
View file

@ -0,0 +1,25 @@
local store = require(script.Parent.store)
local types = require(script.Parent.types)
type Atom<T> = types.Atom<T>
type Source<T> = types.Source<T>
local function capture<T>(source: Source<T>): ({ [Atom<any>]: true }, T)
if store.listeners[source] then
return { [source] = true }, source()
end
store.setCapturing(true)
local success, result = pcall(source)
store.setCapturing(false)
local dependencies = table.clone(store.captured)
table.clear(store.captured)
if not success then
warn("An error occurred while calling an atom:", result)
end
return dependencies, result
end
return capture