@@ -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:' ) ;
0 commit comments