@@ -33,9 +33,10 @@ function ControllerInstanceLayout(
3333 githubUsername : account
3434 } )
3535 . cacheFetch ( function ( instances , cached , cb ) {
36- if ( account === keypather . get ( $rootScope , 'dataApp.data.activeAccount.oauthName()' ) &&
37- $rootScope . dataApp . data . instances !== instances ) {
38- $rootScope . dataApp . data . instances = instances ;
36+ if ( account === keypather . get ( $rootScope , 'dataApp.data.activeAccount.oauthName()' ) ) {
37+ if ( $rootScope . dataApp . data . instances !== instances ) {
38+ $rootScope . dataApp . data . instances = instances ;
39+ }
3940 $scope . dataInstanceLayout . state . loadingInstances = false ;
4041 $rootScope . safeApply ( cb ) ;
4142 } else {
@@ -51,18 +52,23 @@ function ControllerInstanceLayout(
5152 if ( err ) { throw err ; }
5253 } ) ;
5354 }
54-
5555 var dataInstanceLayout = $scope . dataInstanceLayout = {
5656 data : { } ,
5757 state : { } ,
5858 actions : { }
5959 } ;
6060 dataInstanceLayout . data . logoutURL = configLogoutURL ( ) ;
6161
62- $rootScope . $watch ( 'dataApp.data.activeAccount.oauthName()' , function ( n ) {
63- if ( n ) {
64- fetchInstances ( n ) ;
65- }
62+ var instanceListUnwatcher = $scope . $on ( 'INSTANCE_LIST_FETCH' , function ( event , org ) {
63+ fetchInstances ( org . oauthName ( ) ) ;
64+ } ) ;
65+
66+ $scope . $on ( '$destroy' , function ( ) {
67+ instanceListUnwatcher ( ) ;
6668 } ) ;
6769
70+ if ( keypather . get ( $rootScope , 'dataApp.data.activeAccount.oauthName()' ) ) {
71+ fetchInstances ( keypather . get ( $rootScope , 'dataApp.data.activeAccount.oauthName()' ) ) ;
72+ }
73+
6874}
0 commit comments