mirror of
https://github.com/littensy/charm.git
synced 2026-10-24 06:51:37 +00:00
fix: avoid reconnecting to dependencies after cleanup (#14)
* fix: cancel reconnection when unsubscribing * test: remove print * feat: allow factory to return nil * perf: use `next` iteration
This commit is contained in:
parent
62be3e496d
commit
c6762a6525
14 changed files with 87 additions and 63 deletions
|
|
@ -20,9 +20,13 @@ local function computed<T>(molecule: Molecule<T>, options: AtomOptions<T>?): Mol
|
|||
local computedRef = setmetatable({ current = computedAtom }, { __mode = "v" })
|
||||
|
||||
local function listener()
|
||||
if computedRef.current then
|
||||
dependencies, state = store.reconnect(molecule, dependencies, listener, computedRef.current)
|
||||
computedRef.current(state)
|
||||
local computedAtom = computedRef.current
|
||||
|
||||
if computedAtom then
|
||||
store.disconnect(dependencies, listener)
|
||||
dependencies, state = store.capture(molecule)
|
||||
store.connect(dependencies, listener, computedAtom)
|
||||
computedAtom(state)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue