Skip to content

Commit

Permalink
- only store the data, which actually has the value
Browse files Browse the repository at this point in the history
  • Loading branch information
Nickolay Platonov committed Oct 4, 2010
1 parent 26273db commit da9290a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
8 changes: 4 additions & 4 deletions lib/KiokuJS/Node.js
Expand Up @@ -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
Expand Down
17 changes: 9 additions & 8 deletions lib/KiokuJS/TypeMap/Joose.js
Expand Up @@ -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 ])
})


Expand Down
5 changes: 5 additions & 0 deletions t/060_encoder.t.js
Expand Up @@ -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")
Expand All @@ -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")
Expand Down

0 comments on commit da9290a

Please sign in to comment.