jslinting before going forward

This commit is contained in:
Danny Yoo 2011-08-23 13:21:39 -04:00
parent 693bec328d
commit a29188582f
3 changed files with 329 additions and 238 deletions

View File

@ -9,4 +9,3 @@
#:transparent)
(define-predicate AtomicArity? AtomicArity)
(define-predicate listof-atomic-arity? (Listof AtomicArity))

View File

@ -1,3 +1,9 @@
/*jslint browser: true, unparam: true, vars: true, white: true, plusplus: true, maxerr: 50, indent: 4 */
/*global plt,MACHINE,$,EXPORTS*/
(function() {
"use strict";
var makePrimitiveProcedure = plt.baselib.functions.makePrimitiveProcedure;
var makeClosure = plt.baselib.functions.makeClosure;
var finalizeClosureCall = plt.baselib.functions.finalizeClosureCall;
@ -18,10 +24,11 @@ var View = function(top, focused, eventHandlers, pendingActions) {
this.eventHandlers = eventHandlers;
this.pendingActions = pendingActions;
};
View.prototype.toString = function() { return "#<View>"; }
View.prototype.toString = function() { return "#<View>"; };
View.prototype.updateFocused = function(focused) {
return new View(this.top, focused, eventHandlers, pendingActions);
return new View(this.top, focused, this.eventHandlers, this.pendingActions);
};
View.prototype.initialRender = function(top) {
@ -36,24 +43,25 @@ var isView = plt.baselib.makeClassPredicate(View);
var isResource = resourceStructType.predicate;
var resourcePath = function(r) { return resourceStructType.accessor(r, 0); };
var resourceKey = function(r) { return resourceStructType.accessor(r, 1); };
// var resourcePath = function(r) { return resourceStructType.accessor(r, 0); };
// var resourceKey = function(r) { return resourceStructType.accessor(r, 1); };
var resourceContent = function(r) { return resourceStructType.accessor(r, 2); };
var checkResource = plt.baselib.check.makeCheckArgumentType(
isResource, 'resource');
var checkProcedure = plt.baselib.check.checkProcedure;
// var checkResource = plt.baselib.check.makeCheckArgumentType(
// isResource, 'resource');
var checkResourceOrView = plt.baselib.check.makeCheckArgumentType(
function(x) { return isView(x) || isResource(x); },
'resource or view');
var checkView = plt.baselib.check.makeCheckArgumentType(
isView, 'view');
// var checkView = plt.baselib.check.makeCheckArgumentType(
// isView, 'view');
// coerseToView: (U resource View) -> View
var coerseToView = function(x, onSuccess, onFail) {
var dom, v;
var dom;
if (isView(x)) {
return onSuccess(x);
} else if (isResource(x)) {
@ -100,7 +108,7 @@ var StopWhenHandler = function(args, stopWhen) {
StopWhenHandler.prototype = plt.baselib.heir(WorldHandler.prototype);
StopWhenHandler.prototype.toString = function() { return "#<stop-when>"; };
var isStopWhenHandler = plt.baselib.makeClassPredicate(StopWhenHandler);
// var isStopWhenHandler = plt.baselib.makeClassPredicate(StopWhenHandler);
@ -114,7 +122,8 @@ var OnTickHandler = function(args, onTick, delay) {
OnTickHandler.prototype = plt.baselib.heir(WorldHandler.prototype);
OnTickHandler.prototype.toString = function() { return "#<on-tick>"; };
var isOnTickHandler = plt.baselib.makeClassPredicate(OnTickHandler);
// var isOnTickHandler = plt.baselib.makeClassPredicate(OnTickHandler);
@ -145,6 +154,89 @@ var findHandler = function(MACHINE, pred) {
/* Event sources.
An event source are the inputs to a web world program.
Pause and Unpause are semantically meant to be cheaper than start, stop, so
that's why they're a part of this API.
*/
var EventSource = function() {};
EventSource.prototype.onStart = function(fireEvent) {
};
// The default behavior of pause is to cause the event source to stop.
EventSource.prototype.onPause = function() {
this.onStop();
};
// The default behavior of unpause is to start an event source up again.
EventSource.prototype.onUnpause = function(fireEvent) {
this.onStart(fireEvent);
};
EventSource.prototype.onStop = function() {
};
var TickEventSource = function(delay) {
this.delay = delay;
this.id = undefined;
// either undefined, or an integer representing the
// id to cancel a timeout.
};
TickEventSource.prototype = plt.baselib.heir(EventSource.prototype);
TickEventSource.prototype.onStart = function(fireEvent) {
this.id = setInterval(
function() {
fireEvent();
},
this.delay);
};
TickEventSource.prototype.onStop = function() {
if (this.id !== undefined) {
clearInterval(this.id);
this.id = undefined;
}
};
var BindEventSource = function(type, element) {
this.type = type;
this.element = element;
this.handler = undefined;
};
BindEventSource.prototype = plt.baselib.heir(EventSource.prototype);
BindEventSource.prototype.onStart = function(fireEvent) {
this.handler =
function(evt) {
fireEvent(evt);
};
$(this.element).bind(this.type,
this.handler);
};
BindEventSource.prototype.onStop = function() {
if (this.handler !== undefined) {
$(this.element).unbind(this.type, this.handler);
this.handler = undefined;
}
};
//////////////////////////////////////////////////////////////////////
@ -152,8 +244,8 @@ EXPORTS['big-bang'] = makeClosure(
'big-bang',
plt.baselib.arity.makeArityAtLeast(1),
function(MACHINE) {
var oldArgcount = MACHINE.argcount;
var world = MACHINE.env[MACHINE.env.length - 1];
//var oldArgcount = MACHINE.argcount;
//var world = MACHINE.env[MACHINE.env.length - 1];
var initialViewHandler = findHandler(MACHINE, isInitialViewHandler);
var top = $("<div/>");
MACHINE.params.currentDisplayer(MACHINE, top);
@ -165,12 +257,12 @@ EXPORTS['big-bang'] = makeClosure(
// Initialize event handlers to send to that channel.
var onRestart = function() {
restart(function(MACHINE) {
MACHINE.argcount = oldArgcount;
finalizeClosureCall(MACHINE, "ok");
});
};
// var onRestart = function() {
// restart(function(MACHINE) {
// MACHINE.argcount = oldArgcount;
// finalizeClosureCall(MACHINE, "ok");
// });
// };
});
});
@ -179,12 +271,13 @@ EXPORTS['initial-view'] = makeClosure(
'initial-view',
1,
function(MACHINE) {
var resourceOrView = checkResourceOrView(MACHINE, 'initial-view', 0);;
var resourceOrView = checkResourceOrView(MACHINE, 'initial-view', 0);
var oldArgcount = MACHINE.argcount;
PAUSE(function(restart) {
coerseToView(resourceOrView,
function(v) {
restart(function(MACHINE) {
MACHINE.argcount = oldArgcount;
finalizeClosureCall(MACHINE,
new InitialViewHandler(
{
@ -224,21 +317,20 @@ EXPORTS['stop-when'] = makePrimitiveProcedure(
return new StopWhenHandler(
{
onStart : function(MACHINE, onEvent, k) {
k()
k();
},
onPause : function(MACHINE, data, k) {
k(data)
k(data);
},
onResume : function(MACHINE, data, k) {
k(data)
k(data);
},
onStop : function(MACHINE, data, k) {
k()
k();
}
},
stopWhen
);
return undefined;
});
@ -257,21 +349,20 @@ EXPORTS['on-tick'] = makePrimitiveProcedure(
},
onPause : function(MACHINE, data, k) {
clearInterval(data.id);
k(data)
k(data);
},
onResume : function(MACHINE, data, k) {
data.id = setInterval(function () { data.onEvent() },
data.id = setInterval(function () { data.onEvent(); },
this.delay);
k(data)
k(data);
},
onStop : function(MACHINE, data, k) {
clearInterval(data.id);
k()
k();
}
},
onTick
);
return undefined;
});
@ -280,3 +371,4 @@ EXPORTS['on-tick'] = makePrimitiveProcedure(
//////////////////////////////////////////////////////////////////////
}());

View File

@ -1,6 +1,6 @@
#lang racket/base
(provide big-bang initial-view stop-when)
(provide big-bang initial-view stop-when on-tick)
(define (big-bang world . handlers)
(error 'big-bang "Please run in JavaScript context."))