example for bind
This commit is contained in:
parent
1dee54a11a
commit
c95509cab9
32
web-world/examples/field/field.rkt
Normal file
32
web-world/examples/field/field.rkt
Normal file
|
@ -0,0 +1,32 @@
|
|||
#lang planet dyoo/whalesong
|
||||
(require (planet dyoo/whalesong/web-world)
|
||||
(planet dyoo/whalesong/resource))
|
||||
|
||||
(define-resource index.html)
|
||||
(define-resource style.css)
|
||||
|
||||
;; The world is a string which represents the name of the user.
|
||||
|
||||
|
||||
;; on-click: world view -> world
|
||||
;; When the user clicks on the button, grab at the text of the
|
||||
;; text-field.
|
||||
(define (on-click w v)
|
||||
(view-text (view-focus v "#text-field")))
|
||||
|
||||
|
||||
;; on-draw: world view -> view
|
||||
;; Take the view, and replace the template with the world value.
|
||||
(define (on-draw w v)
|
||||
(view-text (view-focus v "#template")
|
||||
w))
|
||||
|
||||
|
||||
(define my-view (view-bind (view-focus (resource->view index.html)
|
||||
"#button")
|
||||
"click"
|
||||
on-click))
|
||||
|
||||
(big-bang "Jane Doe"
|
||||
(initial-view my-view)
|
||||
(to-draw draw))
|
12
web-world/examples/field/index.html
Normal file
12
web-world/examples/field/index.html
Normal file
|
@ -0,0 +1,12 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>My simple program</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<input type="text" id="text-field"/>
|
||||
<input type="button" id="button"/>
|
||||
|
||||
<p>Hello <span id="template">fill-me-in</span>!</p>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user