node package manager
Don’t reinvent the wheel. Reuse code within your team. Create a free org »

object-history

object-history NPM version Build Status js-standard-style

JavaScript Object history

Behind the scenes

For cloning, UltraDeepClone. For diff/apply, changeset.

Old browsers

Works in IE8 with es5-shim. Perhaps IE7, as well.

API

History

Gives birth to instances

  • initial {Object}: The initial history point
  • options {Object}: limit: {Number} Remember this many backward points
var History = require('object-history')
var initial = {foo: 'bar', name: 'victoria'}
var history = new History(initial, {limit: 33})

.add

Add a history point object

  • obj {Object}: The history point
history.add({
  foo: 'bar',
  bar: 'foo'
})

.backward

Go back one history point

.forgetAllBackward

Makes all backward history forgotten

.forgetAllForward

Makes all forward history forgotten

.forward

Go forward one history point

.get

  • returns {Object}: "Current" history point

.lengthBackward

  • returns {Number}: Number of history points backwards

.lengthForward

  • returns {Number}: Number of history points forward

License

Copyright © 2015 PolicyStat LLC

Released under the BSD-3-Clause license.