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