smartxml: allow for removing node data for a specified key
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Tue, 27 May 2014 10:07:05 +0000 (12:07 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Tue, 27 May 2014 14:18:07 +0000 (16:18 +0200)
src/smartxml/smartxml.js
src/smartxml/smartxml.test.js

index 749d4f4..de70e9b 100644 (file)
@@ -177,8 +177,12 @@ $.extend(ElementNode.prototype, {
     nodeType: Node.ELEMENT_NODE,
 
     setData: function(key, value) {
     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);
         } else {
             this._$.removeData(_.keys(this._$.data()));
             this._$.data(key);
index a994f05..2a6c5e0 100644 (file)
@@ -163,6 +163,12 @@ describe('smartxml', function() {
                 node.setData({key1: 'value1', key2: 'value2'});
                 expect(node.getData()).to.eql({key1: 'value1', key2: 'value2'});
             });
                 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() {
         });
 
         describe('Changing node tag', function() {