diff lib/js/urweb.js @ 693:655bcc9b77e0

_Really_ implement embedded closure GC; extend Scriptcheck to figure out when client IDs must be assigned
author Adam Chlipala <adamc@hcoop.net>
date Sat, 04 Apr 2009 14:03:39 -0400
parents 09df0c85f306
children a5d8b470d7ca
line wrap: on
line diff
--- a/lib/js/urweb.js	Sat Apr 04 12:54:39 2009 -0400
+++ b/lib/js/urweb.js	Sat Apr 04 14:03:39 2009 -0400
@@ -22,11 +22,19 @@
 
 // Embedding closures in XML strings
 
+function cs(f) {
+  return {closure: f};
+}
+
+function isWeird(v) {
+  return v.closure != null || v.cat1 != null;
+}
+
 function cat(s1, s2) {
-  if (s1.length && s2.length)
+  if (isWeird(s1) || isWeird(s2))
+    return {cat1: s1, cat2: s2};
+  else
     return s1 + s2;
-  else
-    return {_1: s1, _2: s2};
 }
 
 var closures = [];
@@ -42,12 +50,12 @@
 }
 
 function flatten(tr) {
-  if (tr.length)
+  if (tr.cat1 != null)
+    return flatten(tr.cat1) + flatten(tr.cat2);
+  else if (tr.closure != null)
+    return "cr(" + newClosure(tr.closure) + ")";
+  else
     return tr;
-  else if (tr._1)
-    return cs(tr._1) + cs(tr._2);
-  else
-    return "cr(" + newClosure(tr) + ")";
 }
 
 function clearClosures() {
@@ -157,7 +165,7 @@
         ls.data.dyns = remove(span, ls.data.dyns);
     }
 
-    x.innerHTML = v;
+    x.innerHTML = flatten(v);
     runScripts(x);
 
     if (--dynDepth == 0)
@@ -412,3 +420,7 @@
     k(parse(msg))(null);
   }
 }
+
+
+// App-specific code
+