0.2.2 • Published 5 years ago

fast-undo v0.2.2

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

fast-undo

Efficient data structure for handling undo states.

Build Status

// 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, or similiar:

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

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

See the tests.js file for some more inspiration.

API

init

function init<T>(a: T): History<T>;

undo

function undo<T>(a: History<T>): History<T>;

redo

function redo<T>(a: History<T>): History<T>;

insert

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

prune

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

serialize

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

deserialize

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

history

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

withHistory

function withHistory<T>(a: Reducer<T>): Reducer<History<T>>;
0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.8

6 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago

1.0.0

7 years ago