unreson
TypeScript icon, indicating that this package has built-in type declarations

0.15.0 • Public • Published

unreson -- undo/redo-able object wrapper

unreson provides the StateObject class that manages the state for a provided JSON-safe object. Changes to the object, no matter how deep, may be undone or redone. The state of the object can also be made temporarily immutable if the need arises.

Usage

let unreson = require('unreson')

let myObject = new unreson.StateObject({ a: 0, b: 1, c: {}, d: [0,1,2,3,4] })

console.log(myObject.state) // { a: 0, b: 1, c: {}, d: [ 0, 1, 2, 3, 4 ] }
myObject.state.c = 2
console.log(myObject.state) // { a: 0, b: 1, c: 2, d: [ 0, 1, 2, 3, 4 ] }
myObject.undo()
console.log(myObject.state) // { a: 0, b: 1, c: {}, d: [ 0, 1, 2, 3, 4 ] }
myObject.redo()
console.log(myObject.state) // { a: 0, b: 1, c: 2, d: [ 0, 1, 2, 3, 4 ] }
myObject.freeze()
console.log(myObject.frozen) // true
myObject.state.c = 3
myObject.thaw()
console.log(myObject.frozen) // false
console.log(myObject.state) // { a: 0, b: 1, c: 2, d: [ 0, 1, 2, 3, 4 ] }

Readme

Keywords

Package Sidebar

Install

npm i unreson

Weekly Downloads

2

Version

0.15.0

License

MPL-2.0

Unpacked Size

43.3 kB

Total Files

8

Last publish

Collaborators

  • kettek