mirror of
https://github.com/littensy/charm.git
synced 2026-10-21 03:36:11 +00:00
Including Rojo project files in packages interferes with certain Wally packages that depend on roblox-ts packages
25 lines
647 B
Text
25 lines
647 B
Text
local Charm = require(script.Parent.charm)
|
|
local Vide = if script.Parent:FindFirstChild("Vide")
|
|
then require(script.Parent.Vide)
|
|
else require((script.Parent :: any).vide.src) :: never
|
|
|
|
--[=[
|
|
Subscribes to the state of an atom and returns a Vide source.
|
|
|
|
@param callback The atom or selector to subscribe to.
|
|
@return The reactive source.
|
|
]=]
|
|
local function useAtom<State>(callback: () -> State): () -> State
|
|
local state = Vide.source(callback())
|
|
local unsubscribe = Charm.subscribe(callback, function(value)
|
|
task.spawn(state :: (State) -> State, value)
|
|
end)
|
|
|
|
Vide.cleanup(unsubscribe)
|
|
|
|
return state
|
|
end
|
|
|
|
return {
|
|
useAtom = useAtom,
|
|
}
|