Packages
@azmr/core
Reactive engine — signals, effects, and computed values.
Installation
pnpm add @azmr/coreSignal
A reactive value container. Any effect that reads .get() while active will re-run when the value changes.
import { Signal } from "@azmr/core";
const count = new Signal(0);
count.set(1);
console.log(count.get()); // 1
console.log(count.peek()); // 1 — reads without subscribingeffect
Runs a function immediately and re-runs whenever any Signal read inside it changes. Returns a disposer.
import { Signal, effect } from "@azmr/core";
const name = new Signal("Aroha");
const dispose = effect(() => {
console.log(`Hello, ${name.get()}`);
});
// → Hello, Aroha
name.set("Tane");
// → Hello, Tanecomputed
A read-only Signal whose value is derived from other Signals.
import { Signal, computed } from "@azmr/core";
const price = new Signal(100);
const gst = computed(() => price.get() * 0.15);
console.log(gst.get()); // 15
price.set(200);
console.log(gst.get()); // 30subscribe
Listen to a Signal from outside the reactive system — useful for bridging to React, Vue, or any non-reactive code.
import { Signal } from "@azmr/core";
const price = new Signal(100);
const unsubscribe = price.subscribe((value) => {
console.log(`price changed to ${value}`);
});
price.set(200); // → price changed to 200
unsubscribe(); // stop listeningSafety
The scheduler uses a generation counter to prevent effects from running more than once per flush cycle. An effect that reads and writes the same signal will run at most twice — the re-queue is deduplicated, preventing unbounded loops.
const s = new Signal(0);
// Safe — deduplicated by the scheduler, never runs unboundedly
effect(() => {
s.get();
s.set(s.peek() + 1);
});API Reference
Signal<T>
| Method | Returns | Description |
|---|---|---|
get() | T | Read value and subscribe current effect |
set(value) | void | Update value and notify subscribers |
peek() | T | Read value without subscribing |
subscribe(fn) | () => void | Register a callback, returns unsubscribe function |
Functions
| Function | Description |
|---|---|
effect(fn) | Run fn reactively, returns disposer |
computed(fn) | Create a derived read-only Signal |