Skip to content

Commit

Permalink
Switched to the disposable pattern wherever possible.
Browse files Browse the repository at this point in the history
  • Loading branch information
jsmecham committed Jan 23, 2019
1 parent bb86910 commit 7b4fa7e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
12 changes: 5 additions & 7 deletions lib/terminal-session.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export default class TerminalSession {
this.pty = this.openPseudoterminal();
this.xterm = new Xterm();

this.disposables.add(this.emitter, this.xterm);

this.handleEvents();
}

Expand All @@ -37,7 +39,7 @@ export default class TerminalSession {
});

// Process Terminal Exit Events
this.pty.on('exit', this.destroy.bind(this));
this.pty.on('exit', this.dispose.bind(this));

}

Expand Down Expand Up @@ -88,19 +90,15 @@ export default class TerminalSession {
};
}

destroy() {
dispose() {

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

// Dispose of the Terminal Instance
if (this.xterm) this.xterm.dispose();

// Notify any observers that this session is being destroyed.
// Notify any observers that this session is being disposed.
this.emitter.emit('did-destroy', this);

// Clean up any disposables we're responsible for.
this.emitter.dispose();
this.disposables.dispose();

}
Expand Down
4 changes: 2 additions & 2 deletions lib/terminal-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class TerminalView {
// Observe the Session to know when it is destroyed so that we can
// clean up our state (i.e. remove event observers).
//
this.session.onDidDestroy(this.destroy.bind(this));
this.session.onDidDestroy(this.dispose.bind(this));

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

destroy() {
dispose() {
this.resizeObserver.disconnect();
this.disposables.dispose();
etch.destroy(this);
Expand Down
2 changes: 1 addition & 1 deletion spec/terminal-session-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('TerminalSession', () => {
});

afterEach(() => {
testSession.destroy();
testSession.dispose();
});

describe('xterm', () => {
Expand Down
4 changes: 2 additions & 2 deletions spec/terminal-view-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ describe('TerminalView', () => {
});

afterEach(() => {
terminalView.destroy();
testSession.destroy();
terminalView.dispose();
testSession.dispose();
});

describe('focus', () => {
Expand Down

0 comments on commit 7b4fa7e

Please sign in to comment.