summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adamc@hcoop.net>2008-12-30 16:08:25 -0500
committerGravatar Adam Chlipala <adamc@hcoop.net>2008-12-30 16:08:25 -0500
commit60eda55ff1c5d68bb6b4d1ea49f22ccede87d22e (patch)
tree885bf20f7b2d9dd0cbd857401b5fc833ba27c32d
parent603c77259221a3d0c5577d863b2b2c75fbdc6278 (diff)
Propagating a change through a bind
-rw-r--r--jslib/urweb.js36
-rw-r--r--tests/reactive4.ur7
-rw-r--r--tests/reactive4.urp3
3 files changed, 40 insertions, 6 deletions
diff --git a/jslib/urweb.js b/jslib/urweb.js
index 86c3808c..508f4318 100644
--- a/jslib/urweb.js
+++ b/jslib/urweb.js
@@ -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);
}
diff --git a/tests/reactive4.ur b/tests/reactive4.ur
new file mode 100644
index 00000000..b5278a63
--- /dev/null
+++ b/tests/reactive4.ur
@@ -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>
diff --git a/tests/reactive4.urp b/tests/reactive4.urp
new file mode 100644
index 00000000..e32cf7a7
--- /dev/null
+++ b/tests/reactive4.urp
@@ -0,0 +1,3 @@
+debug
+
+reactive4