if(this._currentTransaction) {
throw new Error('Nested transactions not supported!');
}
+ this._rollbackBackup = this.root.clone();
this._currentTransaction = new Transaction([], metadata);
},
this._currentTransaction = null;
},
+ rollbackTransaction: function() {
+ if(!this._currentTransaction) {
+ throw new Error('Transaction rollback requested, but there is no transaction in progress!');
+ }
+ this.replaceRoot(this._rollbackBackup);
+ this._rollbackBackup = null;
+ this._currentTransaction = null;
+ },
+
transaction: function(callback, context, metadata) {
var toret;
this.startTransaction(metadata);
var transaction = doc.undoStack[0];
expect(transaction.metadata).to.equal(metadata);
});
+
+ it('can be rolled back', function() {
+ var doc = getDocumentFromXML('<root></root>');
+
+ doc.startTransaction();
+ doc.root.append({tagName: 'div'});
+ doc.rollbackTransaction();
+
+ expect(doc.undoStack.length).to.equal(0, 'nothing to undo');
+ expect(doc.root.contents().length).to.equal(0);
+ });
});
describe('Regression tests', function() {