@@ -82,7 +82,6 @@ var isTutor = false;
8282// nasty globals
8383var updateOutputSignalFromRemote = false ;
8484var hashchangeSignalFromRemote = false ;
85- var nowSyncing = false ;
8685
8786// Global hook for ExecutionVisualizer.
8887var try_hook = function ( hook_name , args ) {
@@ -92,7 +91,6 @@ var try_hook = function(hook_name, args) {
9291
9392function 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 } ) ;
0 commit comments