From 863faffd237cd592a6b34b8ab3e4707bb8e4b5f1 Mon Sep 17 00:00:00 2001 From: Matthew Dapena-Tretter Date: Tue, 27 Jun 2017 16:08:16 -0700 Subject: [PATCH] Only expect a single 'did-destroy' event These events will only be fired a single time at most, so we should clean up the listeners after that. This should help minimize accidental memory leaks. --- src/cursor.coffee | 2 +- src/decoration.coffee | 2 +- src/git-repository.coffee | 2 +- src/gutter.coffee | 2 +- src/pane-axis.coffee | 2 +- src/pane.coffee | 2 +- src/panel-container.js | 2 +- src/panel.js | 2 +- src/selection.coffee | 2 +- src/text-editor.coffee | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/cursor.coffee b/src/cursor.coffee index 74922ff51..128fe7ff5 100644 --- a/src/cursor.coffee +++ b/src/cursor.coffee @@ -49,7 +49,7 @@ class Cursor extends Model # # Returns a {Disposable} on which `.dispose()` can be called to unsubscribe. onDidDestroy: (callback) -> - @emitter.on 'did-destroy', callback + @emitter.once 'did-destroy', callback ### Section: Managing Cursor Position diff --git a/src/decoration.coffee b/src/decoration.coffee index 7be15d9f5..f18733f6e 100644 --- a/src/decoration.coffee +++ b/src/decoration.coffee @@ -105,7 +105,7 @@ class Decoration # # Returns a {Disposable} on which `.dispose()` can be called to unsubscribe. onDidDestroy: (callback) -> - @emitter.on 'did-destroy', callback + @emitter.once 'did-destroy', callback ### Section: Decoration Details diff --git a/src/git-repository.coffee b/src/git-repository.coffee index f80152737..c7105baef 100644 --- a/src/git-repository.coffee +++ b/src/git-repository.coffee @@ -129,7 +129,7 @@ class GitRepository # # Returns a {Disposable} on which `.dispose()` can be called to unsubscribe. onDidDestroy: (callback) -> - @emitter.on 'did-destroy', callback + @emitter.once 'did-destroy', callback ### Section: Event Subscription diff --git a/src/gutter.coffee b/src/gutter.coffee index 6b39398dd..4521eeeb2 100644 --- a/src/gutter.coffee +++ b/src/gutter.coffee @@ -48,7 +48,7 @@ class Gutter # # Returns a {Disposable} on which `.dispose()` can be called to unsubscribe. onDidDestroy: (callback) -> - @emitter.on 'did-destroy', callback + @emitter.once 'did-destroy', callback ### Section: Visibility diff --git a/src/pane-axis.coffee b/src/pane-axis.coffee index 31c5e1664..c8fcc4108 100644 --- a/src/pane-axis.coffee +++ b/src/pane-axis.coffee @@ -69,7 +69,7 @@ class PaneAxis extends Model @emitter.on 'did-replace-child', fn onDidDestroy: (fn) -> - @emitter.on 'did-destroy', fn + @emitter.once 'did-destroy', fn onDidChangeFlexScale: (fn) -> @emitter.on 'did-change-flex-scale', fn diff --git a/src/pane.coffee b/src/pane.coffee index 9c0440e0a..3dde9678f 100644 --- a/src/pane.coffee +++ b/src/pane.coffee @@ -170,7 +170,7 @@ class Pane # # Returns a {Disposable} on which `.dispose()` can be called to unsubscribe. onDidDestroy: (callback) -> - @emitter.on 'did-destroy', callback + @emitter.once 'did-destroy', callback # Public: Invoke the given callback when the value of the {::isActive} # property changes. diff --git a/src/panel-container.js b/src/panel-container.js index 65dd89f7a..6d5fb7398 100644 --- a/src/panel-container.js +++ b/src/panel-container.js @@ -40,7 +40,7 @@ module.exports = class PanelContainer { } onDidDestroy (callback) { - return this.emitter.on('did-destroy', callback) + return this.emitter.once('did-destroy', callback) } /* diff --git a/src/panel.js b/src/panel.js index c9beba72a..49b037be0 100644 --- a/src/panel.js +++ b/src/panel.js @@ -66,7 +66,7 @@ class Panel { // // Returns a {Disposable} on which `.dispose()` can be called to unsubscribe. onDidDestroy (callback) { - return this.emitter.on('did-destroy', callback) + return this.emitter.once('did-destroy', callback) } /* diff --git a/src/selection.coffee b/src/selection.coffee index 935a15b13..e361d0b5c 100644 --- a/src/selection.coffee +++ b/src/selection.coffee @@ -54,7 +54,7 @@ class Selection extends Model # # Returns a {Disposable} on which `.dispose()` can be called to unsubscribe. onDidDestroy: (callback) -> - @emitter.on 'did-destroy', callback + @emitter.once 'did-destroy', callback ### Section: Managing the selection range diff --git a/src/text-editor.coffee b/src/text-editor.coffee index bba314825..ddc435414 100644 --- a/src/text-editor.coffee +++ b/src/text-editor.coffee @@ -647,7 +647,7 @@ class TextEditor extends Model # # Returns a {Disposable} on which `.dispose()` can be called to unsubscribe. onDidDestroy: (callback) -> - @emitter.on 'did-destroy', callback + @emitter.once 'did-destroy', callback # Extended: Calls your `callback` when a {Cursor} is added to the editor. # Immediately calls your callback for each existing cursor.