@@ -587,11 +587,10 @@ class OptFrontend extends AbstractBaseFrontend {
587587 this . updateAppDisplay ( 'edit' ) ;
588588 }
589589
590+ // try to make this function as idempotent as possible, so that
591+ // repeated calls with same params don't do anything bad
590592 updateAppDisplay ( newAppMode ) {
591- // idempotence is VERY important here
592- if ( newAppMode == this . appMode ) {
593- return ;
594- }
593+ //console.log('updateAppDisplay', newAppMode);
595594
596595 this . appMode = newAppMode ;
597596
@@ -636,17 +635,20 @@ class OptFrontend extends AbstractBaseFrontend {
636635 // jsPlumb connectors won't render properly
637636 this . myVisualizer . updateOutput ( ) ;
638637
638+ // use .off() to remove all handlers first, to prevent accidental
639+ // multiple attaches ...
640+
639641 // customize edit button click functionality AFTER rendering myVisualizer
640642 $ ( '#pyOutputPane #editCodeLinkDiv' ) . show ( ) ;
641- $ ( '#pyOutputPane #editBtn' ) . click ( ( ) => {
643+ $ ( '#pyOutputPane #editBtn' ) . off ( ) . click ( ( ) => {
642644 this . enterEditMode ( ) ;
643645 } ) ;
644646 var v = $ ( '#pythonVersionSelector' ) . val ( ) ;
645647 if ( v === 'js' || v === '2' || v === '3' ) {
646648 var myArgs = this . getAppState ( ) ;
647649 var urlStr = $ . param . fragment ( 'live.html' , myArgs , 2 /* clobber all */ ) ;
648650 $ ( "#pyOutputPane #liveModeSpan" ) . show ( ) ;
649- $ ( '#pyOutputPane #editLiveModeBtn' ) . click ( this . openLiveModeUrl . bind ( this ) ) ;
651+ $ ( '#pyOutputPane #editLiveModeBtn' ) . off ( ) . click ( this . openLiveModeUrl . bind ( this ) ) ;
650652 } else {
651653 $ ( "#pyOutputPane #liveModeSpan" ) . hide ( ) ;
652654 }
0 commit comments