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

@braine/statemanagement

v1.1.0

Published

A high-performance, proxy-based state management library with built-in async handling.

Downloads

174

Readme

@braine/statemanagement

The "God Particle" of State Management.

A unified architecture that merges Store, Actions, and API Logic into single, high-performance "Smart Models".

npm version License: MIT

Why This Exists?

Existing libraries force you to split your brain:

  • Redux/Zustand: Great for Client state, bad for Server state.
  • React Query: Great for Server state, explicitly ignores Client state.

We solved this. With defineModel, you define Smart Models that own both their data (server + client) and their logic (optimistic updates, fetching).

Installation

npm install @braine/statemanagement
# or
yarn add @braine/statemanagement

The "Smart Model" Pattern

This is all you need to know. One function: defineModel.

1. Define It

import { defineModel } from '@braine/statemanagement';

export const Todos = defineModel({
  // 1. Unified State (Server + Client mixed!)
  state: {
    items: [] as string[],
    filter: 'all',
    isLoading: false
  },

  // 2. Computed Properties (Auto-Memoized)
  computed: {
    activeCount() {
      return this.items.length;
    },
    isEmpty() {
      return this.items.length === 0;
    }
  },

  // 3. Actions (Sync + Async + Optimistic)
  // 'this' is automatically bound to the reactive proxy.
  actions: {
    setFilter(filter: string) {
      this.filter = filter;
    },

    async add(text: string) {
      // A. Optimistic Update (Instant UI)
      this.items.push(text);
      
      try {
        // B. Network Call
        await fetch('/api/todos', { method: 'POST', body: text });
      } catch (err) {
        // C. Auto-Rollback (Manual for now, easy to do)
        this.items.pop();
        alert('Failed to save!');
      }
    }
  }
});

2. Use It

No selectors. No context. No providers. Just use it.

import { useStore } from '@braine/statemanagement';
import { Todos } from './models/Todos';

function TodoApp() {
  const model = useStore(Todos); // Auto-subscribes to properties you access

  if (model.isEmpty) return <div>No tasks!</div>;

  return (
    <div>
      <h1>Active: {model.activeCount}</h1>
      <button onClick={() => model.add("New Task")}>
        Add Task
      </button>
    </div>
  );
}

Comparison

| Feature | Redux Toolkit | TanStack Query | @braine/statemanagement | | :--- | :--- | :--- | :--- | | Philosophy | Reducers + Thunks | Server Cache Only | Unified Smart Models | | Boilerplate | High (Slices, Types) | Medium (Keys, Fetchers) | Zero | | Client State | Yes | No (Need Zustand) | Yes (Integrated) | | Optimistic UI| Complex (onQueryStarted) | Complex (onMutate) | Simple (this.push) | | Performance | Good | Excellent | Excellent (Proxy) |

Advanced Features

Direct Promise Binding

If you don't want a full model, you can still use the raw proxy power:

import { createState } from '@braine/statemanagement';

// Assign a promise, and the UI suspends automatically!
const store = createState({
  data: fetch('/api/data').then(r => r.json())
});

DevTools

Full Redux DevTools support is built-in.

import { enableDevTools } from '@braine/statemanagement';
enableDevTools(Todos, 'TodoModel');

License

MIT