@magnet-js/signal
v0.2.1
Published
Signal primitives: TC39 polyfill, Preact Signals, and alien-signals adapters.
Downloads
567
Readme
@magnet/signal
Signal primitives for Magnet, with three interchangeable adapters exposing the
same API: state, computed, effect, isSignal, and flush.
tc39— built on thesignal-polyfillTC39 proposal polyfill. Effects are scheduled on a microtask and drained withflush().preact— built on@preact/signals-core. Leaner per-signal memory and synchronous effects, soflush()is a no-op.alien— built onalien-signals. The lightest implementation, with synchronous effects, soflush()is a no-op.
Install
JSR
deno add jsr:@magnet/signalnpm via JSR
npx jsr add @magnet/signalnpm
npm install @magnet-js/signalAPI
All primitives are exposed under the tc39, preact, and alien namespaces:
import { preact } from "@magnet/signal";
const { computed, effect, isSignal, state } = preact;
const count = state(0);
const doubled = computed(() => count.get() * 2);
effect(() => {
console.log("count:", count.get());
});
count.set(1); // logs "count: 1"state(initialValue)
Creates a writable signal.
computed(computer)
Creates a read-only signal derived from other signals.
effect(callback)
Runs a side effect whenever its signal dependencies change. The callback may
return a cleanup function. In the tc39 adapter the implementation is pretty
much copy-pasted from
Rob Eisenberg's
eloquent write-up of the TC39 signals proposal; the clarity of that post made
this straightforward.
isSignal(value)
Returns true for signal values created by the adapter in use.
License
MIT © 2026 Fernando G. Vilar.
