Skip to content

Commit 9cd033c

Browse files
committed
removed visualizedAppState
1 parent d30a893 commit 9cd033c

3 files changed

Lines changed: 43 additions & 29 deletions

File tree

‎v3/js/opt-frontend-common.js‎

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ function guid() {
8787

8888

8989
var myVisualizer = null; // singleton ExecutionVisualizer instance
90-
var visualizedAppState = null; // parameters necessary to generate myVisualizer
9190

9291

9392
var rawInputLst = []; // a list of strings inputted by the user in response to raw_input or mouse_input events
@@ -141,9 +140,19 @@ function getAppState() {
141140
textReferences: $('#textualMemoryLabelsSelector').val(),
142141
showOnlyOutputs: $('#showOnlyOutputsSelector').val(),
143142
py: $('#pythonVersionSelector').val(),
144-
curInstr: myVisualizer ? myVisualizer.curInstr : undefined,
145-
// the app state that led to the CURRENT visualization
146-
visualizedAppState: visualizedAppState};
143+
curInstr: myVisualizer ? myVisualizer.curInstr : undefined};
144+
}
145+
146+
// return whether two states match, except don't worry about curInstr
147+
function appStateEq(s1, s2) {
148+
return (s1.code == s2.code &&
149+
s1.mode == s2.mode &&
150+
s1.cumulative == s2.cumulative &&
151+
s1.heapPrimitives == s1.heapPrimitives &&
152+
s1.drawParentPointers == s2.drawParentPointers &&
153+
s1.textReferences == s2.textReferences &&
154+
s1.showOnlyOutputs == s2.showOnlyOutputs &&
155+
s1.py == s2.py);
147156
}
148157

149158
// sets the proper GUI features to match the given appState object
@@ -173,6 +182,13 @@ function updateAppDisplay() {
173182
if (myVisualizer) {
174183
myVisualizer.destroyAllAnnotationBubbles();
175184
}
185+
186+
// Potentially controversial: when you enter edit mode, DESTROY any
187+
// existing visualizer object. note that this simplifies the app's
188+
// conceptual model but breaks the browser's expected Forward and
189+
// Back button flow
190+
$("#pyOutputPane").empty();
191+
myVisualizer = null;
176192
}
177193
else if (appMode == 'display' || appMode == 'visualize' /* 'visualize' is deprecated */) {
178194
if (!myVisualizer) {
@@ -257,8 +273,6 @@ function executePythonCode(pythonSourceCode,
257273
return;
258274
}
259275

260-
visualizedAppState = null; // clear this before attempting to execute
261-
262276
$.get(backendScript,
263277
{user_script : pythonSourceCode,
264278
raw_input_json: rawInputLst.length > 0 ? JSON.stringify(rawInputLst) : '',
@@ -315,12 +329,6 @@ function executePythonCode(pythonSourceCode,
315329
});
316330
}
317331

318-
// set some nasty global state that represents the current
319-
// code that's being visualized at the moment, so that we
320-
// can sync its state with other viewers via TogetherJS
321-
visualizedAppState = getAppState();
322-
visualizedAppState.visualizedAppState = null; // prevent chaining
323-
324332
handleSuccessFunc();
325333
}
326334
},

‎v3/js/opt-frontend.js‎

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -180,23 +180,32 @@ function initTogetherJS() {
180180
try {
181181
var learnerAppState = msg.myAppState;
182182

183-
// if available, first set my own app state to visualizedAppState
184-
// and then EXECUTE that code with the given options to create the
185-
// proper myVisualizer object. then adjust app state to the rest
186-
// of learnerAppState
187-
188-
if (learnerAppState.visualizedAppState) {
189-
setVisibleAppState(learnerAppState.visualizedAppState);
190-
// execute code and jump to the learner's curInstr
191-
executeCode(learnerAppState.curInstr);
183+
if (learnerAppState.mode == 'display' ||
184+
learnerAppState.mode == 'visualize' /* deprecated */) {
185+
if (appStateEq(getAppState(), learnerAppState)) {
186+
// update curInstr only
187+
console.log("on:myAppState - app states equal, renderStep", learnerAppState.curInstr);
188+
myVisualizer.renderStep(learnerAppState.curInstr);
189+
}
190+
else {
191+
console.log("on:myAppState - app states unequal, executing", learnerAppState);
192+
setVisibleAppState(learnerAppState);
193+
// execute code and jump to the learner's curInstr
194+
executeCode(learnerAppState.curInstr);
195+
}
196+
}
197+
else {
198+
console.log("on:myAppState - edit mode sync");
199+
setVisibleAppState(learnerAppState);
192200
}
193-
194-
setVisibleAppState(learnerAppState);
195201

196202
appMode = learnerAppState.mode;
197203
updateAppDisplay();
198204
}
199205
finally {
206+
// TODO: this is wrong since it switches way too early. we should
207+
// stop syncing after executeCode has successfully finished, which
208+
// runs a callback function
200209
nowSyncing = false; // done with a successful sync round trip
201210
}
202211
});
@@ -401,10 +410,10 @@ $(document).ready(function() {
401410
// thanks to http://benalman.com/projects/jquery-bbq-plugin/
402411
$(window).bind("hashchange", function(e) {
403412
appMode = $.bbq.getState('mode'); // assign this to the GLOBAL appMode
413+
console.log('hashchange:', appMode);
404414
updateAppDisplay();
405415

406-
if (TogetherJS.running &&
407-
!hashchangeSignalFromRemote /* don't double send */) {
416+
if (TogetherJS.running && !nowSyncing && !hashchangeSignalFromRemote) {
408417
console.log("TogetherJS SEND hashchange", appMode);
409418
TogetherJS.send({type: "hashchange", appMode: appMode});
410419
}
@@ -731,7 +740,6 @@ $(document).ready(function() {
731740

732741
$('#genUrlBtn').bind('click', function() {
733742
var myArgs = getAppState();
734-
delete myArgs.visualizedAppState; // no need to put this in the URL
735743
var urlStr = $.param.fragment(window.location.href, myArgs, 2 /* clobber all */);
736744
$('#urlOutput').val(urlStr);
737745
});
@@ -740,7 +748,6 @@ $(document).ready(function() {
740748
assert(appMode == 'display' || appMode == 'visualize' /* 'visualize' is deprecated */);
741749
var myArgs = getAppState();
742750
delete myArgs.mode;
743-
delete myArgs.visualizedAppState; // no need to put this in the URL
744751
myArgs.codeDivWidth = myVisualizer.DEFAULT_EMBEDDED_CODE_DIV_WIDTH;
745752
myArgs.codeDivHeight = myVisualizer.DEFAULT_EMBEDDED_CODE_DIV_HEIGHT;
746753

@@ -754,7 +761,6 @@ $(document).ready(function() {
754761
$('.surveyBtn').click(function(e) {
755762
// wow, massive copy-and-paste action from above!
756763
var myArgs = getAppState();
757-
delete myArgs.visualizedAppState; // no need to put this in the URL
758764

759765
var buttonPrompt = $(this).html();
760766
var res = prompt('"' + buttonPrompt + '"' + '\nPlease elaborate if you can and hit OK to submit:');

‎v3/visualize.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
<button id="togetherBtn" type="button"
7878
style="color: #b80000; font-size: 11pt; padding: 6px;
7979
margin-right: 5pt;">Get live help now</button>
80-
<span id="helpQueueUrls"></span>
80+
<span style="display: none;" id="helpQueueUrls"></span>
8181
</div>
8282

8383
<div id="surveyHeader" style="margin-bottom: 5pt; display: none;">

0 commit comments

Comments
 (0)