diff options
author | 2008-12-30 16:08:25 -0500 | |
---|---|---|
committer | 2008-12-30 16:08:25 -0500 | |
commit | 7f3851104f9fdefdd09d8e9a0f600968175589e0 (patch) | |
tree | 885bf20f7b2d9dd0cbd857401b5fc833ba27c32d | |
parent | be73a31fb83c7da398322f6e92e94a7297212b7c (diff) |
Propagating a change through a bind
-rw-r--r-- | jslib/urweb.js | 36 | ||||
-rw-r--r-- | tests/reactive4.ur | 7 | ||||
-rw-r--r-- | tests/reactive4.urp | 3 |
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 |