🍀 Atomic state management for Roblox https://npmjs.org/package/@rbxts/charm
Find a file
2024-03-03 22:50:59 -08:00
.github/workflows refactor: polish code, logo 2024-02-25 12:05:59 -08:00
.vscode feat: initial commit 2024-02-25 03:41:09 -08:00
bin feat: initial commit 2024-02-25 03:41:09 -08:00
images refactor: polish code, logo 2024-02-25 12:05:59 -08:00
src feat!: replace split with mapAtom 2024-03-03 22:50:59 -08:00
.eslintrc feat: initial commit 2024-02-25 03:41:09 -08:00
.gitattributes feat: initial commit 2024-02-25 03:41:09 -08:00
.gitignore feat: initial commit 2024-02-25 03:41:09 -08:00
.luaurc feat: initial commit 2024-02-25 03:41:09 -08:00
.prettierrc feat: initial commit 2024-02-25 03:41:09 -08:00
aftman.toml feat: initial commit 2024-02-25 03:41:09 -08:00
default.project.json feat: initial commit 2024-02-25 03:41:09 -08:00
dev.project.json feat: initial commit 2024-02-25 03:41:09 -08:00
LICENSE.md feat: initial commit 2024-02-25 03:41:09 -08:00
package.json feat: initial commit 2024-02-25 03:41:09 -08:00
pnpm-lock.yaml feat: initial commit 2024-02-25 03:41:09 -08:00
README.md feat!: replace split with mapAtom 2024-03-03 22:50:59 -08:00
selene.toml feat: initial commit 2024-02-25 03:41:09 -08:00
testez-companion.toml feat: initial commit 2024-02-25 03:41:09 -08:00
testez.yml feat: initial commit 2024-02-25 03:41:09 -08:00
tsconfig.json feat: initial commit 2024-02-25 03:41:09 -08:00
wally.lock feat: initial commit 2024-02-25 03:41:09 -08:00
wally.toml feat: initial commit 2024-02-25 03:41:09 -08:00

Logo

Charm

Atomic state management for Roblox.
npm package →

GitHub Workflow Status NPM Version GitHub License

Charm is a Roblox state management library, inspired by Jotai. Designed to be an alternative to Reflex, Charm aims to bring an atomic and composable approach to your game's state.

Note

Charm is incomplete and not ready for use.

📦 Setup

TypeScript

Install Charm through your package manager of choice.
React is optional, but highly recommended.

npm install @rbxts/charm
yarn add @rbxts/charm
pnpm add @rbxts/charm

Wally

Add littensy/charm to your wally.toml file.

[dependencies]
Charm = "littensy/charm@VERSION"

📚 Documentation

Core

atom(state)

derive(...atoms, combiner)

subscribe(atom, listener)

observe(atom, observer)

mapAtom(atom, mapper)

Atom

Atom(state?)

Atom.get(selector?)

Atom.set(state)

Atom.memo(areEqual)

Atom.readonly()

Atom.writable(onSet?)

Atom.named(label)

Atom.unmount()

React

useAtom(atom, selector?)

useAtomState(atom)

useSetAtom(atom)

Sync

sync.client(options)

Client.sync(payload)

sync.server(options)

Server.onSync(callback)

Server.hydrate(player)

🚀 Examples

Counter atom

import { atom, derive, subscribe } from "@rbxts/charm";

const counterAtom = atom(0);
const doubleCounterAtom = derive(counterAtom, (counter) => counter * 2);

subscribe(doubleCounterAtom, (value) => {
	print(value);
});

counterAtom(1);
counterAtom((count) => count + 1);

Counter component

import React from "@rbxts/react";
import { useAtom } from "@rbxts/charm";
import { counterAtom } from "./counter-atom";

function Counter() {
	const [count, setCount] = useAtom(counterAtom);

	return (
		<textlabel
			Text={`Count: ${count}`}
			Size={new UDim2(0, 100, 0, 50)}
			Event={{
				Activated: () => setCount(count + 1),
			}}
		/>
	);
}

🙋 Concerns

In Jotai, atom() returns an atom config, and its state is managed entirely by the Provider. However, in Charm, atom() returns something closer to a store, and its state is managed by the atom itself.

Charm does this for simplicity in use cases outside of React, but this might go against Jotai's focus on pure functional programming. More insight is needed to determine if this is a good idea.


Charm is released under the MIT License.

MIT License