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

@zakkster/lite-undo

v1.0.0

Published

Transactional undo/redo on @zakkster/lite-project: a commit is an undoable transaction, undo/redo are reactive source writes, and preview() shows any historical state as overlays without committing -- time-travel preview for free. Bounded zero-GC history

Readme

@zakkster/lite-undo

npm version Zero-GC sponsor npm bundle size npm downloads npm total downloads lite-signal peer TypeScript Dependencies License: MIT

Transactional undo/redo on @zakkster/lite-project.

A commit is an undoable transaction. You edit through a lite-project projection (ephemeral overlays over a keyed source), then commit() through this controller: it captures each touched key's before (source) and after (overlay) value, commits the projection, and pushes the transaction onto a bounded history. undo() writes the before values back into the source; redo() re-writes the after values. The source is reactive, so every view re-derives -- undo and redo are ordinary writes, not a rebuild.

And because the editing surface is overlays, previewing a historical state is free: apply it as overlays without committing, and the view shows where you'd land while the source and the real cursor stay put.

npm install @zakkster/lite-undo

Peer dependencies: @zakkster/lite-project ^1.0.0 (the editing surface) and @zakkster/lite-signal ^1.5.0 (the cursor signals). ESM only. MIT.


Commit, undo, redo

import { keyedStore, project } from "@zakkster/lite-project";
import { createHistory } from "@zakkster/lite-undo";

const store = keyedStore({ title: "untitled", count: 0 });
const doc = project(store);                       // the editing surface (overlays)
const history = createHistory(doc, store, { capacity: 200 });

doc.set("title", "Draft");                        // stage an overlay (source untouched)
history.commit("rename");                         // capture before/after, commit, record

doc.set("count", 5);
history.commit("set count");

history.undo();    // count -> 0   (writes the before value back to the source)
history.undo();    // title -> "untitled"
history.redo();    // title -> "Draft"

commit(label?) returns false if nothing was staged. transaction(fn, label?) runs fn (which stages overlays) and commits it as one transaction:

history.transaction(() => {
    doc.set("title", "Final");
    doc.set("count", 42);
}, "publish");                                     // one undoable step, two keys

Undo/redo write to the source, so any view derived from it updates reactively. The enable/disable state of your buttons is reactive too:

effect(() => { undoBtn.disabled = !history.canUndo(); });
effect(() => { redoBtn.disabled = !history.canRedo(); });

How a transaction is captured

flowchart LR
    E["doc.set(k, v)<br/>(overlays)"] --> C["history.commit()"]
    C --> B["read source.get(k)<br/>= BEFORE"]
    C --> A["overlay value<br/>= AFTER"]
    B --> R["transaction<br/>{ keys, before, after }"]
    A --> R
    R --> W["projection.commit()<br/>source := AFTER, clear overlays"]
    R --> H["push onto history ring"]
    H -->|undo| B2["source := BEFORE"]
    H -->|redo| A2["source := AFTER"]

The before values are read from the source the instant before the projection commits -- that inverse is what undo() replays.


Time-travel preview

preview(position) shows the source state at any history position without committing to it -- it applies that state as projection overlays (masking the source), so views show it while the source and cursor stay exactly where they are. cancelPreview() clears precisely those overlays.

// history has N transactions; cursor is at the latest
history.preview(0);          // the view now shows the original state...
history.preview(3);          // ...now the state after 3 commits...
history.cancelPreview();     // ...and back to live. The source never moved.

Wire it to a history panel and you get hover-to-preview:

const entries = history.labels();   // reactive: [{ index, label }, ...] oldest-first
// on hover of entry i:  history.preview(i + 1)
// on mouse-out:         history.cancelPreview()
// on click:             while (history.position() > i + 1) history.undo();

Preview reconstructs an arbitrary state -- multi-key, many steps back or forward -- by replaying the right side (before / after) of the transactions between the cursor and the target, closest-to-target winning per key.


History storage

stateDiagram-v2
    [*] --> Applied: commit (cursor++)
    Applied --> Applied: commit -> truncate redo branch, append
    Applied --> Undone: undo (cursor--)
    Undone --> Applied: redo (cursor++)
    Undone --> Applied: commit -> redo branch discarded
    Applied --> Dropped: ring full -> oldest evicted

A fixed-capacity ring with an undo/redo cursor. A new commit truncates the redo branch, appends, and drops the oldest entry when full. Transaction slots and their keys/before/after arrays are pre-allocated and reused -- a steady cycle of commit/undo/redo allocates nothing on the engine pool after warm-up (5,000 cycles flat, verified). It is inlined rather than backed by lite-history-buffer because undo/redo needs cursor and redo-branch semantics a plain ring does not provide.


Boundaries (the honest non-claims)

  • Undo/redo operate on committed source state. Uncommitted overlays you are still editing are separate and remain.
  • Commit through this controller to make a change undoable. A direct projection.commit() bypasses the history.
  • Preview uses overlays, so the projection reads dirty during a preview and it assumes no conflicting pending overlays -- it is for viewing committed history. cancelPreview() clears exactly the keys it set.
  • History slots retain value references up to their per-slot high-water key count (bounded by capacity) -- expected for a history buffer.

API

createHistory(projection, source, opts?: { capacity?: number }): History
createUndo(registry): { createHistory }     // bind cursor signals to a non-default registry

interface History {
  commit(label?): boolean
  transaction(fn: () => void, label?): boolean
  undo(): boolean
  redo(): boolean
  canUndo(): boolean        // reactive
  canRedo(): boolean        // reactive
  position(): number        // reactive
  size(): number            // reactive
  labels(): { index: number; label: unknown }[]   // reactive
  preview(position: number): void
  cancelPreview(): void
  clear(): void
  dispose(): void
}

projection is a lite-project projection; source is the same { get, set } it wraps.


License

MIT (c) 2026 Zahary Shinikchiev <[email protected]>