undo-redoer

Simple and robust CoffeeScript/JavaScript library for undo/redo features on plain state object. Full test coverage. For Node.JS and Browser (with AMD support).

Usage no npm install needed!

<script type="module">
  import undoRedoer from 'https://cdn.skypack.dev/undo-redoer';
</script>

README

UndoRedoer

Simple and robust CoffeeScript/JavaScript library for undo/redo features on plain state object. Full test coverage and it is using on production as well.

Installation

npm install undo-redoer

Usage

UndoRedoer = require './UndoRedoer'

# initiate some example state object
state =
    meta:
        description: "state object can be recursive as well"
        removeMe: "I will be removed"
    id: "unique-id"
    x: 0
    y: 0


ur = new UndoRedoer state

# push some change
ur.pushChanges
    x: 1
    y: 2

# remove something
ur.pushChanges
    meta:
        removeMe: undefined

# whoops
ur.pushChanges
    x: undefined

backDiff = ur.undo() # backDiff now contains reverse change { x:1 }

console.log "\nbackDiff:"
console.dir backDiff # output to console

console.log "\nstate:"
console.dir ur.state # check undo'ed state

above example outputs:

backDiff:
{ x: 1 }

state:
{ meta: { description: 'state object can be recursive as well' },
  id: 'unique-id',
  y: 2,
  x: 1 }

Test

npm intall --dev
npm test

Authors and contributors

License

(The MIT License)

Copyright (c) 2008-2013 Se7enSky studio <info@se7ensky.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.