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

@harlem/extension-history

v3.1.8

Published

The official history extension for Harlem

Downloads

12

Readme

Harlem History Extension (preview)

The history extension adds undo and redo capabilities to your store for easily integrating history features into your application.

Getting Started

Follow the steps below to get started using the history extension.

Installation

Before installing this extension make sure you have installed harlem.

yarn add @harlem/extension-history
# or
npm install @harlem/extension-history

Registration

To get started simply register this extension with the store you wish to extend.

import historyExtension from '@harlem/extension-history';

import {
    createStore
} from 'harlem';

const STATE = {
    firstName: 'Jane',
    lastName: 'Smith'
};

const {
    state,
    getter,
    mutation,
    undo,
    redo
} = createStore('example', STATE, {
    extensions: [
        historyExtension({
            max: 50,
            mutations: [
                {
                    name: 'set-name',
                    description: 'Set the current user\'s name'
                }
            ]
        })
    ]
});

The history extension adds several new methods to the store instance (highlighted above).

Usage

Options

The history extension method accepts an options object with the following properties:

  • max: number - The maximum number of history steps to store. The default value is 50.
  • mutations: object[] - The mutations you wish to track. leaving this undefined will cause all mutations to be tracked. The default is undefined.
    • name: string - The name of the mutation to track. This must match the name of a registered mutation.
    • description: string? - An optional description of the mutations intentions. This is useful for displaying a list of commands in the UI.

Undoing/Redoing mutations

To undo or redo a mutation simply call the undo or redo methods returned from the store instance.

Considerations

Please keep the following points in mind when using this extension:

  • This extension has a slight performance cost. Each tracked mutation is proxied and values are cloned pre/post mutation. If you are assigning/moving/deleting large object structures around state this cause a performance hit and increase in memory usage. It is recommended to keep mutations granular and precise when tracking them with the history (or trace) extension.
  • This extension cannot handle untracked mutation side-effects. For example, say you have 2 mutations, mutation1 and mutation2. Both mutations modify the same branch of state but mutation1 is tracked by the history extension and mutation2 is not. Undoing the changes from mutation1 any time after running mutation2 will cause changes from mutation2 to be lost and unrecoverable.