# easy-undo

> A simple JavaScript undo/redo interface; for easy management of 'state' histories in an application

Latest version **1.0.1** (published 2017-08-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install easy-undo
pnpm add easy-undo
yarn add easy-undo
bun add easy-undo
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2017-08-07 |
| First published | 2017-07-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 9 |
| Author | Sai Kishore Komanduri |
| Maintainers | fatman- |
| Keywords | undo, redo, history |

## Links

- npm: https://www.npmjs.com/package/easy-undo
- Repository: https://github.com/fatman-/easy-undo
- Issues: https://github.com/fatman-/easy-undo/issues
- npm.io page: https://npm.io/package/easy-undo

## Recent versions

- 1.0.1 (latest) — 2017-08-07
- 1.0.0 — 2017-07-16

## README

# easy-undo

A simple JavaScript undo/redo interface; for easy management of 'state' histories in an application.

This is a modern JS rewrite of the awesome [simple-undo](https://github.com/mattjmattj/simple-undo) project.

## Installation

```bash
$ npm install --save easy-undo
```

## Example

```javascript
import EasyUndo from 'easy-undo';

// Let's assume there's an object whose history needs to be tracked
const sampleAppState = {};

// The maximum number of states to be tracked
const maxLength = 10;

// We need a function which provides the required object in its "current" form
// to the EasyUndo instance, whenever required, via a callback function:
const provider = (cb) => cb(JSON.stringify(sampleAppState));

// Let's instantiate EasyUndo
const history = new EasyUndo({ maxLength, provider });

// The stringified version of the `sampleAppState` is saved, and managed by EasyUndo
// when the `save` method is called on the EasyUndo instance (see `provider`)
sampleAppState.secret = "foo";
history.save();

sampleAppState.secret = 42;
history.save();

// We need to specify the corresponding callback functions for the undo/redo
// operations on the EasyUndo instance.
const undoCb = (prevState) => {
    sampleAppState = JSON.parse(prevState);
};
const redoCb = (nextState) => {
    sampleAppState = JSON.parse(nextState);
};
// As you can see, these functions have access to the corresponding states.


history.undo(undoCb);
// sampleAppState -> { secret: "foo" }

history.redo(redoCb);
// sampleAppState -> { secret: 42 }


// That's it! It's Easy! Have fun! :-)
```

## License
MIT © [Sai Kishore Komanduri](https://github.com/fatman-)

---
_Source: https://npm.io/package/easy-undo · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
