@@ -127,7 +127,6 @@ export class Toolbar extends React.Component<IToolbarProps, IToolbarState> {
127127 super ( props ) ;
128128
129129 const repo = this . props . model . pathRepository ;
130- this . _addListeners ( ) ;
131130
132131 this . state = {
133132 branchMenu : false ,
@@ -137,10 +136,17 @@ export class Toolbar extends React.Component<IToolbarProps, IToolbarState> {
137136 } ;
138137 }
139138
139+ /**
140+ * Callback invoked immediately after mounting a component (i.e., inserting into a tree).
141+ */
142+ componentDidMount ( ) : void {
143+ this . _addListeners ( ) ;
144+ }
145+
140146 /**
141147 * Callback invoked when a component will no longer be mounted.
142148 */
143- componentWillUnmount ( ) {
149+ componentWillUnmount ( ) : void {
144150 this . _removeListeners ( ) ;
145151 }
146152
@@ -280,9 +286,6 @@ export class Toolbar extends React.Component<IToolbarProps, IToolbarState> {
280286 * Adds model listeners.
281287 */
282288 private _addListeners ( ) : void {
283- // When the repository changes, we're likely to have a new set of branches:
284- this . props . model . repositoryChanged . connect ( this . _syncState , this ) ;
285-
286289 // When the HEAD changes, decent probability that we've switched branches:
287290 this . props . model . headChanged . connect ( this . _syncState , this ) ;
288291
@@ -294,7 +297,6 @@ export class Toolbar extends React.Component<IToolbarProps, IToolbarState> {
294297 * Removes model listeners.
295298 */
296299 private _removeListeners ( ) : void {
297- this . props . model . repositoryChanged . disconnect ( this . _syncState , this ) ;
298300 this . props . model . headChanged . disconnect ( this . _syncState , this ) ;
299301 this . props . model . statusChanged . disconnect ( this . _syncState , this ) ;
300302 }
0 commit comments