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