From fb3b7d9bff29aa5c99298ce9e4bae53c2eb47a7d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Tue, 27 May 2014 12:07:05 +0200 Subject: [PATCH 1/1] smartxml: allow for removing node data for a specified key --- src/smartxml/smartxml.js | 8 ++++++-- src/smartxml/smartxml.test.js | 6 ++++++ 2 files changed, 12 insertions(+), 2 deletions(-) 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() { -- 2.20.1