From 7fbb36e4b1aa40fad42e519305882ba8a9fa7f35 Mon Sep 17 00:00:00 2001 From: Danny Yoo Date: Mon, 19 Mar 2012 18:22:31 -0400 Subject: [PATCH] trying to write simple binding to google maps --- examples/google-maps/maps.rkt | 44 +++++++++++++++++++++++++++++ js-assembler/runtime-src/runtime.js | 31 +++++++++++--------- 2 files changed, 62 insertions(+), 13 deletions(-) create mode 100644 examples/google-maps/maps.rkt diff --git a/examples/google-maps/maps.rkt b/examples/google-maps/maps.rkt new file mode 100644 index 0000000..b382c08 --- /dev/null +++ b/examples/google-maps/maps.rkt @@ -0,0 +1,44 @@ +#lang planet dyoo/whalesong + +;; A simple binding to Google Maps. + +(require (planet dyoo/whalesong/js)) + + +;; initialize-google-maps-api!: string boolean -> void +;; Dynamically loads the Google Maps API. +(define raw-initialize-google-maps-api! + (js-async-function->procedure + #< string + // Creates a randomly-generated nonce. + var makeRandomNonce = function() { + var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz"; + var LEN = 32; + var result = []; + var i; + for (i = 0; i < LEN; i++) { + result.push(chars.charAt(Math.floor(Math.random() * chars.length))); + } + return result.join(''); + }; + + ////////////////////////////////////////////////////////////////////// // Exclusive Locks. Even though JavaScript is a single-threaded @@ -175,23 +189,11 @@ this.waiters = []; }; - // makeRandomNonce: -> string - // Creates a randomly-generated nonce. - ExclusiveLock.makeRandomNonce = function() { - var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz"; - var LEN = 32; - var result = []; - var i; - for (i = 0; i < LEN; i++) { - result.push(chars.charAt(Math.floor(Math.random() * chars.length))); - } - return result.join(''); - }; ExclusiveLock.prototype.acquire = function(id, onAcquire) { var that = this; if (!id) { - id = ExclusiveLock.makeRandomNonce(); + id = makeRandomNonce(); } this.alreadyReleased = false; @@ -1268,4 +1270,7 @@ exports['checkedCdr'] = checkedCdr; exports['checkedVectorRef'] = checkedVectorRef; exports['checkedVectorSet'] = checkedVectorSet; + + + exports['makeRandomNonce'] = makeRandomNonce; }(this.plt, this.plt.baselib)); \ No newline at end of file