Nicely Presented Misnomer
Publish your own packages to the world's most popular software ecosystem with npm Pro.Get started »

undo-redo-proxy

1.0.0 • Public • Published

undo-redo-proxy

Build Status NPM Version License Dependency Status devDependency Status

⏳ Effortless timetravel - undo/redo proxy wrapper for arrays

Installation

npm install undo-redo-proxy

Usage

import trackHistory from 'undo-redo-proxy'
let array = ['my', 'array']
// wraps your array, returns proxy which behaves like a normal array
array = trackHistory(array)
console.log(array) // ['my', 'array']
array.push('foo')  // ['my', 'array', 'foo']
array[2] = 'bar'   // ['my', 'array', 'bar']
array.undo()       // ['my', 'array', 'foo']
array.undo()       // ['my', 'array']
array.shift()      // ['array']
array.redo()       // ['my', 'array']

Can be used in browser as well

import trackHistory from './node_modules/undo-redo-proxy/index.mjs'
let users = trackHistory([])

Only keeps track of the array and its items and positions.

users.push({name: 'Mike'})
users.push({name: 'Lucy'})
users.shift()
console.log(users) // [{name: 'Lucy'}]
users.undo()
console.log(users) // [{name: 'Mike'}, {name: 'Lucy'}]

Does not track content of array items.

users.push({name: 'Mike'}) // can be undone
users[0].name = 'Lucy' // cannot be undone
console.log(users) // [{name: 'Lucy'}]
users.undo()
console.log(users) // [{name: 'Lucy'}]

Licence

MIT, Mike Kovařík, Mutiny.cz

Install

npm i undo-redo-proxy

DownloadsWeekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

6.55 kB

Total Files

4

Last publish

Collaborators

  • avatar