Skip to content

Commit 3ea9b4f

Browse files
committed
simplified sync code
1 parent e0328d6 commit 3ea9b4f

4 files changed

Lines changed: 34 additions & 41 deletions

File tree

‎v3/js/opt-frontend.js‎

Lines changed: 20 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ var isTutor = false;
8282
// nasty globals
8383
var updateOutputSignalFromRemote = false;
8484
var hashchangeSignalFromRemote = false;
85-
var nowSyncing = false;
8685

8786
// Global hook for ExecutionVisualizer.
8887
var try_hook = function(hook_name, args) {
@@ -92,7 +91,6 @@ var try_hook = function(hook_name, args) {
9291

9392
function requestSync() {
9493
if (TogetherJS.running) {
95-
nowSyncing = true;
9694
TogetherJS.send({type: "requestSync"});
9795
}
9896
}
@@ -114,7 +112,7 @@ function initTogetherJS() {
114112
if (updateOutputSignalFromRemote) {
115113
return;
116114
}
117-
if (TogetherJS.running && !nowSyncing /* don't perterb when syncing */) {
115+
if (TogetherJS.running) {
118116
TogetherJS.send({type: "updateOutput", step: args.myViz.curInstr});
119117
}
120118
}
@@ -126,7 +124,6 @@ function initTogetherJS() {
126124
return;
127125
}
128126
if (myVisualizer) {
129-
console.log("updateOutput:", msg);
130127
// to prevent this call to updateOutput from firing its own TogetherJS event
131128
updateOutputSignalFromRemote = true;
132129
try {
@@ -145,8 +142,10 @@ function initTogetherJS() {
145142
hashchangeSignalFromRemote = true;
146143
try {
147144
console.log("TogetherJS RECEIVE hashchange", msg.appMode);
148-
appMode = msg.appMode; // assign this to the GLOBAL appMode
149-
updateAppDisplay();
145+
if (appMode != msg.appMode) {
146+
appMode = msg.appMode; // assign this to the GLOBAL appMode
147+
updateAppDisplay();
148+
}
150149
}
151150
finally {
152151
hashchangeSignalFromRemote = false;
@@ -175,36 +174,24 @@ function initTogetherJS() {
175174
return;
176175
}
177176

178-
try {
179-
var learnerAppState = msg.myAppState;
180-
181-
if (learnerAppState.mode == 'display' ||
182-
learnerAppState.mode == 'visualize' /* deprecated */) {
183-
if (appStateEq(getAppState(), learnerAppState)) {
184-
// update curInstr only
185-
console.log("on:myAppState - app states equal, renderStep", learnerAppState.curInstr);
186-
myVisualizer.renderStep(learnerAppState.curInstr);
187-
}
188-
else {
189-
console.log("on:myAppState - app states unequal, executing", learnerAppState);
190-
setVisibleAppState(learnerAppState);
191-
// execute code and jump to the learner's curInstr
192-
executeCode(learnerAppState.curInstr);
193-
}
177+
var learnerAppState = msg.myAppState;
178+
179+
if (learnerAppState.mode == 'display' ||
180+
learnerAppState.mode == 'visualize' /* deprecated */) {
181+
if (appStateEq(getAppState(), learnerAppState)) {
182+
// update curInstr only
183+
console.log("on:myAppState - app states equal, renderStep", learnerAppState.curInstr);
184+
myVisualizer.renderStep(learnerAppState.curInstr);
194185
}
195186
else {
196-
console.log("on:myAppState - edit mode sync");
187+
console.log("on:myAppState - app states unequal, executing", learnerAppState);
197188
setVisibleAppState(learnerAppState);
189+
executeCode(learnerAppState.curInstr);
198190
}
199-
200-
appMode = learnerAppState.mode;
201-
updateAppDisplay();
202191
}
203-
finally {
204-
// TODO: this is wrong since it switches way too early. we should
205-
// stop syncing after executeCode has successfully finished, which
206-
// runs a callback function
207-
nowSyncing = false; // done with a successful sync round trip
192+
else {
193+
console.log("on:myAppState - edit mode sync");
194+
setVisibleAppState(learnerAppState);
208195
}
209196
});
210197

@@ -384,11 +371,6 @@ function executeCodeWithRawInput(rawInputStr, curInstr) {
384371
$(document).ready(function() {
385372
setSurveyHTML();
386373

387-
// as of 2014-05-02, remove the button click survey questions from the
388-
// visualizer so as not to clutter up the screen. i started running
389-
// this experiment on 2014-04-09 and put it on hold on 2014-05-02:
390-
$("#surveyHeader").remove();
391-
392374
$("#embedLinkDiv").hide();
393375

394376
pyInputCodeMirror = CodeMirror(document.getElementById('codeInputPane'), {
@@ -410,15 +392,14 @@ $(document).ready(function() {
410392
}
411393

412394

413-
// be friendly to the browser's forward and back buttons
395+
// be (somewhat) friendly to the browser's forward and back buttons
414396
// thanks to http://benalman.com/projects/jquery-bbq-plugin/
415397
$(window).bind("hashchange", function(e) {
416398
appMode = $.bbq.getState('mode'); // assign this to the GLOBAL appMode
417399
console.log('hashchange:', appMode);
418400
updateAppDisplay();
419401

420-
if (TogetherJS.running && !nowSyncing && !hashchangeSignalFromRemote) {
421-
console.log("TogetherJS SEND hashchange", appMode);
402+
if (TogetherJS.running && !hashchangeSignalFromRemote) {
422403
TogetherJS.send({type: "hashchange", appMode: appMode});
423404
}
424405
});

‎v3/js/pytutor.js‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,6 +1773,11 @@ ExecutionVisualizer.prototype.renderStep = function(step) {
17731773
assert(0 <= step);
17741774
assert(step < this.curTrace.length);
17751775

1776+
// ignore redundant calls
1777+
if (this.curInstr == step) {
1778+
return;
1779+
}
1780+
17761781
this.curInstr = step;
17771782
this.updateOutput();
17781783
}

‎v3/opt_togetherjs/admin.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
var linkURL = dat.url + '&role=tutor';
2424

2525
d.html(dat.timestr + ' ' + dat.ip +
26-
' <a href="' + linkURL + '">' + linkURL + '</a> ' +
26+
' <a href="' + linkURL + '" target="_blank">' + linkURL + '</a> ' +
2727
'<button type="button" class="eraseBtn">Erase</button>');
2828

2929
d.find('button.eraseBtn').click(function() {

‎v3/visualize.html‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,16 @@
7575
<!-- hide by default -->
7676
<div id="togetherJSHeader" style="margin-top: 12pt; margin-bottom: 10pt; display: none;">
7777
<button id="togetherBtn" type="button"
78-
style="color: #b80000; font-size: 11pt; padding: 6px;
78+
style="color: #b80000; font-size: 12pt; padding: 6px;
7979
margin-right: 5pt;">Get live help now</button>
8080
<span style="display: none;" id="helpQueueUrls"></span>
8181
</div>
8282

83+
<!--
84+
// as of 2014-05-03, remove the button click survey questions from the
85+
// visualizer so as not to clutter up the screen. i started running
86+
// this experiment on 2014-04-09 and put it on hold on 2014-05-02:
87+
8388
<div id="surveyHeader" style="margin-bottom: 5pt; display: none;">
8489
<div id="vizSurveyLabel" style="font-size: 8pt; color: #666;">
8590
Support our research by clicking a button when you see something interesting in the visualization.<br/>
@@ -93,6 +98,8 @@
9398
</div>
9499
</div>
95100
101+
-->
102+
96103

97104
<div id="pyInputPane">
98105

0 commit comments

Comments
 (0)