1.3.2 • Published 1 year ago

@rbxts/sweet-charm v1.3.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

🌸 Sweet Charm

Library for charm that allows to create atom classes and sync them using repositories

⚙️ Credits

littensy - creator of original library Charm

SUMER - creator of this library (discord: sumer_real)

🌩 Installation

npm install @rbxts/sweet-charm

📖 Documentation

AtomClass

const myAtom = new AtomClass(1);

const unsubscribe = myAtom.subscribe((newData) => {
	print(newData);
});

myAtom.update(10);
myAtom.update((current) => current + 100);

print("current data", myAtom.getData());
print("raw atom", myAtom.getAtom());

AtomRepository

type Event = {
	name: string,
	until: number,
}

type Item = {
	name: string,
	power: number,
}

type MyAtoms = {
	events: AtomClass<Event[]>,
	items: AtomClass<Item[]>,
}

const repo = new AtomRepository<MyAtoms>();

repo.define({
	events: new AtomClass([]),
	items: new AtomClass([]),
});

print("events", repo.get("events").getData());
print("items", repo.get("items").getData());
print("all atoms", repo.getAtoms());

const subRepo = repo.subdivide();

print("parent events", subRepo.get("events"));

repo.remove("events")  // you can remove atom by name from repository

AtomRepository syncer

type Event = {
	name: string,
	until: number,
}

type Item = {
	name: string,
	power: number,
}

type MyAtoms = {
	events: AtomClass<Event[]>,
	items: AtomClass<Item[]>,
}

const repo = new AtomRepository<MyAtoms>();

repo.define({
	events: new AtomClass([]),
	items: new AtomClass([]),
});

repo.syncer.watchDispatch((player, payload) => {
	// send payload to player somehow
})

repo.syncer.hydrate(player);  // will call watchDispatch with all atoms
repo.syncer.start(0);  // optional interval 

AtomRepositoryView

type Event = {
	name: string,
	until: number,
}

type Item = {
	name: string,
	power: number,
}

type MyAtoms = {
	events: AtomClass<Event[]>,
	items: AtomClass<Item[]>,
}

const repoView = new AtomRepositoryView<MyAtoms>();

// use this method to sync payload from AtomRepository syncer
repoView.syncer.sync(payload);

print("events", repoView.get("events"));
1.4.2

10 months ago

1.3.2

1 year ago

1.3.1

1 year ago

1.3.0

1 year ago

1.2.0

1 year ago

1.1.0

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago