Mercurial > urweb
comparison jslib/urweb.js @ 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 | 66463006f893 |
comparison
equal
deleted
inserted
replaced
579:0094e0242100 | 580:bb8463c3b712 |
---|---|
1 function cons(v, ls) { | |
2 return { n : ls, v : v }; | |
3 } | |
1 function callAll(ls) { | 4 function callAll(ls) { |
2 for (; ls; ls = ls.next) | 5 for (; ls; ls = ls.next) |
3 ls.v(); | 6 ls.v(); |
4 } | 7 } |
5 | 8 |
6 function sc(v) { return {v : v, h : null} } | 9 function sc(v) { |
7 function sv(s, v) { s.v = v; callAll(s.h); } | 10 return {v : v, h : null}; |
11 } | |
12 function sv(s, v) { | |
13 s.v = v; | |
14 callAll(s.h); | |
15 } | |
8 | 16 |
9 function ss(s) { return s } | 17 function ss(s) { |
10 function sr(v) { return {v : v, h : null} } | 18 return s; |
11 function sb(x,y) { return {v : y(x.v).v, h : null} } | 19 } |
20 function sr(v) { | |
21 return {v : v, h : null}; | |
22 } | |
23 function sb(x,y) { | |
24 var z = y(x.v); | |
25 var s = {v : z.v, h : null}; | |
26 | |
27 function reZ() { | |
28 z.h = cons(function() { s.v = z.v; callAll(s.h); }, z.h); | |
29 } | |
30 | |
31 x.h = cons(function() { z = y(x.v); reZ(); s.v = z.v; callAll(s.h); }, x.h); | |
32 reZ(); | |
33 | |
34 return s; | |
35 } | |
12 | 36 |
13 function dyn(s) { | 37 function dyn(s) { |
14 var x = document.createElement("span"); | 38 var x = document.createElement("span"); |
15 x.innerHTML = s.v; | 39 x.innerHTML = s.v; |
16 document.body.appendChild(x); | 40 document.body.appendChild(x); |
17 s.h = { n : s.h, v : function() { x.innerHTML = s.v } }; | 41 s.h = cons(function() { x.innerHTML = s.v }, s.h); |
18 } | 42 } |