From: Aleksander Ɓukasz Date: Tue, 27 May 2014 10:07:05 +0000 (+0200) Subject: smartxml: allow for removing node data for a specified key X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/fb3b7d9bff29aa5c99298ce9e4bae53c2eb47a7d smartxml: allow for removing node data for a specified key --- diff --git a/src/smartxml/smartxml.js b/src/smartxml/smartxml.js index 749d4f4..de70e9b 100644 --- a/src/smartxml/smartxml.js +++ b/src/smartxml/smartxml.js @@ -177,8 +177,12 @@ $.extend(ElementNode.prototype, { nodeType: Node.ELEMENT_NODE, setData: function(key, value) { - if(value !== undefined) { - this._$.data(key, value); + if(arguments.length === 2) { + if(_.isUndefined(value)) { + this._$.removeData(key); + } else { + this._$.data(key, value); + } } else { this._$.removeData(_.keys(this._$.data())); this._$.data(key); diff --git a/src/smartxml/smartxml.test.js b/src/smartxml/smartxml.test.js index a994f05..2a6c5e0 100644 --- a/src/smartxml/smartxml.test.js +++ b/src/smartxml/smartxml.test.js @@ -163,6 +163,12 @@ describe('smartxml', function() { node.setData({key1: 'value1', key2: 'value2'}); expect(node.getData()).to.eql({key1: 'value1', key2: 'value2'}); }); + + it('can remove specific data', function() { + node.setData('key', 'value'); + node.setData('key', undefined); + expect(node.getData('key')).to.be.undefined; + }); }); describe('Changing node tag', function() {