diff --git a/examples/js-get-message-parent.html b/examples/js-get-message-parent.html index 0462c1e..f9bfdca 100644 --- a/examples/js-get-message-parent.html +++ b/examples/js-get-message-parent.html @@ -3,6 +3,13 @@ Testing message passing across windows + +

This is a world program:

@@ -18,10 +25,11 @@ diff --git a/examples/js-get-message.rkt b/examples/js-get-message.rkt index 0fd068e..ffb5633 100644 --- a/examples/js-get-message.rkt +++ b/examples/js-get-message.rkt @@ -19,12 +19,27 @@ send)) ;; js-function lifts JavaScript functions to regular function we can call. +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(define (get-message w v msg) - (cons msg w)) +;; With this infrastructure, we can make a world program that responds to window postMessage. For example, +;; we can present a log of all the messages we receive. + +(define-struct world (time messages)) + +(define (read-message w v msg) + (make-world (world-time w) + (cons (format "at time ~a: ~s" + (world-time w) + msg) + (world-messages w)))) + +(define (tick w v) + (make-world (add1 (world-time w)) + (world-messages w))) ;; Finally, let's use our big bang: -(big-bang '("Initial") - (on-message get-message)) ;; Note the on-event here +(big-bang (make-world 0 '()) + (on-tick tick 1) + (on-message read-message))