From e3c197c3e11d59f09175cfc451271e97bb9f8397 Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Sun, 15 Jul 2018 22:08:09 -0600 Subject: [PATCH] Fix event emitter leak --- core/client.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/core/client.js b/core/client.js index a2eb4bc3..ec10947f 100644 --- a/core/client.js +++ b/core/client.js @@ -111,12 +111,13 @@ function Client(/*input, output*/) { this.input.on('data', this.dataHandler); }; - Events.on(Events.getSystemEvents().ThemeChanged, ( { themeId } ) => { - if(_.get(this.currentTheme, 'info.themeId') === themeId) { - this.currentTheme = require('./theme.js').getAvailableThemes().get(themeId); + this.themeChangedListener = function( { themeId } ) { + if(_.get(self.currentTheme, 'info.themeId') === themeId) { + self.currentTheme = require('./theme.js').getAvailableThemes().get(themeId); } - }); + }; + Events.on(Events.getSystemEvents().ThemeChanged, this.themeChangedListener); // // Peek at incoming |data| and emit events for any special @@ -458,7 +459,9 @@ Client.prototype.end = function () { this.term.disconnect(); } - var currentModule = this.menuStack.getCurrentModule; + Events.removeListener(Events.getSystemEvents().ThemeChanged, this.themeChangedListener); + + const currentModule = this.menuStack.getCurrentModule; if(currentModule) { currentModule.leave(); @@ -470,10 +473,9 @@ Client.prototype.end = function () { // // We can end up calling 'end' before TTY/etc. is established, e.g. with SSH // - // :TODO: is this OK? return this.output.end.apply(this.output, arguments); } catch(e) { - // TypeError + // ie TypeError } };