Skip to content

Commit 7b4fa7e

Browse files
committed
Switched to the disposable pattern wherever possible.
1 parent bb86910 commit 7b4fa7e

File tree

4 files changed

+10
-12
lines changed

4 files changed

+10
-12
lines changed

lib/terminal-session.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export default class TerminalSession {
1919
this.pty = this.openPseudoterminal();
2020
this.xterm = new Xterm();
2121

22+
this.disposables.add(this.emitter, this.xterm);
23+
2224
this.handleEvents();
2325
}
2426

@@ -37,7 +39,7 @@ export default class TerminalSession {
3739
});
3840

3941
// Process Terminal Exit Events
40-
this.pty.on('exit', this.destroy.bind(this));
42+
this.pty.on('exit', this.dispose.bind(this));
4143

4244
}
4345

@@ -88,19 +90,15 @@ export default class TerminalSession {
8890
};
8991
}
9092

91-
destroy() {
93+
dispose() {
9294

9395
// Kill the Pseudoterminal (pty) Process
9496
if (this.pty) this.pty.kill();
9597

96-
// Dispose of the Terminal Instance
97-
if (this.xterm) this.xterm.dispose();
98-
99-
// Notify any observers that this session is being destroyed.
98+
// Notify any observers that this session is being disposed.
10099
this.emitter.emit('did-destroy', this);
101100

102101
// Clean up any disposables we're responsible for.
103-
this.emitter.dispose();
104102
this.disposables.dispose();
105103

106104
}

lib/terminal-view.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default class TerminalView {
1818
// Observe the Session to know when it is destroyed so that we can
1919
// clean up our state (i.e. remove event observers).
2020
//
21-
this.session.onDidDestroy(this.destroy.bind(this));
21+
this.session.onDidDestroy(this.dispose.bind(this));
2222

2323
// TODO: Documentation says this should be set for Atom... Research!
2424
// etch.setScheduler(atom.views);
@@ -38,7 +38,7 @@ export default class TerminalView {
3838
return etch.update(this);
3939
}
4040

41-
destroy() {
41+
dispose() {
4242
this.resizeObserver.disconnect();
4343
this.disposables.dispose();
4444
etch.destroy(this);

spec/terminal-session-spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('TerminalSession', () => {
1212
});
1313

1414
afterEach(() => {
15-
testSession.destroy();
15+
testSession.dispose();
1616
});
1717

1818
describe('xterm', () => {

spec/terminal-view-spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ describe('TerminalView', () => {
1515
});
1616

1717
afterEach(() => {
18-
terminalView.destroy();
19-
testSession.destroy();
18+
terminalView.dispose();
19+
testSession.dispose();
2020
});
2121

2222
describe('focus', () => {

0 commit comments

Comments
 (0)