mirror of
https://github.com/littensy/charm.git
synced 2026-10-23 05:46:27 +00:00
refactor: finalize updates
This commit is contained in:
parent
6dfcaa5cfa
commit
a857797465
28 changed files with 300 additions and 240 deletions
25
src/capture.luau
Normal file
25
src/capture.luau
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue