Skip to main content

Fast reactive signals

Works with
This package works with Bun
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Browsers
JSR Score
82%
Published
a month ago

signals

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`

Add Package

deno add @mary/signals

Import symbol

import * as mod from "@mary/signals";

Add Package

npx jsr add @mary/signals

Import symbol

import * as mod from "@mary/signals";

Add Package

yarn dlx jsr add @mary/signals

Import symbol

import * as mod from "@mary/signals";

Add Package

pnpm dlx jsr add @mary/signals

Import symbol

import * as mod from "@mary/signals";

Add Package

bunx jsr add @mary/signals

Import symbol

import * as mod from "@mary/signals";