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

@wasdadeel/state

v1.0.28

Published

Minimal external-state primitives with typed events

Readme

@wasdadeel/state

Minimal external-state primitives with typed events:

  • createState<T> — state container with getState, setState, and typed events.
  • createBoolean() — boolean helper on top of createState.
  • createCounter() — counter with increment/decrement/reset events.

Install

npm i @wasdadeel/state
# or
yarn add @wasdadeel/state

Quick Start

createState()

import { createState } from '@wasdadeel/state';

const $user = createState({ id: '1', name: 'Andrei' });

$user.on('change', ({ prevState, newState }) => {
  console.log(prevState, '→', newState);
});

$user.setState({ id: '2', name: 'Andrew' });
console.log($user.getState()); // { id: '2', name: 'Andrew' }

createBoolean()

import { createBoolean } from '@wasdadeel/state';

const $flag = createBoolean(false);

$flag.on('setTrue', ({ prevState, newState }) => {});
$flag.on('setFalse', ({ prevState, newState }) => {});
$flag.on('change', ({ prevState, newState }) => {});

$flag.setTrue();
$flag.setFalse();
$flag.toggle();

// read synchronously
const v = $flag.getState();

createCounter()

import { createCounter } from '@wasdadeel/state';

const counter = createCounter(0);

counter.on('increment', ({ prevState, newState }) => {});
counter.on('decrement', ({ prevState, newState }) => {}); // note: event name matches code
counter.on('reset', ({ prevState, newState }) => {});

counter.increment(); // 1
counter.decrement(); // 0
counter.getState();
counter.reset();     // back to initial

API Reference

createState<T>(initial: T | (() => T)) => CreatedState<T>

Returns:

  • getState(): T — current value, always fresh
  • setState(next: T | (prev: T) => T, options?: { shouldEmit?: boolean | (event: 'setState' | 'change') => boolean }): void
  • on(event, listener): () => void — subscribe to 'setState' | 'change'

Event payload shapes:

type SetStateEvent<T> = { newState: T };
type ChangeEvent<T> = { prevState: T; newState: T };

createBoolean(initial: boolean | (() => boolean)) => CreatedBoolean

  • getState(), setState(next), setTrue(), setFalse(), toggle()
  • on('setTrue' | 'setFalse' | 'change', listener)

createCounter(initial?: number) => CreatedCounter

  • getState(), increment(), decrement(), reset()
  • on('increment' | 'decrement' | 'change' | 'reset', listener)
  • once(...) also available

Why this library?

  • External state first — read without waiting for React render

  • Typed events — predictable side-effects

  • Zero deps — easy to audit

  • Small surface — primitives only

Types & Utilities

import type { CreatedState, CreatedStateReader, CreatedStateInfer } from '@wasdadeel/state';

// Example:
const $user = createState({ id: '1', name: 'A' });
type User = CreatedStateInfer<typeof $user>; // { id: string; name: string }

Notes

  • shouldEmit lets you suppress setState/change notifications, or only allow specific ones.

License

MIT © Andrei Balashov