mirror of
https://github.com/littensy/charm.git
synced 2026-10-22 21:01:38 +00:00
chore: housekeeping
This commit is contained in:
parent
4931515a95
commit
4edc952c05
77 changed files with 230 additions and 602 deletions
21
packages/vide-charm/src/init.luau
Normal file
21
packages/vide-charm/src/init.luau
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
local Charm = require(script.Parent.Charm)
|
||||
local Vide = require(script.Parent.Vide)
|
||||
|
||||
local subscribe = Charm.subscribe
|
||||
local source = Vide.source
|
||||
local cleanup = Vide.cleanup
|
||||
|
||||
--- Subscribes to the state of an atom or selector. Returns a source that
|
||||
--- updates when the state changes.
|
||||
---
|
||||
--- @param selector The atom or selector to subscribe to.
|
||||
--- @return The reactive source.
|
||||
local function useAtom<State>(selector: () -> State): () -> State
|
||||
local state = source(selector())
|
||||
cleanup(subscribe(selector, state))
|
||||
return state
|
||||
end
|
||||
|
||||
return {
|
||||
useAtom = useAtom,
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue