Skip to content

Commit e2248a9

Browse files
committed
Merge pull request #15 from aki77/fix/remove-dependencies
Fix leak bindings
2 parents 2cb005b + 549e349 commit e2248a9

File tree

3 files changed

+15
-19
lines changed

3 files changed

+15
-19
lines changed

lib/minimap-git-diff-binding.coffee

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
{CompositeDisposable} = require 'event-kit'
1+
{CompositeDisposable} = require 'atom'
22
{repositoryForPath} = require './helpers'
33

44
module.exports =
55
class MinimapGitDiffBinding
66

77
active: false
88

9-
constructor: (@gitDiff, @minimap) ->
9+
constructor: (@minimap) ->
1010
@editor = @minimap.getTextEditor()
1111
@decorations = {}
1212
@markers = null
1313
@subscriptions = new CompositeDisposable
1414

1515
@subscriptions.add @editor.getBuffer().onDidStopChanging @updateDiffs
16+
@subscriptions.add @minimap.onDidDestroy @destroy
1617

1718
if repository = @getRepo()
1819
@subscriptions.add repository.onDidChangeStatuses =>
@@ -59,10 +60,11 @@ class MinimapGitDiffBinding
5960
@markers ?= []
6061
@markers.push(marker)
6162

62-
destroy: ->
63+
destroy: =>
6364
@removeDecorations()
6465
@subscriptions.dispose()
6566
@diffs = null
67+
@minimap = null
6668

6769
getPath: -> @editor.getBuffer()?.getPath()
6870

lib/minimap-git-diff.coffee

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
1-
{CompositeDisposable, Disposable} = require 'event-kit'
2-
{requirePackages} = require 'atom-utils'
1+
{CompositeDisposable, Disposable} = require 'atom'
32

43
MinimapGitDiffBinding = null
54

65
class MinimapGitDiff
76

8-
bindings: {}
97
pluginActive: false
108
constructor: ->
119
@subscriptions = new CompositeDisposable
1210

1311
isActive: -> @pluginActive
1412

1513
activate: ->
14+
@bindings = new WeakMap
1615

1716
consumeMinimapServiceV1: (@minimap) ->
1817
@minimap.registerPlugin 'git-diff', this
1918

2019
deactivate: ->
21-
binding.destroy() for id,binding of @bindings
22-
@bindings = {}
23-
@gitDiff = null
20+
@destroyBindings()
2421
@minimap = null
2522

2623
activatePlugin: ->
@@ -61,16 +58,15 @@ class MinimapGitDiff
6158

6259
return unless editor?
6360

64-
id = editor.id
65-
binding = new MinimapGitDiffBinding @gitDiff, minimap
66-
@bindings[id] = binding
61+
binding = new MinimapGitDiffBinding minimap
62+
@bindings.set(minimap, binding)
6763

6864
getRepositories: -> atom.project.getRepositories().filter (repo) -> repo?
6965

7066
destroyBindings: =>
71-
binding.destroy() for id,binding of @bindings
72-
@bindings = {}
73-
74-
asDisposable: (subscription) -> new Disposable -> subscription.off()
67+
return unless @minimap?
68+
for minimap in @minimap.editorsMinimaps
69+
@bindings.get(minimap)?.destroy()
70+
@bindings.delete(minimap)
7571

7672
module.exports = new MinimapGitDiff

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
},
1919
"dependencies": {
2020
"mixto": "1.x",
21-
"fs-plus": "^2.0.0",
22-
"event-kit": ">= 0.7.2",
23-
"atom-utils": "0.0.1"
21+
"fs-plus": "^2.0.0"
2422
}
2523
}

0 commit comments

Comments
 (0)