got another thing working

This commit is contained in:
Danny Yoo 2012-03-05 16:03:14 -05:00
parent 002521a21b
commit 15812e1c53
2 changed files with 31 additions and 8 deletions

View File

@ -3,6 +3,13 @@
<head><title>Testing message passing across windows</title> <head><title>Testing message passing across windows</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<style type="text/css">
#another-world {
width: 100%;
height: 50%;
}
</style>
</head> </head>
<body> <body>
<p>This is a world program:</p> <p>This is a world program:</p>
@ -18,10 +25,11 @@
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function() { $(document).ready(function() {
var otherWorld = document.getElementById("another-world").contentWindow; var otherWorld = document.getElementById("another-world").contentWindow;
$("#submit").on("click", function() { var send = function() {
otherWorld.postMessage($("#msg").val(), "*"); otherWorld.postMessage($("#msg").val(), "*");
$("#msg").val(""); $("#msg").val("");
}); };
$("#submit").on("click", send);
}); });
</script> </script>
</body> </body>

View File

@ -19,12 +19,27 @@
send)) send))
;; js-function lifts JavaScript functions to regular function we can call. ;; js-function lifts JavaScript functions to regular function we can call.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (get-message w v msg) ;; With this infrastructure, we can make a world program that responds to window postMessage. For example,
(cons msg w)) ;; 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: ;; Finally, let's use our big bang:
(big-bang '("Initial") (big-bang (make-world 0 '())
(on-message get-message)) ;; Note the on-event here (on-tick tick 1)
(on-message read-message))