From da9290ab968a9adeb02223e9aea7733d4688e3b0 Mon Sep 17 00:00:00 2001 From: Nickolay Platonov Date: Mon, 4 Oct 2010 16:19:56 +0400 Subject: [PATCH] - only store the data, which actually has the value --- lib/KiokuJS/Node.js | 8 ++++---- lib/KiokuJS/TypeMap/Joose.js | 17 +++++++++-------- t/060_encoder.t.js | 5 +++++ 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/lib/KiokuJS/Node.js b/lib/KiokuJS/Node.js index 2a64289..16db36f 100644 --- a/lib/KiokuJS/Node.js +++ b/lib/KiokuJS/Node.js @@ -9,11 +9,11 @@ Class('KiokuJS.Node', { // stored attributes ID : null, - className : null, - classVersion : null, - classTraits : null, + className : undefined, + classVersion : undefined, + classTraits : undefined, - isRoot : false, + isRoot : undefined, data : null, // run-time attributes diff --git a/lib/KiokuJS/TypeMap/Joose.js b/lib/KiokuJS/TypeMap/Joose.js index 9ff6d41..c4e1070 100644 --- a/lib/KiokuJS/TypeMap/Joose.js +++ b/lib/KiokuJS/TypeMap/Joose.js @@ -62,14 +62,15 @@ Class('KiokuJS.TypeMap.Joose', { this.eachAttribute(instance, function (attribute, name, attributeLevel) { - if (attributeLevel) { - data[ name ] = collapser.visit(attribute.getRawValueFrom(instance)) - - if (attributeLevel == 2 && attribute.meta.does(KiokuJS.Aspect.AfterCollapse)) attribute.afterCollapse(instance, data[ name ], node, collapser, attribute) - - } else - // Joose.Proto.Class attributes - just raw values - data[ name ] = collapser.visit(instance[ name ]) + if (attribute.hasValue(instance)) + if (attributeLevel) { + data[ name ] = collapser.visit(attribute.getRawValueFrom(instance)) + + if (attributeLevel == 2 && attribute.meta.does(KiokuJS.Aspect.AfterCollapse)) attribute.afterCollapse(instance, data[ name ], node, collapser, attribute) + + } else + // Joose.Proto.Class attributes - just raw values + data[ name ] = collapser.visit(instance[ name ]) }) diff --git a/t/060_encoder.t.js b/t/060_encoder.t.js index b228b74..c55d31a 100644 --- a/t/060_encoder.t.js +++ b/t/060_encoder.t.js @@ -103,6 +103,9 @@ StartTest(function(t) { t.ok(homerData.self.$ref == homerEntry.ID, "Homer's entry has correct self-reference") t.ok(homerData.spouse.$ref == margeNode.ID, "Homer's entry has correct `spouse` ref") t.ok(homerData.children.$ref == childrenNode.ID, "Homer's entry has correct `children` ref") + + t.ok(!homerData.hasOwnProperty('age'), "No property for 'age' attribute (entry only contain attributes with values)") + t.ok(!homerData.hasOwnProperty('task'), "No property for 'task' attribute (entry only contain attributes with values)") t.ok(margeEntry.$entry, "Marge's entry is marked with $entry") @@ -115,6 +118,8 @@ StartTest(function(t) { t.ok(margeData.spouse.$ref == homerNode.ID, "Marge's entry has correct `spouse` ref") t.ok(margeData.children.$ref == childrenNode.ID, "Marge's entry has correct `children` ref") + t.ok(!margeData.hasOwnProperty('age'), "No property for 'age' attribute (entry only contain attributes with values)") + t.ok(childrenEntry.$entry, "Children's entry is marked with $entry") t.ok(childrenEntry.ID == childrenNode.ID, "Children's entry has correct ID")