changeset 580:bb8463c3b712

Propagating a change through a bind
author Adam Chlipala <adamc@hcoop.net>
date Tue, 30 Dec 2008 16:08:25 -0500
parents 0094e0242100
children e955d50c389d
files jslib/urweb.js tests/reactive4.ur tests/reactive4.urp
diffstat 3 files changed, 40 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/jslib/urweb.js	Tue Dec 30 15:53:04 2008 -0500
+++ b/jslib/urweb.js	Tue Dec 30 16:08:25 2008 -0500
@@ -1,18 +1,42 @@
+function cons(v, ls) {
+  return { n : ls, v : v };
+}
 function callAll(ls) {
   for (; ls; ls = ls.next)
     ls.v();
 }
 
-function sc(v) { return {v : v, h : null} }
-function sv(s, v) { s.v = v; callAll(s.h); }
+function sc(v) {
+  return {v : v, h : null};
+}
+function sv(s, v) {
+  s.v = v;
+  callAll(s.h);
+}
 
-function ss(s) { return s }
-function sr(v) { return {v : v, h : null} }
-function sb(x,y) { return {v : y(x.v).v, h : null} }
+function ss(s) {
+  return s;
+}
+function sr(v) {
+  return {v : v, h : null};
+}
+function sb(x,y) {
+  var z = y(x.v);
+  var s = {v : z.v, h : null};
+
+  function reZ() {
+    z.h = cons(function() { s.v = z.v; callAll(s.h); }, z.h);    
+  }
+
+  x.h = cons(function() { z = y(x.v); reZ(); s.v = z.v; callAll(s.h); }, x.h);
+  reZ();
+
+  return s;
+}
 
 function dyn(s) {
   var x = document.createElement("span");
   x.innerHTML = s.v;
   document.body.appendChild(x);
-  s.h = { n : s.h, v : function() { x.innerHTML = s.v } };
+  s.h = cons(function() { x.innerHTML = s.v }, s.h);
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/reactive4.ur	Tue Dec 30 16:08:25 2008 -0500
@@ -0,0 +1,7 @@
+fun main () : transaction page =
+  x <- source <xml>TEST</xml>;
+  return <xml><body>
+    <dyn signal={y <- signal x; return <xml>!{y}?</xml>}/>
+    <br/>
+    <a onclick={set x <xml>CHANGEUP</xml>}>Oh My</a>
+  </body></xml>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/reactive4.urp	Tue Dec 30 16:08:25 2008 -0500
@@ -0,0 +1,3 @@
+debug
+
+reactive4