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

simple-data-store-history

v3.3.0

Published

An implementation of history support for Simple Data Store.

Readme

Simple Data Store History

NPMBadge for Gzip size

An extention to SimpleDataStore to add history support.

The history store is able to hook into the stores subscription and keeps track of all the changes to the state and then can replay a state when needed to.

Install

To get from npm simply run.

npm install --save simple-data-store-history

Simple Data Store is a peer dependency and won't work without it.

Example

import DataStore from "simple-data-store";
import HistoryStore from "../src";

interface SimpleState
{
    readonly counter: number;
}

function change(value: number)
{
    return (state: SimpleState) => ({ counter: state.counter + value });
}

const store = new DataStore<SimpleState>
({
    counter: 0
});

// History store is kind of like an extension.
// Really it's just an application of the subscribeAny and execute methods.
const historyStore = new HistoryStore<SimpleState>(store, 100);

store.subscribeAny((state) => console.log(state));

store.execute(change(1));
store.execute(change(2));
store.execute(change(-1));

historyStore.back();

/* Example output:
{ counter: 1 }
{ counter: 3 }
{ counter: 2 }
{ counter: 3 }
*/

API

HistoryStore

The history store is a helper store for keeping track of all changes to the store and allows for going back and forth through that history.

The history store itself is just an application of using a subscription and executing a modifier and doesn't rely on any internal API.

Constructor

store: DataStore<TState> The parent store to listen for the history of.

limiter: number = 100 The limiting number for how many items to keep. A value of zero will keep all items.

Creates a new history store. The first thing the history store will do is populate the first history with the current state of the store.

getIndex

returns: number The current index in to the history items list.

Returns the current index in to the history items list.

getItems

returns: Readonly<HistoryItem<TState>[]> The list of history items.

Returns the current list of history items.

subscribe

subscription: HistorySubscription<TState> A callback to be trigger when a new history item is added.

returns: RemoveSubscription A function to remove the subscription from the store.

Subscribe a callback to be triggered when a new history item is added.

setEnabled

enabled: boolean Sets if the history is enabled or not.

Sets if the history should be enabled or not. Internally it is subscribing and unsubscribing from the store.

isEnabled

returns: boolean Returns true if the history store is enabled.

Returns true if the store is enabled.

clear

Clears the history items from the history store.

back

Goes back one item in the history. If history is disabled or is at the start of the history nothing is triggered.

forward

Goes forward one item in the history. If the history is disabled or at the most recent item nothing is triggered.

goto

index: number The history index to go to.

Goes to the history index. If it is out of outs, the index is the same as the current one or history is disabled then nothing is trigged.

License

MIT

Author

Alan Lawrey 2019