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

@ydant/reactive

v0.2.0

Published

Reactivity system for Ydant

Readme

@ydant/reactive

Signal-based reactivity system for Ydant.

Installation

pnpm add @ydant/reactive

Usage

Basic Signals

import { signal, computed, effect } from "@ydant/reactive";

// Create a signal
const count = signal(0);

// Read value
console.log(count()); // 0

// Update value
count.set(5);
count.update((n) => n + 1);

// Create computed value
const doubled = computed(() => count() * 2);
console.log(doubled()); // 12

// Run effects
const dispose = effect(() => {
  console.log(`Count: ${count()}`);
});

count.set(10); // Logs: "Count: 10"
dispose(); // Stop tracking

With DOM (reactive primitive)

import { mount, type Component } from "@ydant/core";
import { createBasePlugin, div, button, text, on } from "@ydant/base";
import { signal, reactive, createReactivePlugin } from "@ydant/reactive";

const count = signal(0);

const Counter: Component = () =>
  div(function* () {
    // Auto-update on signal change
    yield* reactive(() => [text(`Count: ${count()}`)]);

    yield* button(() => [on("click", () => count.update((n) => n + 1)), text("Increment")]);
  });

mount(Counter, document.getElementById("app")!, {
  plugins: [createBasePlugin(), createReactivePlugin()],
});

API

signal

function signal<T>(initialValue: T): Signal<T>;

interface Signal<T> extends Readable<T> {
  (): T; // Read (tracks dependencies)
  peek(): T; // Read without tracking
  set(value: T): void; // Write
  update(fn: (prev: T) => T): void; // Update with function
}

computed

function computed<T>(fn: () => T): Computed<T>;

interface Computed<T> extends Readable<T> {
  (): T; // Read (automatically tracks dependencies)
  peek(): T; // Read without tracking
}

effect

function effect(fn: () => void | (() => void)): () => void;

Runs fn immediately and re-runs when dependencies change. Returns a dispose function. If fn returns a cleanup function, it will be called before each re-run and on dispose.

reactive

function reactive(fn: () => Render): Reactive;

Creates a reactive block that auto-updates DOM when signals change. Use with yield* in generator syntax.

batch

function batch(fn: () => void): void;

Batches multiple signal updates to trigger effects only once:

const firstName = signal("John");
const lastName = signal("Doe");

effect(() => {
  console.log(`${firstName()} ${lastName()}`);
});
// Logs: "John Doe"

batch(() => {
  firstName.set("Jane");
  lastName.set("Smith");
});
// Logs only once: "Jane Smith"

Without batch, each set() call would trigger the effect immediately. With batch, updates are collected and the effect runs only once at the end with the final values.

createReactivePlugin

function createReactivePlugin(): Plugin;

Creates a plugin that handles reactive blocks. Must be passed to mount(). Depends on createBasePlugin().

Module Structure

  • types.ts - Subscriber, Readable types
  • signal.ts - Signal implementation
  • computed.ts - Computed implementation
  • effect.ts - Effect implementation
  • batch.ts - Batch functionality
  • reactive.ts - reactive primitive
  • plugin.ts - DOM plugin
  • tracking.ts - Subscription tracking (internal)