# fast-undo

> Efficient data structure for handling undo states.

Latest version **0.2.2** (published 2019-01-30) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.2 |
| Published | 2019-01-30 |
| First published | 2017-06-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 53.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Adam Gamble |
| Maintainers | gamble |
| Keywords | undo, redux, history, redo, state |

## Links

- npm: https://www.npmjs.com/package/fast-undo
- Repository: https://github.com/gamb/fast-undo
- Homepage: https://github.com/gamb/fast-undo#readme
- Issues: https://github.com/gamb/fast-undo/issues
- npm.io page: https://npm.io/package/fast-undo

## Alternatives

- [@reckona/mreact-store](https://npm.io/package/@reckona/mreact-store.md) — 976 weekly downloads
- [regular-state](https://npm.io/package/regular-state.md) — 410 weekly downloads
- [@pacote/flux-actions](https://npm.io/package/@pacote/flux-actions.md) — 65 weekly downloads
- [@pilotlab/lux-debug](https://npm.io/package/@pilotlab/lux-debug.md) — 39 weekly downloads
- [vue-persist-state](https://npm.io/package/vue-persist-state.md) — 19 weekly downloads

## Recent versions

- 0.2.2 (latest) — 2019-01-30
- 0.2.1 — 2019-01-27
- 0.2.0 — 2019-01-19
- 0.1.4 — 2018-05-04
- 0.1.3 — 2018-05-02
- 0.1.2 — 2018-05-02
- 0.1.1 — 2018-05-02
- 0.1.0 — 2018-05-02
- 0.0.7 — 2017-09-01
- 0.0.6 — 2017-08-12
- 0.0.5 — 2017-06-09
- 0.0.4 — 2017-06-07
- 0.0.3 — 2017-06-07
- 0.0.2 — 2017-06-07

## README

# fast-undo

Efficient data structure for handling undo states.

[![Build Status](https://travis-ci.org/gamb/fast-undo.svg?branch=master)](https://travis-ci.org/gamb/fast-undo)

```javascript
// create an empty undo history
const history = undo.history()

// insert a few values
history.insert('cat')
history.insert('dog')
history.insert('rabbit')

// undo
history.undo() // cat <| dog |> rabbit

// redo
history.redo() // dog <| rabbit |> EMPTY

// export
history.toJSON() // '{"past":["dog","cat"],"present":"rabbit","future":[]}'
```

Install as an NPM module:

```
$ npm install fast-undo
```

Works as a higher-order reducer with [Redux](https://github.com/reactjs/redux/), or similiar:

```javascript
import { combineReducers } from 'redux';
import { withHistory } from 'fast-undo';

combineReducers({
  undoableReducer: withHistory(myReducer)
});
```

See the tests.js file for some more inspiration.

## API

### init
```typescript
function init<T>(a: T): History<T>;
```

### undo
```typescript
function undo<T>(a: History<T>): History<T>;
```

### redo
```typescript
function redo<T>(a: History<T>): History<T>;
```

### insert
```typescript
function insert<T>(a: History<T>, b: T): History<T>;
```

### prune
```typescript
function prune<T>(history: History<T>, size?: number): History<T>;
```

### serialize
```typescript
function serialize<T>(a: History<T>): JSONHistory<T>;
```

### deserialize
```typescript
function deserialize<T>(a: JSONHistory<T>): History<T>;
```

### history
```typescript
function history<T>(a: T): {
    undo: () => History<T>;
    redo: () => History<T>;
    insert: (a: T) => History<T>;
    get: () => History<T>;
    toJSON: () => string;
};
```

### withHistory
```typescript
function withHistory<T>(a: Reducer<T>): Reducer<History<T>>;
```

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