Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Favor the Disposal Pattern #104

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Unreleased

* Extended our use of the disposable pattern to include Xterm and Emitter instances and renamed our own `destroy()` methods to `dispose()`.
* Updated Etch to 0.14.0.
* Updated Xterm.js to 3.10.1.
* Added package-lock.json to the repository.
* Updated CircleCI configuration for CircleCI 2.0.

## 0.5.7
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Terminal for Atom

A simple terminal for Atom that is based on the excellent [Xterm.js](http://xtermjs.org) and [node-pty](https://github.com/Tyriar/node-pty) projects. Works best with Atom 1.17 and later with support for Docks.
A simple terminal for Atom that is based on the excellent [Xterm.js](http://xtermjs.org) and [node-pty](https://github.com/Tyriar/node-pty) projects.

## Demo

Expand Down
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();

// Destroy the Terminal Instance
if (this.xterm) this.xterm.destroy();

// 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
Loading