forked from rabbibotton/clog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
14-tutorial.lisp
57 lines (54 loc) · 2.29 KB
/
14-tutorial.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
(defpackage #:clog-tut-14
(:use #:cl #:clog)
(:export start-tutorial))
(in-package :clog-tut-14)
;;; HTML 5 local storage are the best way to stort client side data
;;; and in general are a far better than cookies.
(defun on-new-window (body)
(setf (title (html-document body)) "Tutorial 14")
(set-on-click (create-button body :content "Set Local Key")
(lambda (obj)
(declare (ignore obj))
(setf (storage-element (window body) :local "my-local-key")
(get-universal-time))
(reload (location body))))
(set-on-click (create-button body :content "Set Session Key")
(lambda (obj)
(declare (ignore obj))
(setf (storage-element (window body) :session "my-session-key")
(get-universal-time))
(reload (location body))))
(set-on-storage (window body)
(lambda (obj data)
(declare (ignore obj))
(create-div body :content
(format nil "<br>~A : ~A => ~A<br>"
(getf data ':key)
(getf data ':old-value)
(getf data ':value)))))
(create-div body :content (format nil
"<H1>Local Storage vs Session Storage</H1>
<p width=500>
The value of local storage persists in the browser cache even after the browser
is closed. If you reset this page the session storage key will remain the same,
but opening this page in another window or tab will be a new session. If the
new window came from a click from this window, the session keys (on some
browsers are copied first to the new window, if you wish to persist data accross
windows use local storage instead.</p>
<br>
<a href='.' target='_blank'>Another Window = Different Session</a><br>
<br>
<br>
Local Storage key: ~A := ~A<br>
<br>
Session Storage key: ~A := ~A<br>
<br>
Changes made to a local key will fire an event and print below:<br>"
"my-local-key"
(storage-element (window body) :local "my-local-key")
"my-session-key"
(storage-element (window body) :session "my-session-key"))))
(defun start-tutorial ()
"Start turtorial."
(initialize 'on-new-window)
(open-browser))