example for bind

This commit is contained in:
Danny Yoo 2011-08-26 22:31:36 -04:00
parent 1dee54a11a
commit c95509cab9
2 changed files with 44 additions and 0 deletions

View 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))

View 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>