Skip to content

Commit 404caec

Browse files
committed
bam cleaned up ts stuff
1 parent 8e7bc98 commit 404caec

5 files changed

Lines changed: 59 additions & 34 deletions

File tree

‎v5-unity/js/opt-frontend-common.ts‎

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,31 @@ declare var diff_match_patch: any;
1919
declare var codeopticonUsername: string; // FIX later when porting Codeopticon
2020
declare var codeopticonSession: string; // FIX later when porting Codeopticon
2121

22+
// augment existing interface definitions from typings/
23+
interface JQuery {
24+
// attr can also take a boolean as a second argument
25+
attr(attributeName: string, b: boolean): JQuery;
26+
}
27+
28+
interface JQueryStatic {
29+
doTimeout: any;
30+
}
31+
32+
declare namespace AceAjax {
33+
interface IEditSession {
34+
setFoldStyle: any;
35+
setOption: any;
36+
gutterRenderer: any;
37+
}
38+
39+
interface Editor {
40+
setHighlightGutterLine: any;
41+
setDisplayIndentGuides: any;
42+
on: any;
43+
}
44+
}
45+
46+
2247
var originFrontendJsFile: string = undefined;
2348

2449
// backend scripts to execute (Python 2 and 3 variants, if available)
@@ -167,14 +192,14 @@ function initDeltaObj() {
167192
startTime: new Date().getTime()};
168193
}
169194

