mirror of
https://github.com/littensy/charm.git
synced 2026-10-22 12:41:37 +00:00
build: create project files for release
This commit is contained in:
parent
aff5f768bf
commit
b9d32ba4f2
13 changed files with 87 additions and 72 deletions
|
|
@ -1,31 +1 @@
|
|||
local Charm = require(script.Parent.charm)
|
||||
local React = if script.Parent:FindFirstChild("React")
|
||||
then require(script.Parent.React)
|
||||
else require((script.Parent :: any).react) :: never
|
||||
|
||||
--[=[
|
||||
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: Charm.Selector<State>, dependencies: { any }?): State
|
||||
local state, setState = React.useState(callback)
|
||||
|
||||
React.useEffect(function()
|
||||
setState(callback())
|
||||
return Charm.subscribe(callback, setState)
|
||||
end, dependencies or {})
|
||||
|
||||
return state
|
||||
end
|
||||
|
||||
return {
|
||||
useAtom = useAtom,
|
||||
}
|
||||
return require(script.src)
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@
|
|||
"description": "React bindings for Charm",
|
||||
"repository": "littensy/charm",
|
||||
"license": "MIT",
|
||||
"main": "src/init.luau",
|
||||
"types": "src/index.d.ts",
|
||||
"main": "init.luau",
|
||||
"types": "index.d.ts",
|
||||
"scripts": {
|
||||
"prepare": "cp ../../LICENSE.md . && cp ../../README.md .",
|
||||
"publish:wally": "wally publish"
|
||||
|
|
|
|||
31
packages/react/src/init.luau
Normal file
31
packages/react/src/init.luau
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
local Charm = require(script.Parent.Parent.charm)
|
||||
local React = if script.Parent.Parent:FindFirstChild("React")
|
||||
then require(script.Parent.Parent.React)
|
||||
else require((script.Parent.Parent :: any).react) :: never
|
||||
|
||||
--[=[
|
||||
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: Charm.Selector<State>, dependencies: { any }?): State
|
||||
local state, setState = React.useState(callback)
|
||||
|
||||
React.useEffect(function()
|
||||
setState(callback())
|
||||
return Charm.subscribe(callback, setState)
|
||||
end, dependencies or {})
|
||||
|
||||
return state
|
||||
end
|
||||
|
||||
return {
|
||||
useAtom = useAtom,
|
||||
}
|
||||
|
|
@ -3,7 +3,8 @@ name = "littensy/react-charm"
|
|||
version = "0.2.0"
|
||||
registry = "https://github.com/UpliftGames/wally-index"
|
||||
realm = "shared"
|
||||
exclude = ["package.json"]
|
||||
exclude = ["package.json", "node_modules"]
|
||||
include = ["LICENSE.md"]
|
||||
|
||||
[dependencies]
|
||||
charm = "littensy/charm@^0.9"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue