Skip to content

Commit 1f940fc

Browse files
committed
Remove listener and move listener binding to lifecyle method
1 parent 9bdb8f3 commit 1f940fc

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

src/components/BranchMenu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export class BranchMenu extends React.Component<
9898
/**
9999
* Callback invoked when a component will no longer be mounted.
100100
*/
101-
componentWillUnmount() {
101+
componentWillUnmount(): void {
102102
this._removeListeners();
103103
}
104104

src/components/NewBranchDialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export class NewBranchDialog extends React.Component<
126126
/**
127127
* Callback invoked when a component will no longer be mounted.
128128
*/
129-
componentWillUnmount() {
129+
componentWillUnmount(): void {
130130
this._removeListeners();
131131
}
132132

src/components/Toolbar.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)