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

@chris39704/ezstate

v1.0.6

Published

Tiny TS state manager with actions, views, patches & snapshots

Downloads

20

Readme

EZState

Tiny. Typed. Time-travelling. Your minimalist MST-style state manager, zero dependencies, lightning fast.

🚀 Installation

bash npm install ezstate

or

yarn add ezstate

✨ Key Features

  • Actions & computed views via createModel
  • Proxy-tracked getters: just write a view function, EZState auto-tracks dependencies
  • Snapshots & patches: time-travel, undo/redo, or hydrate SSR state
  • Zero runtime deps: ~50 lines of code
  • Universal support: ESM, CJS, Node SSR, browser & Next.js
  • Full TypeScript support: infer your state, actions, and views

🔧 Quickstart

ts import { createModel } from 'ezstate'

  1. Define a model

const counter = createModel({ initialState: { a: 1, b: 2 }, actions: { incA: (s, by = 1) => ({ a: s.a + by }), incB: (s, by = 1) => ({ b: s.b + by }), }, views: { sum: s => s.a + s.b, isEvenA: s => s.a % 2 === 0, } })

// 2) Use it anywhere

console.log(counter.sum) // 3 counter.incA(5) console.log(counter.sum) // 8

// 3) Snapshots & patches

const snapshot = counter.getSnapshot() counter.incB(2) console.log(counter.getPatches()) // [ { op: 'replace', path: '/b', value: 4 } ]

// undo last change

counter.applyPatch([{ op: 'replace', path: '/b', value: snapshot.b }]) console.log(counter.getState()) // { a: 6, b: 2 }

🔄 React / Next.js Integration

ts // use in React components

import { useSyncExternalStore } from 'react' import { counter } from './models/counter'

function useCounter() { return useSyncExternalStore( counter.subscribe, () => counter.getState() ) }

// Hydration in pages/_app.js

import { useEffect } from 'react' import { counter } from '@/models/counter'

let hydrated = false export default function MyApp({ Component, pageProps }) { useEffect(() => { if (!hydrated && pageProps.initialState) { // hydrate by replacing state counter.setState(pageProps.initialState) hydrated = true } }, [pageProps.initialState])

return <Component {...pageProps} /> }

🛠️ API Reference

createModel(def)

  • initialState: S — your starting state object
  • actions: { [K: string]: (state: S, ...args) => Partial } — update functions
  • views?: { [K: string]: (state: S) => any } — computed values

Returns a model with:

  • getState(): S — read current state
  • subscribe(fn: (s: S) => void): () => void — listen for changes
  • (...args): void — invoke your actions
  • : any — read computed views as getters
  • getSnapshot(): S — deep clone state
  • onPatch(fn: (ops: JsonPatch) => void): () => void — listen to patch events
  • getPatches(): JsonPatch — get full patch history
  • applyPatch(ops: JsonPatch): void — apply JSON-Patch ops

❤️ Why EZState?

  • Bundle-friendly: tiny footprint
  • Predictable: explicit, immutable-style state updates
  • Performant: views recalc only on real changes
  • Extensible: hook into patches for undo/redo, logging, persistence

Happy state managing! 🎉