Updated to latest jsonld.js.
authorDave Longley <dlongley@digitalbazaar.com>
Wed, 09 Nov 2011 13:02:52 -0500
changeset 269 d6d08346d7fe
parent 268 1cf767917b93
child 270 b612b2699a7f
Updated to latest jsonld.js.
playground/jsonld.js
--- a/playground/jsonld.js	Wed Nov 09 12:56:20 2011 -0500
+++ b/playground/jsonld.js	Wed Nov 09 13:02:52 2011 -0500
@@ -645,7 +645,7 @@
                break;
             }
          }
-      }m
+      }
       if(quit)
       {
          break;
@@ -1850,17 +1850,23 @@
    }
    
    // keep sorting and naming blank nodes until they are all named
+   var resort = true;
    var self = this;
    while(bnodes.length > 0)
    {
-      bnodes.sort(function(a, b)
+      if(resort)
       {
-         return self.deepCompareBlankNodes(a, b);
-      });
+         bnodes.sort(function(a, b)
+         {
+            return self.deepCompareBlankNodes(a, b);
+         });
+      }
       
       // name all bnodes according to the first bnode's relation mappings
+      // (if it has mappings then a resort will be necessary)
       var bnode = bnodes.shift();
       var iri = bnode['@subject']['@iri'];
+      resort = (this.serializations[iri]['props'] !== null);
       var dirs = ['props', 'refs'];
       for(var d in dirs)
       {
@@ -1896,21 +1902,25 @@
             }
          }
          
-         // only keep non-canonically named bnodes
-         var tmp = bnodes;
-         bnodes = [];
-         for(var i in tmp)
+         // only clear serializations if resorting is necessary
+         if(resort)
          {
-            var b = tmp[i];
-            var iriB = b['@subject']['@iri'];
-            if(!c14n.inNamespace(iriB))
+            // only keep non-canonically named bnodes
+            var tmp = bnodes;
+            bnodes = [];
+            for(var i in tmp)
             {
-               // mark serializations related to the named bnodes as dirty
-               for(var i2 in renamed)
+               var b = tmp[i];
+               var iriB = b['@subject']['@iri'];
+               if(!c14n.inNamespace(iriB))
                {
-                  this.markSerializationDirty(iriB, renamed[i2], dir);
+                  // mark serializations related to the named bnodes as dirty
+                  for(var i2 in renamed)
+                  {
+                     this.markSerializationDirty(iriB, renamed[i2], dir);
+                  }
+                  bnodes.push(b);
                }
-               bnodes.push(b);
             }
          }
       }
@@ -2974,19 +2984,19 @@
    }
    else if(frame.constructor === Array)
    {
-      // save first context
+      // save first context in the array
       if(frame.length > 0 && '@context' in frame[0])
       {
          ctx = _clone(frame[0]['@context']);
-         
-         // expand all elements in the array
-         var tmp = [];
-         for(var i in frame)
-         {
-            tmp.push(jsonld.expand(frame[i]));
-         }
-         frame = tmp;
       }
+      
+      // expand all elements in the array
+      var tmp = [];
+      for(var i in frame)
+      {
+         tmp.push(jsonld.expand(frame[i]));
+      }
+      frame = tmp;
    }
    
    // create framing options