PageRenderTime 5ms CodeModel.GetById 2ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/examples/state.lisp

http://github.com/mtravers/wuwei
Lisp | 49 lines | 41 code | 8 blank | 0 comment | 0 complexity | 83d80421ae2839a3f1442e44b16b5508 MD5 | raw file
 1(in-package :wu)
 2
 3(publish-code)
 4
 5(publish :path "/state-demo" 
 6	 :content-type "text/html"
 7	 :function 'state-demo)
 8
 9(def-session-variable *demo-counter* 0)
10
11(defun state-demo (req ent)
12  (with-session (req ent)
13    (with-http-response-and-body (req ent)
14      (html (:head
15	     (javascript-includes "prototype.js" "effects.js" "dragdrop.js")
16	     (css-includes "wuwei.css"))
17	    (:body
18	     (example-header #.(this-pathname))
19	     (:h1 "Two kinds of state demo")
20	     "This counter is maintained in a continuation (so will get reset on a page refresh)"
21	     :br
22	     (let ((i 0))
23	       (html
24		 ((:span :id "i_c") (:princ i))
25		 (nbsp)
26		 (link-to-remote
27		  "Increment"
28		  (ajax-continuation (:keep t) 
29		    (render-update
30		      (:update "i_c" (html (:princ (incf i))))))))
31
32	       (html
33		 :p
34		 "This counter is maintained in a session variable, so will persist across page refreshes and browser restarts.  "
35		 (when *developer-mode*
36		   (html ((:a :href "/session-debug") "See or reset the session state")))
37		 :br
38		 ((:span :id "s_c") (:princ *demo-counter*))
39		 (nbsp)
40		 (link-to-remote
41		  "Increment"
42		  (ajax-continuation (:keep t) 
43		    (render-update
44		      (:update "s_c" (html (:princ (incf *demo-counter*)))))))))
45	     (tracker)
46	     )))))
47
48	   
49