trying to get it to work
This commit is contained in:
parent
ecb62a63e8
commit
2e44e1cfdb
|
@ -6,9 +6,10 @@
|
|||
MACHINE.modules['whalesong/web-world/impl.rkt'].privateExports;
|
||||
var EventSource = WebWorld.EventSource;
|
||||
var EventHandler = WebWorld.EventHandler;
|
||||
var wrapFunction = WebWorld.wrapFunction;
|
||||
|
||||
var makeClosure = plt.baselib.functions.makeClosure;
|
||||
var makePrimitive = plt.baselib.functions.makePrimitive;
|
||||
var makePrimitiveProcedure = plt.baselib.functions.makePrimitiveProcedure;
|
||||
var finalizeClosureCall = plt.runtime.finalizeClosureCall;
|
||||
|
||||
var checkProcedure = plt.baselib.check.checkProcedure;
|
||||
|
@ -34,11 +35,9 @@
|
|||
fireEvent = void(0);
|
||||
};
|
||||
|
||||
var sender = function() {
|
||||
var sender = function(v) {
|
||||
if (enabled) {
|
||||
var args = Array.prototype.slice.call(arguments, 0);
|
||||
args.unshift(void(0));
|
||||
fireEvent.apply(null, args);
|
||||
fireEvent(void(0), v);
|
||||
}
|
||||
};
|
||||
return { eventSource: new JsEventSource(),
|
||||
|
@ -52,16 +51,17 @@
|
|||
function(M) {
|
||||
var eventSourceRecord = makeJsEventSource();
|
||||
eventSourceRecord.eventSource
|
||||
var makeHandler = makePrimitive('make-js-world-event',
|
||||
1,
|
||||
function(M) {
|
||||
var onEvent = checkProcedure(M, 'js-world-event-handler', 0);
|
||||
return new EventHandler('js-world-event',
|
||||
eventSourceRecord.eventSource,
|
||||
onEvent);
|
||||
});
|
||||
var makeHandler = makePrimitiveProcedure(
|
||||
'make-js-world-event',
|
||||
1,
|
||||
function(M) {
|
||||
var onEvent = wrapFunction(checkProcedure(M, 'js-world-event-handler', 0));
|
||||
return new EventHandler('js-world-event',
|
||||
eventSourceRecord.eventSource,
|
||||
onEvent);
|
||||
});
|
||||
finalizeClosureCall(M,
|
||||
"first value",
|
||||
makeHandler,
|
||||
eventSourceRecord.sender);
|
||||
});
|
||||
|
||||
|
|
|
@ -1,21 +1,29 @@
|
|||
#lang planet dyoo/whalesong
|
||||
(require (planet dyoo/whalesong/js/world)
|
||||
(planet dyoo/whalesong/js))
|
||||
(planet dyoo/whalesong/js)
|
||||
(planet dyoo/whalesong/web-world))
|
||||
|
||||
;; Test of getting world events from arbitrary JavaScript function application.
|
||||
|
||||
;; We first define a new event handler type, by using make-js-world-event:
|
||||
(define-values (on-event send-event)
|
||||
(make-js-world-event))
|
||||
|
||||
((js-function (js-eval "function(x) { window.sendTheTick = x; }"))
|
||||
send-event)
|
||||
;; It gives us two values back:
|
||||
;; 1. An event handler that can be passed to big-bang
|
||||
;; 2. A raw JavaScript function that can fire events
|
||||
|
||||
|
||||
on-event
|
||||
send-event
|
||||
(void ((js-function (js-eval "function(x) { window.sendTheTick = x; }"))
|
||||
send-event))
|
||||
|
||||
|
||||
(define (handle-event w v)
|
||||
(define (handle-event w v e f g)
|
||||
(displayln e)
|
||||
(displayln f)
|
||||
(displayln g)
|
||||
(add1 w))
|
||||
|
||||
;(big-bang 0
|
||||
; (on-event handle-event)
|
||||
; (stop-when (lambda (w) (> w 5))))
|
||||
(big-bang 0
|
||||
(on-event handle-event)
|
||||
(stop-when (lambda (w v) (> w 5))))
|
||||
|
|
|
@ -2204,5 +2204,6 @@
|
|||
// For private importers of the web-world library, like the FFI's js/world library.
|
||||
EXPORTS['EventSource'] = EventSource;
|
||||
EXPORTS['EventHandler'] = EventHandler;
|
||||
EXPORTS['wrapFunction'] = wrapFunction;
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
}());
|
Loading…
Reference in New Issue
Block a user