mirror of
https://github.com/littensy/charm.git
synced 2026-10-22 12:41:37 +00:00
refactor: use new type solver
This commit is contained in:
parent
748dbc5014
commit
22b440e35f
32 changed files with 169 additions and 155 deletions
|
|
@ -13,12 +13,12 @@ local React = require("./React")
|
|||
@param dependencies An array of values used to memoize the getter.
|
||||
@return The current state.
|
||||
]]
|
||||
local function useSignalState<T>(getter: () -> T, dependencies: { any }?): T
|
||||
local function useSignalState<T>(getter: () -> T, dependencies: {}?): T
|
||||
local value, setValue = React.useState(getter)
|
||||
|
||||
React.useLayoutEffect(function()
|
||||
return Charm.listen(getter, setValue)
|
||||
end, dependencies or {})
|
||||
return Charm.listen(getter, setValue :: (T, T?) -> ())
|
||||
end, dependencies :: { any } or {})
|
||||
|
||||
return value
|
||||
end
|
||||
|
|
@ -34,13 +34,13 @@ end
|
|||
@param dependencies An array of values used to memoize the getter.
|
||||
@return A binding that stores the current state.
|
||||
]]
|
||||
local function useSignalBinding<T>(getter: () -> T, dependencies: { any }?)
|
||||
local function useSignalBinding<T>(getter: () -> T, dependencies: {}?)
|
||||
local initialValue = React.useMemo(getter, {})
|
||||
local binding, setBinding = React.useBinding(initialValue)
|
||||
|
||||
React.useLayoutEffect(function()
|
||||
return Charm.listen(getter, setBinding)
|
||||
end, dependencies or {})
|
||||
return Charm.listen(getter, setBinding :: (T, T?) -> ())
|
||||
end, dependencies :: { any } or {})
|
||||
|
||||
return binding
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue