mirror of
https://github.com/littensy/charm.git
synced 2026-10-20 17:51:37 +00:00
refactor: embrace scope cleanup, restructure code
This commit is contained in:
parent
3eba56e298
commit
8d385356cd
81 changed files with 687 additions and 626 deletions
|
|
@ -1,2 +0,0 @@
|
|||
--!nocheck
|
||||
return require(script.Parent.charm.src)
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
--!nocheck
|
||||
return require(script.Parent.react)
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
{
|
||||
"name": "ReactCharm",
|
||||
"tree": {
|
||||
"$path": "src"
|
||||
}
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
local Charm = require(script.Parent.Charm)
|
||||
local React = require(script.Parent.React)
|
||||
|
||||
local listen = Charm.listen
|
||||
local useEffect = React.useEffect
|
||||
local useState = React.useState
|
||||
|
||||
--[=[
|
||||
A hook that subscribes to changes in the given atom or selector. The
|
||||
component is re-rendered whenever the state changes.
|
||||
|
||||
If the `dependencies` array is provided, the subscription to the atom or
|
||||
selector is re-created whenever the dependencies change. Otherwise, the
|
||||
subscription is created once when the component is mounted.
|
||||
|
||||
@param callback The atom or selector to subscribe to.
|
||||
@param dependencies An array of values that the subscription depends on.
|
||||
@return The current state.
|
||||
]=]
|
||||
local function useAtom<State>(callback: () -> State, dependencies: { any }?): State
|
||||
local state, setState = useState(callback)
|
||||
|
||||
useEffect(function()
|
||||
return listen(callback, setState)
|
||||
end, dependencies or {})
|
||||
|
||||
return state
|
||||
end
|
||||
|
||||
return {
|
||||
useAtom = useAtom,
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
[package]
|
||||
name = "littensy/react-charm"
|
||||
version = "0.3.0"
|
||||
registry = "https://github.com/UpliftGames/wally-index"
|
||||
realm = "shared"
|
||||
exclude = ["Charm.luau", "React.luau"]
|
||||
|
||||
[dependencies]
|
||||
Charm = "littensy/charm@^0.10"
|
||||
React = "jsdotlua/react@^17"
|
||||
Loading…
Add table
Add a link
Reference in a new issue