Updated to latest jsonld.js.
authorDave Longley <dlongley@digitalbazaar.com>
Mon, 28 Nov 2011 22:56:02 -0500
changeset 279 05a8952a7c64
parent 278 635430da786a
child 280 c70c1b587b38
Updated to latest jsonld.js.
playground/jsonld.js
--- a/playground/jsonld.js	Sun Nov 27 22:28:16 2011 -0800
+++ b/playground/jsonld.js	Mon Nov 28 22:56:02 2011 -0500
@@ -2737,10 +2737,10 @@
    // 1. The frame OR default option specifies @embed as ON, AND
    // 2. There is no existing embed OR it is an autoembed, AND
    //    autoembed mode is off.
-   var embedOn =
+   var embedOn = (
       (('@embed' in frame && frame['@embed']) ||
       (!('@embed' in frame) && options.defaults.embedOn)) &&
-      (embed === null || (embed.autoembed && !autoembed));
+      (embed === null || (embed.autoembed && !autoembed)));
    
    if(!embedOn)
    {
@@ -2760,6 +2760,7 @@
       {
          if(embed.parent[embed.key].constructor === Array)
          {
+            // find and replace embed in array
             var objs = embed.parent[embed.key];
             for(var i in objs)
             {
@@ -2775,6 +2776,23 @@
          {
             embed.parent[embed.key] = value['@subject'];
          }
+         
+         // recursively remove any dependent dangling embeds
+         var removeDependents = function(iri)
+         {
+            var iris = Object.keys(embeds);
+            for(var i in iris)
+            {
+               i = iris[i];
+               if(i in embeds && embeds[i].parent !== null &&
+                  embeds[i].parent['@subject']['@iri'] === iri)
+               {
+                  delete embeds[i];
+                  removeDependents(i);
+               }
+            }
+         };
+         removeDependents(iri);
       }
       
       // update embed entry