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

lucidstate

v1.0.1

Published

Signals based reactive state management for vanilla javascript

Downloads

4

Readme

LucidState

💧 Simple and lightweight signals based reactive state management library for building applications with vanilla javascript and DOM APIs.

Installation

npm i lucidstate

Usage

import { computed, effect, state } from "lucidstate";

const count = state(0);
const countString = computed(() => `${count.get()}`);

count.subscribe(() => {
  console.log("count changed:", count.get());
});

effect(() => {
  console.log(
    "count and count string changed:",
    count.get(),
    countString.get()
  );
});

State

state creates a reactive value that can be retrived, updated and subscribed to.

import { state } from "lucidstate";

const count = state(0);

count.subscribe(() => console.log("count changed"));

count.get(); // 0
count.set(1);
count.get(); // 1

Subscribing to changes

Subscribers are called after a reactive value is changed. Multiple calls to set state are batched and only after the final value changed will the subscribers be called.

Subscribers may return a cleanup function that will be called before rerunning.

Subscribers may also receive a signal to unsubscribe when the signal aborts.

import { state } from "lucidstate";

const count = state(0);
const controller = new AbortController();

count.subscribe(
  () => {
    console.log("count changed");
    return () => console.log("running cleanup");
  },
  { signal: controller.signal }
);

// subscribers will not be called as the value did not change
const update1 = () => {
  count.set(0);
};

// subscribers will not be called as the final value is still 0
const update2 = () => {
  count.set(1);
  count.set(2);
  count.set(0);
};

// subscribers are called once after the last update
const update3 = () => {
  count.set(1);
  count.set(2);
  count.set(3);
};

Computed

computed creates a reactive value that can be retrieved and subscribed to.

computed automatically subscribes to reactive values that are used inside it and updates when any of it's dependencies updates.

import { computed, state } from "lucidstate";

const count = state(0);
const countString = computed(() => `${count.get()}`);

countString.subscribe(() => console.log("count string changed"));

countString.get(); // "0"

Effect

effect automatically subscribes to reactive values that are used inside it and reruns when any of it's dependencies updates. Effects are ran immediately and when dependencies update.

Effects may return a cleanup function that will be called before rerunning.

Effects may also receive a signal to unsubscribe when the signal aborts.

import { effect, state } from "lucidstate";

const count = state(0);
const count2 = state(100);
const controller = new AbortController();

effect(
  () => {
    console.log("changed", count.get(), count2.get());
    return () => console.log("running cleanup");
  },
  { signal: controller.signal }
);

Context

context creates a block that can be loaded and unloaded. A context accepts a signal that is aborted when the context is unloaded.

A context may return a cleanup function that will be called before rerunning.

import { context } from "lucidstate";

const registerEvents = context((signal) => {
  console.log("registering events");
  window.addEventListener(
    "resize",
    () => {
      console.log("window resized");
    },
    { signal }
  );
  return () => console.log("running cleanup");
});

registerEvents.unload(); // runs cleanup and aborts signal

Explicit context loading

Context function runs immediately, if you prefer to run it manually then make the context lazy.

Calling load on a context unloads the context (if already loaded) before rerunning.

import { context } from "lucidstate";

const registerEvents = context(
  (signal) => {
    console.log("registering events");
    window.addEventListener(
      "resize",
      () => {
        console.log("window resized");
      },
      { signal }
    );
    return () => console.log("running cleanup");
  },
  { lazy: true }
);

registerEvents.load(); // manually load
registerEvents.load(); // runs cleanup and aborts signal and reruns
registerEvents.unload(); // runs cleanup and aborts signal

Ref

ref is an alias for document.querySelector()

const btn = ref<HTMLButtonElement>("#btn");