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

immer-patch-history-engine

v0.1.1

Published

Framework-agnostic, Immer patch-based undo and redo history.

Readme

immer-patch-history-engine

A framework-agnostic undo/redo manager that records compact Immer patches instead of whole-state snapshots. It works with any object state and has no UI or application-domain dependencies.

Install

npm install immer-patch-history-engine immer

immer is a peer dependency so your application owns its version.

Basic usage

import { HistoryManager } from 'immer-patch-history-engine';

type State = { count: number };
const history = new HistoryManager<State>();
let state = { count: 0 };

state = history.apply(state, draft => { draft.count += 1; }, { label: 'Increment' });
state = history.undo(state); // { count: 0 }
state = history.redo(state); // { count: 1 }

Batching a gesture

Use explicit batching for multiple updates that should undo as one action. Inverse patches are prepended while accumulating, so replaying them reverses same-path changes correctly.

history.startBatch();
state = history.apply(state, draft => { draft.position.x = 10; });
state = history.apply(state, draft => { draft.position.x = 20; });
history.endBatch();
state = history.undo(state); // returns to the value before the batch

Merge recent changes

For typing-style interactions, merge adjacent non-batched actions made within a time window.

const history = new HistoryManager<{ text: string }>({ mergeWindowMs: 500 });
state = history.apply(state, draft => { draft.text += 'a'; });
state = history.apply(state, draft => { draft.text += 'b'; });
// One undo removes both changes when they occur within 500 ms.

API

| Method | Signature | Description | | --- | --- | --- | | apply | (state, recipe, options?) => T | Produces next state and records patches unless the recipe is a no-op. | | undo | (state) => T | Applies the newest inverse patch entry. | | redo | (state) => T | Reapplies the newest redo entry. | | canUndo | () => boolean | Whether an undo entry exists. | | canRedo | () => boolean | Whether a redo entry exists. | | startBatch | () => void | Begins one grouped history entry. | | endBatch | () => void | Commits the current grouped entry, if it changed state. | | getUndoLabel | () => string \| undefined | Label of the next action to undo. | | getRedoLabel | () => string \| undefined | Label of the next action to redo. | | subscribe | (listener) => unsubscribe | Watches history changes. | | clear | () => void | Removes undo and redo entries. |

Constructor options

| Option | Default | Description | | --- | --- | --- | | maxHistorySize | 100 | Maximum completed undo entries; oldest entries are evicted first. | | mergeWindowMs | none | Milliseconds within which consecutive non-batched actions are grouped. |

Notes

History entries are plain JSON-serializable patches, though persistence is intentionally not included. Future work may add framework adapters for React, Vue, and Svelte.

Development

npm run build
npm run test