trying to figure out where the infinite loop is coming from in forward-backward movement
This commit is contained in:
parent
21c73b77c3
commit
38cb67a63c
|
@ -51,3 +51,5 @@ false
|
|||
"remove"
|
||||
(html (head) (body "some text"))
|
||||
"some text"
|
||||
|
||||
"forward and backward"
|
||||
|
|
|
@ -248,4 +248,8 @@
|
|||
(type "text")
|
||||
(value "this is a message")))
|
||||
"some text"))))
|
||||
"my-field")))
|
||||
"my-field")))
|
||||
|
||||
|
||||
(newline)
|
||||
"forward and backward"
|
||||
|
|
48
web-world/examples/forward-backward/forward-backward.rkt
Normal file
48
web-world/examples/forward-backward/forward-backward.rkt
Normal file
|
@ -0,0 +1,48 @@
|
|||
#lang planet dyoo/whalesong
|
||||
|
||||
(require (planet dyoo/whalesong/resource)
|
||||
(planet dyoo/whalesong/web-world))
|
||||
|
||||
(define-resource index.html)
|
||||
|
||||
(define (go-forward world dom)
|
||||
(add1 world))
|
||||
|
||||
(define (go-backward world dom)
|
||||
(max (sub1 world) 0))
|
||||
|
||||
|
||||
(define (clear-all a-view)
|
||||
(define updated-view (update-view-css a-view "border" "none"))
|
||||
(cond
|
||||
[(view-forward? updated-view)
|
||||
(clear-all (view-forward updated-view))]
|
||||
[else
|
||||
updated-view]))
|
||||
|
||||
(define (iterate n f x)
|
||||
(if (= n 0)
|
||||
x
|
||||
(iterate (sub1 n ) f (f x))))
|
||||
|
||||
(define (draw world dom)
|
||||
(update-view-css (iterate world
|
||||
view-forward
|
||||
(clear-all dom))
|
||||
"border"
|
||||
"1px solid blue"))
|
||||
|
||||
(define my-initial-view (view-bind
|
||||
(view-focus
|
||||
(view-bind
|
||||
(view-focus (->view index.html)
|
||||
"forward")
|
||||
"click"
|
||||
go-forward)
|
||||
"backward")
|
||||
"click"
|
||||
go-backward))
|
||||
|
||||
(big-bang 0
|
||||
(initial-view my-initial-view)
|
||||
(to-draw draw))
|
26
web-world/examples/forward-backward/index.html
Normal file
26
web-world/examples/forward-backward/index.html
Normal file
|
@ -0,0 +1,26 @@
|
|||
<html>
|
||||
<head><title>Test</title></head>
|
||||
<body>
|
||||
<h1>This is a test</h1>
|
||||
<input type="button" id="forward" value="Forward">
|
||||
<input type="button" id="backward" value="Backward">
|
||||
|
||||
|
||||
<table>
|
||||
<tr><td>First Row</td></tr>
|
||||
<tr><td>Middle Row</td></tr>
|
||||
<tr><td>Last Row</td></tr>
|
||||
</table>
|
||||
<ul>
|
||||
<li>Item one</li>
|
||||
<li>Item two</li>
|
||||
<li>
|
||||
<ul>
|
||||
<li>Nested item one</li>
|
||||
<li>Nested item two</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user