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

@atsu/taihou

v0.5.3

Published

Small state manager written in Typescript

Readme

A simple state manager written in Typescript

How to Install

Copy, paste and run, like most packages.

npm i @atsu/taihou

Usage

There is only one simple thing to learn for Taihou, the UseStateProps

export type UseStateProps<State, Actions, Getters> = {
    state: State; // Initial state you want to track
    actions: Actions; // Set of functions that will update the state
    getters: Getters; // Set of functions that will get data from the state
    options?: TaihouOptions; // Configuration options
};

Then you are good to go, this is a basic example on how to use it.

import { useState } from "@atsu/taihou";

const taihou = useState({
    state: {
        list: [],
        flag: false,
        nested: {
            listenToMe: false,
        },
    },
    actions: {
        // Define how your actions will modify the state, and return a new state object
        addToList: (state, payload) => ({
            ...state,
            list: [...state.list, ...payload],
        }),
        changeFlag: (state, payload) => ({ ...state, flag: payload }),
        toggleListenToMe: (state, payload) => ({
            ...state,
            nested: {
                ...state.nested,
                listenToMe: payload;
            }
        })
    },
    getters: {
        isListenToMe: (state) => state.nested.listenToMe;
    }
});

const onTaihouUpdate = ({ list, flag }) => {
    console.log("I will receive this updated ", list);
    console.log("I will receive this updated flag as", flag);
};

watchTaihou(onTaihouUpdate); // I want to watch for updates

// Get the actions
const { addToList, changeFlag, toggleListenToMe } = taihouState.actions;

addToList(["I want to add this"]); // This will trigger an update
changeFlag(true); // This will trigger an update again
toggleListenToMe(true); // This too


const { isListenToMe } = taihouState.getters;

console.log(isListenToMe()) // Should get the current state of nested.listenToMe

console.log(taihouState.getState()) // I get the whole state object;

unwatchTaihou(onTaihouUpdate); // I am responisble and clean my listeners

Typescript

After you define your state, it should be possible to have type inference.

taihou.getState(); // Should be of type { list: any[], flag: boolean, nested: { listenToMe: boolean }}

This is nice, and enforces a type safe development, but it can be a bit hard to read if you have a big state.

Plus, we have an any[] in the list type, TS took the initial values to type it.

We can do it better, so we simply define an TaihouState interface to feed the useState generic:

interface TaihouState {
    list: string[];
    flag: boolean;
    nested: {
        listenToMe: boolean;
    };
}

And include it in the useState as useState<TaihouState>.

Or you can always make your code organized, I prefer it this way:

const initialTaihouState: TaihouState = {
    list: [],
    flag: false,
    nested: {
        listenToMe: false;
    };
};
const taihou = useState(initialTaihouState);

And that's it, really simple!

You can organize multiple states as sections of a store, if you want to separate concerns and also to separate the watchers' event handlers.

export const MyAppStore = {
    taihou: useState(initialTaihouState);
    azuma: useState(initialAzumaState);
    atago: useState(initialAtagoState);
}
/* In another file */
const { getState, actions, getters, watch, unwatch } = MyAppStore.azuma;

Configuration

If you wanna see what's going on every update, just enable debug mode in the options:

useState({
    // ... rest of the props
    options: { debug: true },
});

This way Taihou will log any change update into the console.

Common questions and answers

Q: I checked the code, we are DeepCloning with JSON parse/stringify!?

A: Yes, for now. I will change to a faster method whenever i have time.

Q: What happened to the simplicity of 0.4.x?, the [state, watch, unwatch] paradigm?

A: That was awesome, but it had a problem with how JS handles objects by reference, making the Proxy to not trigger updates when dynamically adding properties.

I wanted to make the actions (state mutations) more explicit, although sacrificing a bit of simplicity, we can have more control on every update and be reliable on edits.

Q: This basically describes the Publish-subscribe pattern, why not simply use a message system?

A: I do not want to define messages and map them in an Enum. Taihou 0.2.x used this method of doing things.

Q: Why I would use this instead of Redux or Pinia or any other store management?

A: The main point of Taihou is simplicity, it resolves the problem of needing a State and Event management and only that. This gives you also the benefit of integrating on almost any project (that uses npm).

Author

👤 Tsukugi

🤝 Contributing

Contributions, issues and feature requests are welcome!Feel free to check issues page.

Show your support

Give a ⭐️ if this project helped you!