refactor: move modules to packages (#41)

* refactor: move modules to `packages`

* chore: remove .vscode
This commit is contained in:
richard 2025-01-25 13:12:50 -08:00 • committed by GitHub
parent 89f1dfeaa5
commit 8eddd182d3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
49 changed files with 152 additions and 174 deletions

View file

@ -0,0 +1,6 @@
{
"name": "VideCharm",
"tree": {
"$path": "src"
}
}

View 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
View 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;

View 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
View 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"