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 🙏

© 2025 – Pkg Stats / Ryan Hefner

redux-undo-actions

v0.1.1

Published

Redux middleware for undo/redo actions by dispatching reverting action

Readme

redux-undo-actions

Overview

redux-undo-actions is a Redux middleware for undo/redo actions. It doesn't change the state as redux-undo. Instead of changing the state of application it dispatches an action that is the opposite of the one that is in the history.

Installation

To start using redux-undo-actions, you need to run following command:

npm install --save redux-undo-actions

Usage

To start using this middleware, you need to add it to your redux middlewares and pass config as a parameter:

import {undoActionsMiddleware} from 'redux-undo-actions'


export const config = {
    revertibleActions: {
        [actionTypes.INCREMENT]: actions.decrement(),
        [actionTypes.DECREMENT]: actions.increment()
    }
};

const middlewares = [
    undoActionsMiddleware(config),
    // other middlewares that you want to use
];

const store = createStore(
    reducer,
    applyMiddleware(...middlewares)
);

Here config is an object that contains currently only one field revertibleActions. It's a mapping between original actions and reverting action. So, when undo is called, it takes action from the history, searches for reverting action in this revertibleActions and if it was found, then a new reverting action is dispatched. There can be situations when new action needs arguments that can be obtained from the state or the original actions. In this case, you need to use the more complex notation:

export const config = {
    revertibleActions: {
        [actionTypes.CREATE]: ({
            actionCreator: ({ id }) => actions.remove(id),
            mapStateToArgs: (action) => ({ id: action.id })
        }),
        [actionTypes.REMOVE]: ({
            actionCreator: ({ id, text }) => actions.create(id, text),
            mapStateToArgs: (action, state) => ({
                id: action.id,
                text: state.list.filter(el => el.id === action.id)[0].text
            })
        })
    }
};

mapStateToArgs is a function that takes original action and previous state and returns an object of arguments for the new action.

When this is done, you need to add undoHistory to your top-level reducer:

import undoHistory from 'redux-undo-actions';

export default combineReducers({
    application,
    undoHistory
});

## Undo/Redo Actions

Then you can use this actions when you want to call undo/redo:

import {undoActions} from 'redux-undo-actions';

store.dispatch(undoActions.undo()) // undo the last action
store.dispatch(undoActions.redo()) // redo the last action

store.dispatch(undoActions.clearHistory()) // clear undo/redo history

Contribution

This is the list of features to be done:

  • Store asynchronous actions in the history in the order they are dispatched including their children
  • When undo is called two times, wait for the first reverting action to be done and then dispatch second
  • ~~Add support for asynchronous actions~~

If you feel that you have some time to improve this package, feel free to fork this repo and make a pull request with your changes.

License & Author

This package is distributed under the MIT License by Taras Zelyk