Wrap any class with this mixin and it will track the objects history, including all property changes on the object, and gives the ability to undo and redo.
class Person extends KeepsHistory(class {}) {
constructor(name, age) {
this.name = name
this.age = age
}
}
let jimmy = new Person('jimmy', 0)
jimmy.age = 50
console.log(jimmy.age) // 50
jimmy.undo()
console.log(jimmy.age) // 0
jimmy.redo()
console.log(jimmy.age) // 50
jimmy.age = 10
jimmy.age = 20
jimmy.age = 30
console.log(jimmy.age) // 30
jimmy.undo(2) // undo twice
console.log(jimmy.age) // 10
jimmy.redo(2) // redo twice
console.log(jimmy.age) // 30