mirror of
https://github.com/littensy/charm.git
synced 2026-10-23 13:54:07 +00:00
22 lines
530 B
Text
22 lines
530 B
Text
local Charm = require("./Charm")
|
|
local Vide = require("./Vide")
|
|
|
|
--[[
|
|
Returns a reactive source that subscribes to the current value of the given
|
|
signal or getter function.
|
|
|
|
@param getter The getter function to subscribe to.
|
|
@return The reactive source.
|
|
]]
|
|
local function useSignalState<State>(getter: () -> State): () -> State
|
|
local state = Vide.source(getter())
|
|
|
|
Vide.cleanup(Charm.listen(getter, state :: (State, State?) -> ()))
|
|
|
|
return state
|
|
end
|
|
|
|
return {
|
|
useSignalState = useSignalState,
|
|
useAtom = useSignalState,
|
|
}
|