From fb23a597811c4c60dd1b9bddeab4335a33bee8c1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Tue, 17 Dec 2013 12:52:33 +0100 Subject: [PATCH] smartxml: transactions fix - ignore empty transactions Handle doc.transactionStart(); doc.transactionEnd() without actual transformations performed in between. --- src/smartxml/smartxml.js | 6 ++++-- src/smartxml/smartxml.test.js | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/smartxml/smartxml.js b/src/smartxml/smartxml.js index d9e44be..f92bf01 100644 --- a/src/smartxml/smartxml.js +++ b/src/smartxml/smartxml.js @@ -509,8 +509,10 @@ $.extend(Document.prototype, Backbone.Events, { throw new Error('End of transaction requested, but there is no transaction in progress!'); } this._transactionInProgress = false; - this.undoStack.push(this._transactionStack); - this._transactionStack = []; + if(this._transactionStack.length) { + this.undoStack.push(this._transactionStack); + this._transactionStack = []; + } }, getNodeByPath: function(path) { diff --git a/src/smartxml/smartxml.test.js b/src/smartxml/smartxml.test.js index cc68cdd..57f11cc 100644 --- a/src/smartxml/smartxml.test.js +++ b/src/smartxml/smartxml.test.js @@ -1273,6 +1273,13 @@ describe('smartxml', function() { expect(doc.root.getAttr('test'), '3'); }); + it('ignores empty transactions', function() { + var doc = getDocumentFromXML('
'); + doc.startTransaction(); + doc.endTransaction(); + expect(doc.undoStack).to.have.length(0, 'empty transaction doesn\'t get pushed into undo stack'); + }); + it('doesn\'t break on optimizations', function() { // This is a smoke test checking if optimizations made to transaction undoing // doesnt't break anything. -- 2.20.1