diff tests/ms.ur @ 1447:17393c5e2b90

Send newly created sources with messages to clients
author Adam Chlipala <adam@chlipala.net>
date Sat, 09 Apr 2011 20:00:52 -0400
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/ms.ur	Sat Apr 09 20:00:52 2011 -0400
@@ -0,0 +1,35 @@
+table ms : {Client : client, Channel : channel xbody}
+
+val hitMe =
+    me <- self;
+    ch <- oneRowE1 (SELECT (ms.Channel)
+                    FROM ms
+                    WHERE ms.Client = {[me]});
+
+    s <- source 0;
+    send ch <xml>
+      <dyn signal={n <- signal s; return <xml>{[n]}</xml>}/>
+      <button value="Inc" onclick={n <- get s; set s (n + 1)}/>
+    </xml>
+
+fun main' () =
+    me <- self;
+    ch <- channel;
+    dml (INSERT INTO ms (Client, Channel) VALUES ({[me]}, {[ch]}));
+
+    s <- source <xml/>;
+
+    return <xml><body onload={let
+                                  fun loop () =
+                                      x <- recv ch;
+                                      set s x;
+                                      loop ()
+                              in
+                                  loop ()
+                              end}>
+      <button value="Another" onclick={rpc hitMe}/>
+      <dyn signal={signal s}/>
+    </body></xml>
+
+fun main () =
+    return <xml><body><form><submit action={main'}/></form></body></xml>