mirror of
https://github.com/littensy/charm.git
synced 2026-10-20 17:51:37 +00:00
refactor: move modules to packages (#41)
* refactor: move modules to `packages` * chore: remove .vscode
This commit is contained in:
parent
89f1dfeaa5
commit
8eddd182d3
49 changed files with 152 additions and 174 deletions
6
packages/vide/default.project.json
Normal file
6
packages/vide/default.project.json
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"name": "VideCharm",
|
||||
"tree": {
|
||||
"$path": "src"
|
||||
}
|
||||
}
|
||||
19
packages/vide/package.json
Normal file
19
packages/vide/package.json
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"name": "@rbxts/vide-charm",
|
||||
"version": "0.1.1",
|
||||
"description": "Vide bindings for Charm",
|
||||
"repository": "littensy/charm",
|
||||
"license": "MIT",
|
||||
"main": "src/init.luau",
|
||||
"types": "src/index.d.ts",
|
||||
"scripts": {
|
||||
"prepare": "cp ../../LICENSE.md . && cp ../../README.md .",
|
||||
"publish:wally": "wally publish"
|
||||
},
|
||||
"dependencies": {
|
||||
"@rbxts/charm": "workspace:*"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@rbxts/vide": "*"
|
||||
}
|
||||
}
|
||||
9
packages/vide/src/index.d.ts
vendored
Normal file
9
packages/vide/src/index.d.ts
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import { Selector } from "@rbxts/charm";
|
||||
|
||||
/**
|
||||
* Subscribes to the state of an atom and returns a Vide source.
|
||||
*
|
||||
* @param callback The atom or selector to subscribe to.
|
||||
* @returns The reactive source.
|
||||
*/
|
||||
export function useAtom<T>(callback: Selector<T>): () => T;
|
||||
27
packages/vide/src/init.luau
Normal file
27
packages/vide/src/init.luau
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
local Charm = require(script.Parent.Charm)
|
||||
local Vide = if script.Parent:FindFirstChild("vide")
|
||||
then require(script.Parent.vide.src) :: never
|
||||
else require(script.Parent.Vide)
|
||||
|
||||
--[=[
|
||||
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(function()
|
||||
state(value)
|
||||
end)
|
||||
end)
|
||||
|
||||
Vide.cleanup(unsubscribe)
|
||||
|
||||
return state
|
||||
end
|
||||
|
||||
return {
|
||||
useAtom = useAtom,
|
||||
}
|
||||
9
packages/vide/wally.toml
Normal file
9
packages/vide/wally.toml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
[package]
|
||||
name = "littensy/vide-charm"
|
||||
version = "0.1.1"
|
||||
registry = "https://github.com/UpliftGames/wally-index"
|
||||
realm = "shared"
|
||||
|
||||
[dependencies]
|
||||
Charm = "littensy/charm@^0.8"
|
||||
Vide = "centau/vide@^0.3"
|
||||
Loading…
Add table
Add a link
Reference in a new issue