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 🙏

© 2025 – Pkg Stats / Ryan Hefner

solid-state-tools

v1.3.1

Published

A collection of Solid JS state utilities

Readme

Solid State Tools

Links: GitHub Repository, NPM Package.

Solid State Tools is a collection of simple utilities for managing Solid JS state.

All features are intended to compliment Solid JS's existing state system, building upon the existing foundation.

The package is small and only has a peer dependency of Solid JS.

Usage

This library introduces some new primitives:

  1. atom
  2. createCouple

And, a few shorthand functions that combine these primitives and those from Solid JS together.

  1. asig
  2. apair

Read the sections below for a breakdown of each utility.

Atoms (atom)

Atoms combine the getter and setter of a signal into one function.

const count: Atom<Signal<number>> = atom(createSignal(0));

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

count(100);
console.log(count()); // 100

count(count() + 1);
console.log(count()); // 101

count((c) => c + 1);
console.log(count()); // 102

When called with no arguments, the atom acts like the signal's getter. If an argument is passed, it is forwarded to the signal's setter. Note that undefined is considered an argument and is forwarded to the setter.

Atoms simplify the boilerplate that comes with managing separate getters and setters. However, signals are still preferred when granular control of the getter and setter is needed. Additionally, atoms incur a tiny performance cost. Thus, atoms do not replace signals. They coexist.

Atomic signals (asig)

Creating a signal and immediately 'atomizing' it is a common pattern. The asig function was created for this, along with its related type Asig.

const count: Asig<number> = asig(0);
// is short for
const count: Atom<Signal<number>> = atom(createSignal(0));

The second parameter (optional) is the config object, which is simply forwarded to the createSignal call.

const list = asig([], { equals: false });
// is short for
const list = atom(createSignal([], { equals: false }));

Couples (createCouple)

A signal can be summarized as a getter setter pair. However, the setter of a Solid JS signal is more complex than it appears at first glance. Why?

  1. It accepts a function which transforms the previous value into the new one.

    setCount(x => x + 1);
  2. It also returns the value.

    const [ _count, setCount ] = createSignal(0);
    
    console.log(setCount(10));         // Prints: 10
    console.log(setCount(x => x + 5)); // Prints: 15

All of this is to say that creating custom signal pairs can be tedious. Below is an example showing the complexity involved.

const [ count, setCount ] = createSignal(0);

const [ double, setDouble ] = [
	// The getter
	createMemo(() => count() * 2),
	
	// The setter
	(newValue: number | ((prev: number) => number)) => {
		
		// The function case must be handled.
		const unwrappedNewValue = (typeof newValue === "function") ? newValue(untrack(double)) : newValue;
		
		setCount(unwrappedNewValue / 2);
		
		// And the result must be returned.
		return unwrappedNewValue;
	},
];

With that, the following statements work (as is expected of a setter):

setDouble(10);              // double: 10, count: 5
setDouble(x => x + 1);      // double: 11, count: 5.5
console.log(setDouble(20)); // Prints: 20

But, the crusty boilerplate to get it working is annoying as heck.

Enter the createCouple utility.

It accepts a getter and a co-setter and returns a signal. A co-setter is similar to a setter, except that it doesn't take a function nor does it return a value. Basically, it's the previous example without the boilerplate. See it in action:

const [ count, setCount ] = createSignal(0);

const [ double, setDouble ] = createCouple(
	() => count() * 2,
	
	(newValue) => {
		// Notice how we don't need to handle `newValue` being a function here.
		setCount(newValue / 2);
		
		// Nor do we need to return anything.
	},
);

// Yet, we can still pass a function in.
setDouble(x => x + 2);
console.log(double(), count()); // 2 1

// Or use its return value.
console.log(setDouble(10), count()); // 10 5

Much better, right?

[!NOTE] The getter passed to createCouple is always memoized. This immediately invokes the getter, so keep that in mind.

By the way! A createCouple call, like any expression that evaluates to a signal, can be converted into an atom so that the getter and setter are merged into one.

const double = atom(createCouple(/* ... */));

Atomic couples (apair)

Similar to atomic signals, wrapping a createCouple call with atom is a common enough pattern to warrant a shorthand: apair.

const double = apair(() => count() * 2, (double) => count(double / 2));
// is short for
const double = atom(createCouple(() => count() * 2, (double) => count(double / 2)));

Conclusion

Perhaps you can see the power of the above primitives. Not only in what they do, but also in how they combine.

More utilities for this library are in the works and will be coming soon.