mirror of
https://github.com/littensy/charm.git
synced 2026-10-20 17:51:37 +00:00
feat!: run listen and subscribe callback in untracked
This commit is contained in:
parent
50afcaf6e9
commit
5c27052965
11 changed files with 28 additions and 156 deletions
|
|
@ -1,5 +1 @@
|
|||
local Charm = require(script.Parent.Parent.charm.src)
|
||||
|
||||
export type Atom<T = any> = Charm.Atom<T>
|
||||
|
||||
return Charm
|
||||
return require(script.Parent.Parent.charm.src)
|
||||
|
|
|
|||
|
|
@ -1,12 +1 @@
|
|||
type CoreReactBinding<T> = {
|
||||
getValue: (self: CoreReactBinding<T>) -> T,
|
||||
_source: string?,
|
||||
}
|
||||
|
||||
type ReactBindingMap = {
|
||||
map: <T, U>(self: CoreReactBinding<T> & ReactBindingMap, (T) -> U) -> ReactBindingMap & CoreReactBinding<U>,
|
||||
}
|
||||
|
||||
export type Binding<T> = CoreReactBinding<T> & ReactBindingMap
|
||||
|
||||
return require(script.Parent.Parent.Parent:WaitForChild("@rbxts-js").React)
|
||||
|
|
|
|||
|
|
@ -17,10 +17,7 @@ local function useSignalState<T>(getter: () -> T, dependencies: { any }?): T
|
|||
local value, setValue = React.useState(getter)
|
||||
|
||||
React.useLayoutEffect(function()
|
||||
return Charm.effect(function()
|
||||
-- Wrap in untracked to avoid tracking inner effect and atom calls
|
||||
Charm.untracked(setValue, getter())
|
||||
end)
|
||||
return Charm.listen(getter, setValue)
|
||||
end, dependencies or {})
|
||||
|
||||
return value
|
||||
|
|
@ -42,10 +39,7 @@ local function useSignalBinding<T>(getter: () -> T, dependencies: { any }?)
|
|||
local binding, setBinding = React.useBinding(initialValue)
|
||||
|
||||
React.useLayoutEffect(function()
|
||||
return Charm.effect(function()
|
||||
-- Wrap in untracked to avoid tracking inner effect and atom calls
|
||||
Charm.untracked(setBinding, getter())
|
||||
end)
|
||||
return Charm.listen(getter, setBinding)
|
||||
end, dependencies or {})
|
||||
|
||||
return binding
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue