Ember.js v0.9.7.1
by pangratz666
HTML
<script src="https://github.com/downloads/emberjs/ember.js/ember-0.9.7.1.js"></script>
<script src="https://raw.github.com/pangratz/ember-memento/master/app/lib/memento.js"></script>
<script type="text/x-handlebars" >
</script>
JavaScript
App = Ember.Application.create({});
var myObj = Ember.Object.create(Ember.Memento, {
// properties which are "tracked"
mementoProperties: 'firstName age tags'.w(),
firstName: 'Buster',
age: 78,
tags: ['cool', 'great'],
log: function() {
console.log('firstName = %@ , age = %@ , tags = %@'.fmt(this.get('firstName'), this.get('age'), this.get('tags')));
}
});
myObj.get('tags').pushObject('super');
myObj.set('firstName', 'Michael');
myObj.set('age', 100);
myObj.log();
myObj.undo();
myObj.log(); // firstName = Michael, age = 78, tags = [cool, great, super]
myObj.undo();
myObj.log(); // firstName = Buster, age 78, tags = [cool, great, super]
myObj.undo();
myObj.log(); // firstName = Buster, age 78, tags = [cool, great]
myObj.redo();
myObj.log(); // firstName = Buster, age 78, tags = [cool, great, super]
myObj.redo();
myObj.log(); // firstName = Michael, age 78, tags = [cool, great, super]
myObj.redo();
myObj.log(); // firstName = Michael, age 100, tags = [cool, great, super]