fast reactive signals jsr.io/@mary/signals
typescript jsr
TypeScript 100.0%
17 1 0

Clone this repository

https://tangled.org/mary.my.id/pkg-signals https://tangled.org/did:plc:ia76kvnndjutgedggx2ibrem/pkg-signals
git@tangled.org:mary.my.id/pkg-signals git@tangled.org:did:plc:ia76kvnndjutgedggx2ibrem/pkg-signals

For self-hosted knots, clone URLs may differ based on your setup.

Download tar.gz
README.md

signals#

JSR | source code

fast reactive signals.

const name = signal(`Mary`);

// run a side effect that gets rerun on state changes...
effect(() => {
	console.log(`Hello, ${name.value}!`);
});
// logs `Hello, Mary!`

// combine multiple writes into a single update...
batch(() => {
	name.value = `Elly`;
	name.value = `Alice!`;
});
// logs `Hello, Alice!`

// run derivations that only gets updated as needed when not depended on...
const doubled = computed(() => {
	console.log(`Computation ran!`);
	return name.repeat(2);
});

doubled.value;
// logs `Computation ran!`
// -> `AliceAlice`

name.value = `Alina`;
// no logs as it's not being read under an effect yet!

doubled.value;
// logs `Computation ran!`
// -> `AlinaAlina`