/undo-redo

Javascript package for handling undo/redo functionality.

Primary LanguageJavaScript

Undo/Redo

A javascript package for handling undo/redo functionality.

Read the docs

NPM

Install

yarn add @fa-repo/undo-redo --dev

Basic usage

import UndoRedo from '@fa-repo/undo-redo';
import arrayMove from 'array-move';

let items = ['apple', 'pear', 'mango'];

const undoRedo = new UndoRedo();

const moveItem = (from, to) => {
  undoRedo.add({
    do: () => arrayMove(items, from, to),
    undo:() => arrayMove(items, to, from),
  })
}

const undoChanges = () => {
  undoRedo.undo();
}

const redoChanges = () => {
  undoRedo.redo();
}

License

MIT