dwarves example is running, but does not yet show dynamic html stuff
This commit is contained in:
parent
944ac897cf
commit
28367166fe
|
@ -1,40 +0,0 @@
|
|||
#lang planet dyoo/whalesong
|
||||
(require (planet dyoo/whalesong/web-world)
|
||||
(planet dyoo/whalesong/resource))
|
||||
(define-resource index.html)
|
||||
|
||||
;; make-item: string -> view
|
||||
(define (make-item name)
|
||||
(view-bind (->view `(li ,name))
|
||||
"click"
|
||||
hide-on-click))
|
||||
|
||||
|
||||
;; When a dwarf clicks, it hides!
|
||||
(define (hide-on-click w v)
|
||||
(view-hide v))
|
||||
|
||||
|
||||
(define dwarf-names
|
||||
'("Doc" "Grumpy" "Happy" "Sleepy" "Bashful" "Sneezy" "Dopey"))
|
||||
|
||||
|
||||
;; Update the view so it shows the next dwarf on the scene,
|
||||
;; until we're all done.
|
||||
(define (draw w v)
|
||||
(cond [(< w (length dwarf-names))
|
||||
(view-append-child (view-focus v "#list")
|
||||
(make-item (list-ref dwarf-names w)))]
|
||||
[else
|
||||
v]))
|
||||
|
||||
|
||||
;; tick: world view -> world
|
||||
(define (tick w v)
|
||||
(add1 w))
|
||||
|
||||
|
||||
(big-bang 0
|
||||
(initial-view index.html)
|
||||
(on-tick tick .5)
|
||||
(to-draw draw))
|
|
@ -1,8 +0,0 @@
|
|||
<html>
|
||||
<head><title>Dwarves</title></head>
|
||||
<body>
|
||||
<h1>Dwarfs from Snow White</h1>
|
||||
<ul id="list">
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
53
web-world/examples/dwarves/dwarves.rkt
Normal file
53
web-world/examples/dwarves/dwarves.rkt
Normal file
|
@ -0,0 +1,53 @@
|
|||
#lang planet dyoo/whalesong
|
||||
(require (planet dyoo/whalesong/web-world)
|
||||
(planet dyoo/whalesong/resource))
|
||||
(define-resource index.html)
|
||||
|
||||
;; The world is the set of dwarfs.
|
||||
|
||||
|
||||
;; make-item: string -> view
|
||||
(define (make-item name)
|
||||
(view-bind (->view `(li ,name))
|
||||
"click"
|
||||
hide-on-click))
|
||||
|
||||
|
||||
;; When a dwarf clicks, it hides!
|
||||
(define (hide-on-click w v)
|
||||
(remove (view-id v) w))
|
||||
|
||||
|
||||
(define dwarf-names
|
||||
'("Doc" "Grumpy" "Happy" "Sleepy" "Bashful" "Sneezy" "Dopey"))
|
||||
|
||||
|
||||
;; Update the view so it shows the next dwarf on the scene,
|
||||
;; until we're all done.
|
||||
(define (draw w dom-view)
|
||||
(foldl (lambda (name view)
|
||||
(define focused (view-focus view (format "#~a" name)))
|
||||
(cond
|
||||
[(member name w)
|
||||
(view-show focused)]
|
||||
[else
|
||||
(view-hide focused)]))
|
||||
dom-view
|
||||
dwarf-names))
|
||||
|
||||
|
||||
|
||||
;; The first view consists of index.html. We attach event handlers
|
||||
;; to each name here.
|
||||
(define my-view
|
||||
(foldl (lambda (name view)
|
||||
(view-bind (view-focus view (format "#~a" name))
|
||||
"click"
|
||||
hide-on-click))
|
||||
(->view index.html)
|
||||
dwarf-names))
|
||||
|
||||
|
||||
(big-bang dwarf-names
|
||||
(initial-view my-view)
|
||||
(to-draw draw))
|
16
web-world/examples/dwarves/index.html
Normal file
16
web-world/examples/dwarves/index.html
Normal file
|
@ -0,0 +1,16 @@
|
|||
<html>
|
||||
<head><title>Dwarves</title></head>
|
||||
<body>
|
||||
<h1>Dwarfs from Snow White</h1>
|
||||
<p>Click on a dwarf to make them hide.</p>
|
||||
<ul id="list">
|
||||
<li id="Doc">Doc</li>
|
||||
<li id="Grumpy">Grumpy</li>
|
||||
<li id="Happy">Happy</li>
|
||||
<li id="Sleepy">Sleepy</li>
|
||||
<li id="Bashful">Bashful</li>
|
||||
<li id="Sneezy">Sneezy</li>
|
||||
<li id="Dopey">Dopey</li>
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
|
@ -43,6 +43,8 @@
|
|||
view-attr
|
||||
update-view-attr
|
||||
|
||||
view-id
|
||||
|
||||
view-form-value
|
||||
update-view-form-value
|
||||
view-append-child
|
||||
|
|
|
@ -346,6 +346,11 @@
|
|||
)
|
||||
};
|
||||
|
||||
MockView.prototype.id = function() {
|
||||
return this.cursor.node.id;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -832,8 +837,6 @@
|
|||
mockView = mockView.updateFocus('#' + nextEvent.who.id);
|
||||
}
|
||||
|
||||
console.log('dispatching event', nextEvent);
|
||||
|
||||
// FIXME: deal with event data here
|
||||
racketWorldCallback = nextEvent.handler.racketWorldCallback;
|
||||
racketWorldCallback(MACHINE,
|
||||
|
@ -1214,17 +1217,17 @@
|
|||
'view-show',
|
||||
1,
|
||||
function(MACHINE) {
|
||||
var view = checkMockView(MACHINE, 'show', 0);
|
||||
return view.show(value);
|
||||
var view = checkMockView(MACHINE, 'view-show', 0);
|
||||
return view.show();
|
||||
});
|
||||
|
||||
|
||||
EXPORTS['hide'] = makePrimitiveProcedure(
|
||||
'hide',
|
||||
EXPORTS['view-hide'] = makePrimitiveProcedure(
|
||||
'view-hide',
|
||||
1,
|
||||
function(MACHINE) {
|
||||
var view = checkMockView(MACHINE, 'hide', 0);
|
||||
return view.hide(value);
|
||||
var view = checkMockView(MACHINE, 'view-hide', 0);
|
||||
return view.hide();
|
||||
});
|
||||
|
||||
|
||||
|
@ -1259,6 +1262,14 @@
|
|||
});
|
||||
|
||||
|
||||
EXPORTS['view-id'] = makePrimitiveProcedure(
|
||||
'view-id',
|
||||
1,
|
||||
function(MACHINE) {
|
||||
var view = checkMockView(MACHINE, 'view-hide', 0);
|
||||
return view.id();
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
view-left view-right view-up view-down
|
||||
view-text update-view-text
|
||||
view-attr update-view-attr
|
||||
view-id
|
||||
|
||||
view-bind
|
||||
|
||||
view-form-value
|
||||
|
@ -13,8 +15,7 @@
|
|||
|
||||
view-show
|
||||
view-hide
|
||||
view-append-child
|
||||
)
|
||||
view-append-child)
|
||||
|
||||
|
||||
(define (big-bang world . handlers)
|
||||
|
@ -72,6 +73,10 @@
|
|||
(error 'update-view-attr "Please run in JavaScript context."))
|
||||
|
||||
|
||||
(define (view-id v)
|
||||
(error 'view-id "Please run in JavaScript context."))
|
||||
|
||||
|
||||
(define (view-bind v type worldF)
|
||||
(error 'view-bind "Please run in JavaScript context."))
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user