170-
function initAceEditor(height) {
195+
var initAceEditor = function(height) {
171196
pyInputAceEditor = ace.edit('codeInputPane');
172197
var s = pyInputAceEditor.getSession();
173198
// tab -> 4 spaces
174199
s.setTabSize(4);
175200
s.setUseSoftTabs(true);
176201
// disable extraneous indicators:
177-
(s as any /* TS too strict */).setFoldStyle('manual'); // no code folding indicators
202+
s.setFoldStyle('manual'); // no code folding indicators
178203
s.getDocument().setNewLineMode('unix'); // canonicalize all newlines to unix format
179204
pyInputAceEditor.setHighlightActiveLine(false);
180205
pyInputAceEditor.setShowPrintMargin(false);
@@ -189,7 +214,7 @@ function initAceEditor(height) {
189214

190215
initDeltaObj();
191216
pyInputAceEditor.on('change', function(e) {
192-
($ as any /* TS too strict */).doTimeout('pyInputAceEditorChange', CODE_SNAPSHOT_DEBOUNCE_MS, snapshotCodeDiff); // debounce
217+
$.doTimeout('pyInputAceEditorChange', CODE_SNAPSHOT_DEBOUNCE_MS, snapshotCodeDiff); // debounce
193218
clearFrontendError();
194219
s.clearAnnotations();
195220
});
@@ -485,7 +510,7 @@ function initTogetherJS() {
485510
if (appMode == 'edit' && msg.codeInputScrollTop !== undefined &&
486511
pyInputGetScrollTop() != msg.codeInputScrollTop) {
487512
// hack: give it a bit of time to settle first ...
488-
($ as any /* TS too strict */).doTimeout('pyInputCodeMirrorInit', 200, function() {
513+
$.doTimeout('pyInputCodeMirrorInit', 200, function() {
489514
pyInputSetScrollTop(msg.codeInputScrollTop);
490515
});
491516
}
@@ -498,7 +523,7 @@ function initTogetherJS() {
498523
$("#codeInputWarnings").hide();
499524
$("#someoneIsTypingDiv").show();
500525

501-
($ as any /* TS too strict */).doTimeout('codeMirrorWarningTimeout', 1000, function() { // debounce
526+
$.doTimeout('codeMirrorWarningTimeout', 1000, function() { // debounce
502527
$("#codeInputWarnings").show();
503528
$("#someoneIsTypingDiv").hide();
504529
});
@@ -570,7 +595,7 @@ function initTogetherJS() {
570595
// give pyInputAceEditor a bit of time to settle with
571596
// its new value. this is hacky; ideally we have a callback function for
572597
// when setValue() completes.
573-
($ as any /* TS too strict */).doTimeout('pyInputCodeMirrorInit', 200, function() {
598+
$.doTimeout('pyInputCodeMirrorInit', 200, function() {
574599
pyInputSetScrollTop(msg.codeInputScrollTop);
575600
});
576601
}
@@ -646,11 +671,11 @@ function initTogetherJS() {
646671
});
647672
}
648673

649-
function TogetherjsReadyHandler() {
674+
var TogetherjsReadyHandler = function() {
650675
alert("ERROR: need to override TogetherjsReadyHandler()");
651676
}
652677

653-
function TogetherjsCloseHandler() {
678+
var TogetherjsCloseHandler = function() {
654679
alert("ERROR: need to override TogetherjsCloseHandler()");
655680
}
656681

@@ -706,7 +731,7 @@ function populateTogetherJsShareUrl() {
706731
707732
$("#sharedSessionWhatLearned").val('');
708733
$("#sharedSessionWhatLearnedThanks").show();
709-
($ as any).doTimeout('sharedSessionWhatLearnedThanksFadeOut', 1000, function() {
734+
$.doTimeout('sharedSessionWhatLearnedThanksFadeOut', 1000, function() {
710735
$("#sharedSessionWhatLearnedThanks").fadeOut(2000);
711736
});
712737
}
@@ -851,7 +876,7 @@ function genericOptFrontendReady(params) {
851876
/*
852877
pyInputAceEditor.getSession().on('changeScrollTop', function() {
853878
if (typeof TogetherJS !== 'undefined' && TogetherJS.running) {
854-
($ as any).doTimeout('codeInputScroll', 100, function() { // debounce
879+
$.doTimeout('codeInputScroll', 100, function() { // debounce
855880
// note that this will send a signal back and forth both ways
856881
// (there's no easy way to prevent this), but it shouldn't keep
857882
// bouncing back and forth indefinitely since no the second signal
@@ -977,7 +1002,7 @@ function genericOptFrontendReady(params) {
9771002
clearFrontendError();
9781003

9791004
$("#embedLinkDiv").hide();
980-
$("#executeBtn").attr('disabled', (false as any /* TS too strict */));
1005+
$("#executeBtn").attr('disabled', false);
9811006
$("#executeBtn").click(executeCodeFromScratch);
9821007

9831008
// for Versions 1 and 2, initialize here. But for version 3+, dynamically
@@ -1242,13 +1267,13 @@ function updateAppDisplay(newAppMode) {
12421267
pendingCodeOutputScrollTop = null;
12431268
}
12441269

1245-
($ as any /* TS too strict */).doTimeout('pyCodeOutputDivScroll'); // cancel any prior scheduled calls
1270+
$.doTimeout('pyCodeOutputDivScroll'); // cancel any prior scheduled calls
12461271

12471272
// TODO: this might interfere with experimentalPopUpSyntaxErrorSurvey (2015-04-19)
12481273
myVisualizer.domRoot.find('#pyCodeOutputDiv').scroll(function(e) {
12491274
var elt = $(this);
12501275
// debounce
1251-
($ as any /* TS too strict */).doTimeout('pyCodeOutputDivScroll', 100, function() {
1276+
$.doTimeout('pyCodeOutputDivScroll', 100, function() {
12521277
// note that this will send a signal back and forth both ways
12531278
if (typeof TogetherJS !== 'undefined' && TogetherJS.running) {
12541279
// (there's no easy way to prevent this), but it shouldn't keep
@@ -1319,13 +1344,13 @@ function handleUncaughtExceptionFunc(trace) {
13191344

13201345
function startExecutingCode() {
13211346
$('#executeBtn').html("Please wait ... executing (takes up to 10 seconds)");
1322-
$('#executeBtn').attr('disabled', (true as any /* TS too strict */));
1347+
$('#executeBtn').attr('disabled', true);
13231348
isExecutingCode = true; // nasty global
13241349
}
13251350

13261351
function doneExecutingCode() {
13271352
$('#executeBtn').html("Visualize Execution");
1328-
$('#executeBtn').attr('disabled', (false as any /* TS too strict */));
1353+
$('#executeBtn').attr('disabled', false);
13291354
isExecutingCode = false; // nasty global
13301355
}
13311356

@@ -1421,7 +1446,7 @@ function executeCodeAndCreateViz(codeToExec,
14211446
}
14221447

14231448
// debounce to compress a bit ... 250ms feels "right"
1424-
($ as any /* TS too strict */).doTimeout('updateOutputLogEvent', 250, function() {
1449+
$.doTimeout('updateOutputLogEvent', 250, function() {
14251450
var obj: any = {type: 'updateOutput', step: args.myViz.curInstr,
14261451
curline: args.myViz.curLineNumber,
14271452
prevline: args.myViz.prevLineNumber};
@@ -2010,7 +2035,7 @@ display a brief "Thanks!" note]
20102035
20112036
$("#iJustLearnedInput").val('');
20122037
$("#iJustLearnedThanks").show();
2013-
($ as any).doTimeout('iJustLearnedThanksFadeOut', 1200, function() {
2038+
$.doTimeout('iJustLearnedThanksFadeOut', 1200, function() {
20142039
$("#iJustLearnedThanks").fadeOut(1000);
20152040
});
20162041
});
@@ -2161,7 +2186,7 @@ display a brief "Thanks!" note]
21612186
21622187
$("#iJustLearnedInput").val('');
21632188
$("#iJustLearnedThanks").show();
2164-
($ as any).doTimeout('iJustLearnedThanksFadeOut', 1200, function() {
2189+
$.doTimeout('iJustLearnedThanksFadeOut', 1200, function() {
21652190
$("#iJustLearnedThanks").fadeOut(1000);
21662191
});
21672192
@@ -2185,6 +2210,7 @@ function logEventCodeopticon(obj) {}
21852210
// only export methods and NOT objects, since they're copied by value
21862211
// (unless they're constants, in which case they can be exported at the
21872212
// end after they've been initialized)
2213+
declare var module: any;
21882214
module.exports = {
21892215
setSurveyHTML: setSurveyHTML,
21902216
genericOptFrontendReady: genericOptFrontendReady,

‎v5-unity/js/opt-frontend.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ function experimentalPopUpSyntaxErrorSurvey() {
355355
s.setTabSize(4);
356356
s.setUseSoftTabs(true);
357357
// disable extraneous indicators:
358-
(s as any /* TS too strict */).setFoldStyle('manual'); // no code folding indicators
358+
s.setFoldStyle('manual'); // no code folding indicators
359359
s.getDocument().setNewLineMode('unix'); // canonicalize all newlines to unix format
360360
bubbleAceEditor.setHighlightActiveLine(false);
361361
bubbleAceEditor.setShowPrintMargin(false);
@@ -368,7 +368,7 @@ function experimentalPopUpSyntaxErrorSurvey() {
368368

369369
// don't do real-time syntax checks:
370370
// https://github.com/ajaxorg/ace/wiki/Syntax-validation
371-
(s as any /* TS too strict*/).setOption("useWorker", false);
371+
s.setOption("useWorker", false);
372372

373373
var lang = prevExecutionExceptionObj.myAppState.py;
374374
var mod = 'python';

‎v5-unity/js/opt-live.ts‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ function optliveFinishSuccessfulExecution() {
256256
$(".ui-widget-content").css('font-size', '0.9em');
257257

258258
// unbind first to prevent multiple bindings
259-
sliderDiv.unbind('slide').bind('slide', function(evt, ui) {
259+
(sliderDiv as any /* TS too strict*/).unbind('slide').bind('slide', function(evt, ui) {
260260
// this is SUPER subtle. if this value was changed programmatically,
261261
// then evt.originalEvent will be undefined. however, if this value
262262
// was changed by a user-initiated event, then this code should be
@@ -375,14 +375,14 @@ function initAceEditor(height) {
375375
var s = pyInputAceEditor.getSession();
376376

377377
// disable extraneous indicators:
378-
(s as any /* TS too strict */).setFoldStyle('manual'); // no code folding indicators
378+
s.setFoldStyle('manual'); // no code folding indicators
379379
s.getDocument().setNewLineMode('unix'); // canonicalize all newlines to unix format
380380
pyInputAceEditor.setHighlightActiveLine(false);
381381
pyInputAceEditor.setShowPrintMargin(false);
382382
pyInputAceEditor.setBehavioursEnabled(false);
383383

384-
(pyInputAceEditor as any /* TS too strict */).setHighlightGutterLine(false); // to avoid gray highlight over gutter of active line
385-
(pyInputAceEditor as any /* TS too strict */).setDisplayIndentGuides(false); // to avoid annoying gray vertical lines
384+
pyInputAceEditor.setHighlightGutterLine(false); // to avoid gray highlight over gutter of active line
385+
pyInputAceEditor.setDisplayIndentGuides(false); // to avoid annoying gray vertical lines
386386

387387
pyInputAceEditor.$blockScrolling = Infinity; // kludgy to shut up weird warnings
388388

@@ -404,8 +404,8 @@ function initAceEditor(height) {
404404
}
405405
});
406406

407-
(pyInputAceEditor as any /* TS too strict*/).on('change', function(e) {
408-
($ as any /* TS too strict */).doTimeout('pyInputAceEditorChange',
407+
pyInputAceEditor.on('change', function(e) {
408+
$.doTimeout('pyInputAceEditorChange',
409409
500, /* go a bit faster than CODE_SNAPSHOT_DEBOUNCE_MS to feel more snappy */
410410
//CODE_SNAPSHOT_DEBOUNCE_MS /* match the value in opt-frontend-common.js for consistency and easy apples-to-apples comparisons later on */,
411411
optliveExecuteCodeFromScratch); // debounce
@@ -415,12 +415,12 @@ function initAceEditor(height) {
415415

416416
// don't do real-time syntax checks:
417417
// https://github.com/ajaxorg/ace/wiki/Syntax-validation
418-
(s as any /* TS too strict */).setOption("useWorker", false);
418+
s.setOption("useWorker", false);
419419
pyInputAceEditor.focus();
420420

421421
// custom gutter renderer, make it wider to accomodate arrows on left
422422
// http://stackoverflow.com/a/28404331
423-
(s as any /* TS too strict*/).gutterRenderer = {
423+
s.gutterRenderer = {
424424
getWidth: function(session, lastLineNumber, config) {
425425
return (lastLineNumber.toString().length * config.characterWidth) + 6;
426426
},

‎v5-unity/js/opt-testcases.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@ function getCombinedCode(id) {
6868
}
6969

7070
function startRunningTest(id) {
71-
$("#runAllTestsButton,.runTestCase,.vizTestCase").attr('disabled', (true as any) /* TS too strict */);
71+
$("#runAllTestsButton,.runTestCase,.vizTestCase").attr('disabled', true);
7272
var e = ace.edit('testCaseEditor_' + id);
7373
e.getSession().clearAnnotations();
7474
$('#outputTd_' + id).html('');
7575
}
7676

7777
function doneRunningTest() {
78-
$("#runAllTestsButton,.runTestCase,.vizTestCase").attr('disabled', (false as any) /* TS too strict */);
78+
$("#runAllTestsButton,.runTestCase,.vizTestCase").attr('disabled', false);
7979
$(".runTestCase").html('Run');
8080
$(".vizTestCase").html('Visualize');
8181
}
@@ -133,10 +133,10 @@ function addTestcase(initialCod /* optional code to pre-seed this test */,
133133
s.setTabSize(2);
134134
s.setUseSoftTabs(true);
135135
// disable extraneous indicators:
136-
(s as any /* TS too strict */).setFoldStyle('manual'); // no code folding indicators
136+
s.setFoldStyle('manual'); // no code folding indicators
137137
// don't do real-time syntax checks:
138138
// https://github.com/ajaxorg/ace/wiki/Syntax-validation
139-
(s as any /* TS too strict */).setOption("useWorker", false);
139+
s.setOption("useWorker", false);
140140

141141
// TODO: change syntax highlighting mode if the user changes languages:
142142
var lang = $('#pythonVersionSelector').val();

‎v5-unity/js/pytutor.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4066,8 +4066,7 @@ function htmlsanitize(str) {
40664066
}
40674067

40684068

4069-
// silence TS typechecker here:
4070-
(String.prototype as any).rtrim = function() {
4069+
(String.prototype as any /* TS too strict */).rtrim = function() {
40714070
return this.replace(/\s*$/g, "");
40724071
}
40734072

0 commit comments

Comments
 (0)