diff --git a/web-world/dwarves/dwarves.rkt b/web-world/dwarves/dwarves.rkt
deleted file mode 100644
index deb3459..0000000
--- a/web-world/dwarves/dwarves.rkt
+++ /dev/null
@@ -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))
diff --git a/web-world/dwarves/index.html b/web-world/dwarves/index.html
deleted file mode 100644
index 95cc8ac..0000000
--- a/web-world/dwarves/index.html
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
Dwarves
-
- Dwarfs from Snow White
-
-
-
diff --git a/web-world/examples/dwarves/dwarves.rkt b/web-world/examples/dwarves/dwarves.rkt
new file mode 100644
index 0000000..29675c9
--- /dev/null
+++ b/web-world/examples/dwarves/dwarves.rkt
@@ -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))
diff --git a/web-world/examples/dwarves/index.html b/web-world/examples/dwarves/index.html
new file mode 100644
index 0000000..71e62c4
--- /dev/null
+++ b/web-world/examples/dwarves/index.html
@@ -0,0 +1,16 @@
+
+ Dwarves
+
+ Dwarfs from Snow White
+ Click on a dwarf to make them hide.
+
+ - Doc
+ - Grumpy
+ - Happy
+ - Sleepy
+ - Bashful
+ - Sneezy
+ - Dopey
+
+
+
diff --git a/web-world/impl.rkt b/web-world/impl.rkt
index af69961..ee2634a 100644
--- a/web-world/impl.rkt
+++ b/web-world/impl.rkt
@@ -43,6 +43,8 @@
view-attr
update-view-attr
+ view-id
+
view-form-value
update-view-form-value
view-append-child
diff --git a/web-world/js-impl.js b/web-world/js-impl.js
index 444819d..4cb5796 100644
--- a/web-world/js-impl.js
+++ b/web-world/js-impl.js
@@ -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();
+ });
+
diff --git a/web-world/racket-impl.rkt b/web-world/racket-impl.rkt
index e31f88d..64593c2 100644
--- a/web-world/racket-impl.rkt
+++ b/web-world/racket-impl.rkt
@@ -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."))