mirror of
https://github.com/littensy/charm.git
synced 2026-10-21 11:44:08 +00:00
feat: allow conditional dependencies (#4)
* feat: allow conditional dependencies * docs: remove conditional deps warnings * fix: allow nested captures * docs: add dev flag * fix: `try()` uses pcall if passed `finally()` * docs: interval is optional * docs: update readme * docs: add client/server tags
This commit is contained in:
parent
fbc86d22c6
commit
a90d131fed
14 changed files with 290 additions and 98 deletions
|
|
@ -16,20 +16,18 @@ local function subscribe<T>(molecule: Molecule<T>, callback: (state: T, prev: T)
|
|||
|
||||
local function listener()
|
||||
local prevState = state
|
||||
state = molecule()
|
||||
|
||||
captured, state = store.reconnect(molecule, captured, listener)
|
||||
|
||||
if state ~= prevState then
|
||||
callback(state, prevState)
|
||||
end
|
||||
end
|
||||
|
||||
for atom in captured do
|
||||
store.listeners[atom][listener] = true
|
||||
end
|
||||
store.connect(captured, listener)
|
||||
|
||||
return function()
|
||||
for atom in captured do
|
||||
store.listeners[atom][listener] = nil
|
||||
end
|
||||
store.disconnect(captured, listener)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue