mirror of
https://github.com/rabbibotton/clog.git
synced 2025-12-06 10:40:45 -08:00
Tutorial 03
This commit is contained in:
parent
a378dff2f7
commit
f897486c81
2 changed files with 72 additions and 0 deletions
33
tutorial/03-tutorial.lisp
Normal file
33
tutorial/03-tutorial.lisp
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
(defpackage #:clog-user
|
||||
(:use #:cl #:clog)
|
||||
(:export start-tutorial))
|
||||
|
||||
(in-package :clog-user)
|
||||
|
||||
(defun on-new-window (body)
|
||||
"On-new-window handler."
|
||||
|
||||
(setf (title (html-document body)) "Tutorial 2")
|
||||
|
||||
(let ((hello-element
|
||||
(create-child body "<h1>Hello World! (click me!)</h1>")))
|
||||
|
||||
(let ((x 0))
|
||||
(set-on-click hello-element
|
||||
(lambda ()
|
||||
(incf x)
|
||||
(dotimes (n x)
|
||||
(create-child body
|
||||
(format nil "<p>Clicked ~A times.</p>" x))
|
||||
(sleep x)))))))
|
||||
|
||||
;; Running this version of the last tutorial and clicking quickly on the (click me!)
|
||||
;; will demonstrate an important aspect of CLOG, events can happen in _parallel_.
|
||||
;; This means that appropriate precautions to thread protect data should be taken
|
||||
;; and that events do not wait for previous event handlers to complete.
|
||||
|
||||
(defun start-tutorial ()
|
||||
"Start turtorial."
|
||||
|
||||
(initialize #'on-new-window)
|
||||
(open-browser))
|
||||
Loading…
Add table
Add a link
Reference in a new issue