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

@intactile/redux-undo-redo

v0.10.1

Published

An undo redo package for redux

Readme

redux-undo-redo

An undo redo package for redux

Build Status Maintainability Test Coverage

This package is heavily inspired by the undo/redo package developed by PowToon.

This package adds an undo redo history to a redux state. For each undoable action, you have to provide its reverting action. It supports also grouped actions which lets you undo a set of actions in one step.

Installation

npm install @intactile/redux-undo-redo

or

yarn add @intactile/redux-undo-redo

Configuration

This package is configured with a set of reverting actions:

import counter, {
  increment,
  decrement,
  setValue,
  INCREMENT,
  DECREMENT,
  SET_COUNTER_VALUE
} from "./counterReduxModule";

const revertingActions = {
  [INCREMENT]: () => decrement(),
  [DECREMENT]: () => increment(),
  [SET_COUNTER_VALUE]: {
    action: (action, { val }) => setValue(val),
    createArgs: (state, action) => ({ val: state.counter })
  }
};

Reverting actions

This is a map between the action type and it's reverting action creator, the action creator gets the original action and should return the reverting action. If the the original action is not enough to create a reverting action you can provide createArgs that will result in an args argument for the reverting action:

{
  action: (action, args) => revertingActionCreator(action.something, args.somethingElse),
  createArgs: (state, action) => ({somethingElse: state.something}),
  groupWithPrevious: (action, previousAction) => action.type === previousAction.type
}

the createArgs function runs before the action happens and collects information needed to revert the action. you get this as a second argument for the reverting action creator. the optional groupWithPrevious function allows to group an action with the previous one.

Middleware and reducer

These reverting actions are supplied to a middleware registered with a reducer on the redux store.

import { createStore, combineReducers, applyMiddleware } from "redux";
import {
  createUndoReducer,
  createUndoMiddleware
} from "@intactile/redux-undo-redo";

const undoMiddleware = createUndoMiddleware({ revertingActions });
const undoHistory = : createUndoReducer();
const store = createStore(
  combineReducers({ counter, undoHistory }), // add the reducer
  initialState,
  applyMiddleware(thunk) // add the middleware
);

History size

The undo and the redo histories are limited to respectively 50 and 10 by default. They can be increased or decreased when the reducer is created:

const undoHistory = createUndoReducer({
  undoHistorySize: 200,
  redoHistorySize: 100
});

Usage

Undo/redo actions

import { actions, selectors } from "@intactile/redux-undo-redo";
import { increment, decrement, setValue } from "./counterReduxModule";

store.dispatch(increment()); // counter = 1
store.dispatch(increment()); // counter = 2
console.log(selectors.canUndo(store.getState())); // true

store.dispatch(actions.undo()); // counter = 1
console.log(selectors.canRedo(store.getState())); // true

store.dispatch(actions.redo()); // counter = 2

Undo/redo group of actions

store.dispatch(actions.group(increment(), increment(), increment())); // counter = 3

store.dispatch(actions.undo()); // counter = 0
store.dispatch(actions.redo()); // counter = 3

Undo/redo group of actions with redux-thunk

store.dispatch(
  actions.group(dispatch => {
    dispatch(increment());
    dispatch(increment());
    dispatch(increment());
  })
); // counter = 3

store.dispatch(actions.undo()); // counter = 0
store.dispatch(actions.redo()); // counter = 3

Group automatically successive actions

It is possible to group an action with the previous one. The reverting action should be configured with a new function.

[ADD_VALUE]: {
  action: action => removeValue(action.payload),
  groupWithPrevious: (action, previousAction) => action.type === previousAction.type
}

If the previous action have the same type, the actions will be automatically grouped.

store.dispatch(addValue(1)); // counter = 1
store.dispatch(addValue(2)); // counter = 3
store.dispatch(addValue(3)); // counter = 6

store.dispatch(actions.undo()); // counter = 0
store.dispatch(actions.redo()); // counter = 6