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 🙏

© 2024 – Pkg Stats / Ryan Hefner

immutable-undo

v2.0.0

Published

Data structure for and Undo/Redo stack, using ImmutableJS

Downloads

440

Readme

Immutable Undo

Simple data structure for and undo/redo stack, using ImmutableJS. The structure holds a stack of undo states, and a stack of redo states. It does not keep a reference to the current state to avoid duplicating data if your state is already stored in another structure.

Installation

npm install --save immutable-undo

Reference

Static

History.create

  • {Object} [opts] Option object
  • {Number} [opts.maxUndos=500] Maximum number of undos stored. Beyond that, some undos are dropped, according to the specified drop strategy.
  • { (History) => History } [opts.strategy=History.lru] The drop strategy. See strategies.
  • return {History} An empty history
var history = History.create({
    maxUndos: 100
});

Properties

canUndo

  • return {Boolean} True if the history has undos

canRedo

  • return {Boolean} True if the history has redos

previous

  • return {State | Undefined} The most recent state in the undo stack

next

  • return {State | Undefined} The most recent state in the redo stack

Methods

push

  • {State} newState The state to push on top of the undo stack
  • return {History}

Pushes a new state on the undo stack, and clears the redo stack

undo

  • {State} current The current state, that will be pushed on the redo stack
  • return {History} The history with the undo stack popped once, and the current state added to redos.

redo

  • {State} current The current state, that will be pushed on the undo stack
  • return {History} The history with the redo stack popped once, and the current state added to redos

Strategies

These are built-in strategies for keeping the undo stack under its size limit.

History.lru

Least Recently Used. Simply drops the oldest undo to make room for new one.

History.smooth

Will always keep the initial state (the first undo), and will drop undos such as the oldest undos grow more and more spaced in time, but the more recent undos keep a high precision.

You can imagine the density of undos over time becoming more like this curve:

curve