npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@just-dom/signals

v1.1.0

Published

Fine-grained reactive signals for just-dom

Downloads

131

Readme

@just-dom/signals

Fine-grained reactive signals for Just DOM.

A single source of truth that keeps data and UI in sync automatically — no manual subscription lists, no full re-renders.

Install

npm install @just-dom/signals

No peer dependencies.

Usage

import DOM, { createRoot } from "just-dom";
import { createSignal, computed, reactive, effect, when, each } from "@just-dom/signals";

const [count, setCount] = createSignal(0);
const double = computed(() => count() * 2);

const app = DOM.div({}, [
  DOM.button({ onclick: () => setCount((c) => c - 1) }, ["-"]),
  DOM.span({}, [reactive(count)]),
  DOM.button({ onclick: () => setCount((c) => c + 1) }, ["+"]),
  DOM.p({}, ["doubled: ", reactive(double)]),
]);

createRoot("app", app);

API

createSignal<T>(initial)

Returns [get, set]. Reading get() inside an effect or computed subscribes automatically. Writing the same value (Object.is) is a no-op.

const [name, setName] = createSignal("world");
setName("just-dom");           // direct value
setName((prev) => prev + "!"); // updater function

effect(fn) / effect(el, fn)

Runs fn immediately and re-runs it whenever any signal read inside changes.

// Manual dispose — call stop() when you remove the element
const stop = effect(() => {
  btn.className = active() ? "on" : "off";
});
stop();

Pass an element as first argument and the effect self-disposes automatically when that element leaves the live document:

DOM.button({
  ref: (el) => {
    effect(el, () => {
      el.className = active() ? "on" : "off";
      el.disabled  = !active();
    });
  },
  onclick: () => setActive((a) => !a),
}, ["Toggle"]);

fn may return a cleanup callback called before each re-run:

effect(() => {
  const id = setInterval(() => tick(), 1000);
  return () => clearInterval(id);
});

computed<T>(fn)

A read-only signal derived from other signals. Updates eagerly when dependencies change.

const total = computed(() => price() * qty());
const vat   = computed(() => total() * 0.22);

reactive(signal)

Creates a Text DOM node that stays in sync with signal(). Pass it as a Just DOM child — no wiring needed. Self-cleans when the node is removed from the live document.

DOM.p({}, ["Count: ", reactive(count)]);
DOM.h1({}, [reactive(() => `Hello, ${name()}`)]);

when(condition, render)

Creates an anchored DOM region that renders a branch while condition() is truthy. Static siblings around the region are left untouched.

const [show, setShow] = createSignal(false);

DOM.section({}, [
  DOM.h2({}, ["Static title"]),
  when(show, () => DOM.p({}, ["Visible"])),
  DOM.button({ onclick: () => setShow((v) => !v) }, ["Toggle"]),
]);

Use object branches for an else case:

when(show, {
  then: () => DOM.p({}, ["Visible"]),
  else: () => DOM.p({}, ["Hidden"]),
});

Pass { cache: true } to keep branch nodes and move them back later instead of recreating them.

The anchored region self-cleans after it is removed from the live document.

each(items, key, renderItem)

Renders a keyed list. Existing nodes are moved when the array order changes, so event listeners, refs, input state, and child DOM identity are preserved.

renderItem receives an item signal and an index signal. Use item() inside nested reactive() or effect() calls when item data should update without recreating the node:

const [todos, setTodos] = createSignal([
  { id: "a", label: "Write docs" },
  { id: "b", label: "Ship package" },
]);

DOM.ul({}, [
  each(
    todos,
    (todo) => todo.id,
    (todo, index) => DOM.li({}, [
      reactive(() => `${index() + 1}. ${todo().label}`),
    ]),
  ),
]);

The anchored list region self-cleans after it is removed from the live document.

Limits

  • No deep reactivity — mutating object properties does not trigger updates; replace the reference.
  • No batching — two setters in sequence run effects twice (V1).
  • effect(fn) dispose is manual — the bare form without el returns a dispose function you must call. Use effect(el, fn) inside a callback ref for automatic cleanup.
  • computed is eager — recalculates on dependency change even if nothing reads the result.
  • each requires stable unique keys — duplicate keys throw, and key changes are treated as remove + add.

Documentation

Full docs at just-dom.vercel.app/docs/official-plugins/signals.