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

immertation

v0.1.26

Published

<p align="center"> <img src="media/logo.png" alt="Immertation" width="33%" /> </p>

Downloads

622

Readme

State management library that tracks changes to your data using Immer patches and provides a powerful annotation system for operation tracking.

Operations are particularly useful for async operations and optimistic updates, where the model is being operated on but not yet committed to the final value. This allows you to track pending changes and distinguish between the current committed state and the draft state with pending operations.

Contents

Getting started

import { State, Op } from 'immertation';

type Model = {
  name: string;
  age: number;
};

const state = new State<Model>();
state.hydrate({ name: 'Imogen', age: 30 });

state.produce((draft) => {
  draft.name = 'Phoebe';
  draft.age = 31;
});

console.log(state.model.name); // 'Phoebe'
console.log(state.model.age); // 31

console.log(state.inspect.name.pending()); // false
console.log(state.inspect.age.pending()); // false

Using annotations

Annotations allow you to track pending changes. This is especially useful for optimistic updates in async operations, where you want to immediately reflect changes in the UI while the operation is still in progress:

import { State, Op } from 'immertation';

// Annotate a value to mark it as pending
state.produce((draft) => void (draft.name = state.annotate(Op.Update, 'Phoebe')));

// The model retains the original value
console.log(state.model.name); // 'Imogen'

// But we can check if it has a pending operation
console.log(state.inspect.name.pending()); // true

// Later, commit the actual change
state.produce((draft) => void (draft.name = 'Phoebe'));

console.log(state.model.name); // 'Phoebe'
console.log(state.inspect.name.pending()); // false

Available operations

The Op enum provides operation types for annotations:

  • Op.Add - Mark a value as being added
  • Op.Remove - Mark a value as being removed
  • Op.Update - Mark a value as being updated
  • Op.Replace - Mark a value as being replaced
  • Op.Move - Mark a value as being moved
  • Op.Sort - Mark a value as being sorted
// Adding a new item
state.produce((draft) => void draft.locations.push(state.annotate(Op.Add, { id: State.pk(), name: 'Horsham' })));

// Marking for removal (keeps item until actually removed)
state.produce((draft) => {
  const index = draft.locations.findIndex((loc) => loc.id === id);
  draft.locations[index] = state.annotate(Op.Remove, draft.locations[index]);
});

// Updating a property
state.produce((draft) => void (draft.user.name = state.annotate(Op.Update, 'Phoebe')));

Inspecting state

The inspect property provides a proxy to check pending operations at any path:

// Check if a value has any pending operation
state.inspect.name.pending(); // boolean

// Check for a specific operation type
state.inspect.users[0].is(Op.Add); // true if being created
state.inspect.users[0].is(Op.Remove); // true if being deleted

// Get the draft value (annotated value or actual model value)
state.inspect.name.draft(); // returns annotated value if pending, otherwise model value

// Wait for a value to have no pending annotations
const value = await state.inspect.name.settled(); // resolves when annotations are pruned

// Works with nested paths
state.inspect.user.profile.email.pending();

// Works with array indices
state.inspect.locations[0].name.pending();

Pruning annotations

Remove annotations by process after async operations complete:

const process = state.produce((draft) => void (draft.name = state.annotate(Op.Update, 'Phoebe')));

// After async operation completes
state.prune(process);

Observing changes

Subscribe to model changes to react whenever mutations occur:

const unsubscribe = state.observe((model) => {
  console.log('Model changed:', model);
});

// Later, stop listening
unsubscribe();

Identity function

By default, Immertation tracks object identity using an internal κ property — you typically don't need to configure this. However, if you need custom identity tracking (e.g., using your own id fields), you can optionally pass a custom identity function to the State constructor:

const state = new State<Model>((snapshot) => {
  if ('id' in snapshot) return snapshot.id;
  if (Array.isArray(snapshot)) return snapshot.map((item) => item.id).join(',');
  return JSON.stringify(snapshot);
});