Skip to content

Commit

Permalink
fix(performance): fix event emitter memory leak (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
OmriBarZik authored May 9, 2021
1 parent 37779d2 commit 9851ce4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/screen.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const CONTAINERS_GRID_LAYOUT = {
const SERVICES_GRID_LAYOUT = {
'actionsMenu': [4, 4, 4, 4],
'actionStatus': [6, 0, 1, 10],
'searchInput': [11, 0, 1, 12],
'help': [4, 4, 4, 4],
'servicesInfo': [2, 2, 8, 8],
'servicesList': [0, 0, 6, 10],
Expand Down Expand Up @@ -124,6 +125,13 @@ class screen {
}
}

clearWidgets () {
for (let [widgetName] of this.assets.get('widgets').entries()) {
this.widgets.delete(widgetName)
this.widgetsRepository.delete(widgetName)
}
}

setWidgetsRepo () {
for (let widgetObject of this.widgetsRepository.values()) {
widgetObject.setWidgetsRepo(this.widgetsRepository)
Expand Down Expand Up @@ -190,6 +198,7 @@ class screen {

this.screen.key('v', () => {
this.clearHooks()
this.clearWidgets()
this.toggleMode()
this.screen.destroy()
this.init()
Expand Down
11 changes: 7 additions & 4 deletions src/widgetsTemplates/list.widget.template.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,13 @@ class myWidget extends baseWidget(EventEmitter) {
}
})

const searchInput = this.widgetsRepo.get('searchInput')
searchInput.on('keypress', (data) => {
this.filterList(data)
})
if (this.widgetsRepo && this.widgetsRepo.has('searchInput')) {
const searchInput = this.widgetsRepo.get('searchInput')

searchInput.on('keypress', (data) => {
this.filterList(data)
})
}
}

getWidget () {
Expand Down

0 comments on commit 9851ce4

Please sign in to comment.