Learn
Core Concepts
The four primitives — signal, computed, effect, and batch — that everything else in Pulse is built from.
Signals
A signal is a container for a value that notifies its readers when the value changes. Calling it as a function reads the value; calling .set() writes it.
import { signal } from "pulse";
const name = signal("Ada");
name(); // "Ada"
name.set("Grace"); // updates, notifies readersReading a signal inside a component or an effect automatically subscribes to it. There is no dependency array to maintain — Pulse records exactly which signals were read during that run.
Computed values
computed() derives a value from other signals and caches it until one of its dependencies changes.
import { signal, computed } from "pulse";
const price = signal(20);
const qty = signal(3);
const total = computed(() => price() * qty());
total(); // 60 — recalculated only when price or qty changeEffects
An effect re-runs whenever any signal it reads changes. Use it for anything that reaches outside the reactive graph — logging, network requests, or syncing with the DOM directly.
import { effect, signal } from "pulse";
const theme = signal("light");
effect(() => {
document.body.dataset.theme = theme();
});Effects don't return values
If you need a derived value rather than a side effect, use computed() instead — it’s cached, and reading it doesn’t trigger extra work.
Batching updates
Setting several signals in a row triggers one notification per signal by default. Wrap related updates in batch() to coalesce them into a single update:
import { batch } from "pulse";
batch(() => {
firstName.set("Grace");
lastName.set("Hopper");
});
// dependents re-run once, not twiceMental model comparison
If you’re coming from another framework, this table maps the core ideas:
| Pulse | React | Vue |
|---|---|---|
| signal() | useState() | ref() |
| computed() | useMemo() | computed() |
| effect() | useEffect() | watchEffect() |
| batch() | automatic batching | nextTick() |
How updates propagate
When a signal changes, Pulse walks its dependency graph and re-runs only the computed values and effects that read it — components themselves never re-render. A component function runs exactly once, on mount; everything after that is targeted DOM patching.