changeset 648:3c6d535d3d8b

Increment demo
author Adam Chlipala <adamc@hcoop.net>
date Tue, 10 Mar 2009 13:57:09 -0400
parents ae374df5ccbd
children 96ebc6bdb5a0
files demo/increment.ur demo/increment.urp demo/increment.urs demo/prose include/urweb.h
diffstat 5 files changed, 22 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/demo/increment.ur	Tue Mar 10 13:57:09 2009 -0400
@@ -0,0 +1,10 @@
+sequence seq
+
+fun increment () = nextval seq
+
+fun main () =
+    src <- source 0;
+    return <xml><body>
+      <dyn signal={n <- signal src; return <xml>{[n]}</xml>}/>
+      <button value="Update" onclick={n <- increment (); set src n}/>
+    </body></xml>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/demo/increment.urp	Tue Mar 10 13:57:09 2009 -0400
@@ -0,0 +1,4 @@
+database dbname=test
+sql increment.sql
+
+increment
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/demo/increment.urs	Tue Mar 10 13:57:09 2009 -0400
@@ -0,0 +1,1 @@
+val main : unit -> transaction page
--- a/demo/prose	Tue Mar 10 13:46:45 2009 -0400
+++ b/demo/prose	Tue Mar 10 13:57:09 2009 -0400
@@ -205,3 +205,7 @@
 <p>The central data structure is the <tt>rlist</tt>, a list whose individual elements are sources, enabling fine-grained mutation.  Every rlist is either nil or is a cons cell made up of a source for a string data element, another source to serve as a scratchpad for GUI-based edits to the data element, and a final source that stores the remainder of the list.</p>
 
 <p>The main program provides operations to append to a list and to edit the data stored at any cell of the list.  Append is implemented by maintaining a source <tt>head</tt>, which points to the first list element; and a source <tt>tailP</tt>, which points to a <tt>source rlist</tt> where we should place the next appended node.</p>
+
+increment.urp
+
+<p>Here's an example where client-side code needs to run more code on the server.  We maintain a (server-side) SQL sequence.  When the user clicks a button, an AJAX request increments the remote sequence and gets the new value.</p>
--- a/include/urweb.h	Tue Mar 10 13:46:45 2009 -0400
+++ b/include/urweb.h	Tue Mar 10 13:57:09 2009 -0400
@@ -79,9 +79,9 @@
 uw_Basis_bool uw_Basis_unurlifyBool(uw_context, char **);
 uw_Basis_time uw_Basis_unurlifyTime(uw_context, char **);
 
-uw_Basis_string uw_Basis_strcat(uw_context, uw_Basis_string, uw_Basis_string);
-uw_Basis_string uw_Basis_strdup(uw_context, uw_Basis_string);
-uw_Basis_string uw_Basis_maybe_strdup(uw_context, uw_Basis_string);
+uw_Basis_string uw_Basis_strcat(uw_context, const char *, const char *);
+uw_Basis_string uw_Basis_strdup(uw_context, const char *);
+uw_Basis_string uw_Basis_maybe_strdup(uw_context, const char *);
 
 uw_Basis_string uw_Basis_sqlifyInt(uw_context, uw_Basis_int);
 uw_Basis_string uw_Basis_sqlifyFloat(uw_context, uw_Basis_float);