Bkash Payment Gateway

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.

ts
import { signal } from "pulse";

const name = signal("Ada");
name();          // "Ada"
name.set("Grace"); // updates, notifies readers

Reading 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.

ts
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 change

Effects

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.

ts
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:

ts
import { batch } from "pulse";

batch(() => {
  firstName.set("Grace");
  lastName.set("Hopper");
});
// dependents re-run once, not twice

Mental model comparison

If you’re coming from another framework, this table maps the core ideas:

PulseReactVue
signal()useState()ref()
computed()useMemo()computed()
effect()useEffect()watchEffect()
batch()automatic batchingnextTick()

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.