dom-remove
This commit is contained in:
parent
008b5a5000
commit
6adf007205
56
web-world/examples/dwarves-delete/dwarves-delete.rkt
Normal file
56
web-world/examples/dwarves-delete/dwarves-delete.rkt
Normal file
|
@ -0,0 +1,56 @@
|
|||
#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)
|
||||
(cond [(view-focus? view (format "#~a" name))
|
||||
(define focused (view-focus view (format "#~a" name)))
|
||||
(cond
|
||||
[(member name w)
|
||||
view]
|
||||
[else
|
||||
(view-remove focused)])]
|
||||
[else
|
||||
view]))
|
||||
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-delete/index.html
Normal file
16
web-world/examples/dwarves-delete/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>
|
|
@ -67,8 +67,9 @@
|
|||
|
||||
view-form-value
|
||||
update-view-form-value
|
||||
view-append-child
|
||||
|
||||
view-append-child
|
||||
view-remove
|
||||
|
||||
xexp?
|
||||
xexp->dom
|
||||
|
|
|
@ -332,6 +332,28 @@
|
|||
};
|
||||
|
||||
|
||||
MockView.prototype.remove = function() {
|
||||
return this.act(
|
||||
function(cursor) {
|
||||
return cursor.deleteNode();
|
||||
},
|
||||
function(eventHandlers) {
|
||||
return eventHandlers;
|
||||
},
|
||||
function(view) {
|
||||
var elt = view.focus;
|
||||
if (view.focus.next().length > 0) {
|
||||
view.focus = view.focus.next();
|
||||
} else if (view.focus.prev().length > 0) {
|
||||
view.focus = view.focus.prev();
|
||||
} else {
|
||||
view.focus = view.focus.parent();
|
||||
}
|
||||
elt.remove();
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
MockView.prototype.appendChild = function(domNode) {
|
||||
return this.act(
|
||||
function(cursor) {
|
||||
|
@ -1621,6 +1643,15 @@
|
|||
});
|
||||
|
||||
|
||||
EXPORTS['view-remove'] = makePrimitiveProcedure(
|
||||
'view-remove',
|
||||
1,
|
||||
function(MACHINE) {
|
||||
var view = checkMockView(MACHINE, 'view-remove', 0);
|
||||
return view.remove();
|
||||
});
|
||||
|
||||
|
||||
|
||||
EXPORTS['view-append-child'] = makeClosure(
|
||||
'view-append-child',
|
||||
|
@ -1652,6 +1683,7 @@
|
|||
});
|
||||
|
||||
|
||||
|
||||
EXPORTS['view-id'] = makePrimitiveProcedure(
|
||||
'view-id',
|
||||
1,
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
view-hide
|
||||
view-append-child
|
||||
|
||||
view-remove
|
||||
|
||||
open-output-element
|
||||
|
||||
xexp?
|
||||
|
@ -136,21 +138,25 @@
|
|||
(define (view-bind v type worldF)
|
||||
(error 'view-bind "Please run in JavaScript context."))
|
||||
|
||||
(define (view-form-value)
|
||||
(define (view-form-value view)
|
||||
(error 'view-form-value "Please run in JavaScript context."))
|
||||
|
||||
(define (update-view-form-value val)
|
||||
(define (update-view-form-value view val)
|
||||
(error 'view-form-value "Please run in JavaScript context."))
|
||||
|
||||
|
||||
(define (view-show)
|
||||
(define (view-show view)
|
||||
(error 'view-show "Please run in JavaScript context."))
|
||||
|
||||
(define (view-hide)
|
||||
(define (view-hide view)
|
||||
(error 'view-hide "Please run in JavaScript context."))
|
||||
|
||||
|
||||
(define (view-append-child dom)
|
||||
(define (view-remove view)
|
||||
(error 'view-delete "Please run in JavaScript context."))
|
||||
|
||||
|
||||
(define (view-append-child view dom)
|
||||
(error 'view-append "Please run in JavaScript context."))
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user