Skip to content

Commit e71bd8d

Browse files
authored
fix: Optimizations (#14)
1 parent 900ed0e commit e71bd8d

File tree

3 files changed

+23
-18
lines changed

3 files changed

+23
-18
lines changed

lib/minimap-bookmarks-binding.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ class MinimapBookmarksBinding {
88

99
this.subscriptions = new CompositeDisposable()
1010
this.editor = this.minimap.getTextEditor()
11-
this.decorationsByMarkerId = {}
12-
this.decorationSubscriptionsByMarkerId = {}
11+
this.decorationsByMarkerId = new Map()
12+
this.decorationSubscriptionsByMarkerId = new Map()
1313

1414
// We need to wait until the bookmarks package had created its marker
1515
// layer before retrieving its id from the state.
@@ -39,23 +39,26 @@ class MinimapBookmarksBinding {
3939
handleMarker (marker) {
4040
const { id } = marker
4141
const decoration = this.minimap.decorateMarker(marker, { type: 'line', class: 'bookmark', plugin: 'bookmarks' })
42-
this.decorationsByMarkerId[id] = decoration
43-
this.decorationSubscriptionsByMarkerId[id] = decoration.onDidDestroy(() => {
44-
this.decorationSubscriptionsByMarkerId[id].dispose()
42+
this.decorationsByMarkerId.set(id, decoration)
43+
this.decorationSubscriptionsByMarkerId.set(id,
44+
decoration.onDidDestroy(() => {
45+
this.decorationSubscriptionsByMarkerId.get(id).dispose()
4546

46-
delete this.decorationsByMarkerId[id]
47-
delete this.decorationSubscriptionsByMarkerId[id]
48-
})
47+
this.decorationsByMarkerId.delete(id)
48+
this.decorationSubscriptionsByMarkerId.delete(id)
49+
}),
50+
)
4951
}
5052

5153
destroy () {
52-
for (const id in this.decorationsByMarkerId) {
53-
const decoration = this.decorationsByMarkerId[id]
54-
this.decorationSubscriptionsByMarkerId[id].dispose()
54+
const ids = this.decorationsByMarkerId.keys()
55+
for (const id of ids) {
56+
const decoration = this.decorationsByMarkerId.get(id)
57+
this.decorationSubscriptionsByMarkerId.get(id).dispose()
5558
decoration.destroy()
5659

57-
delete this.decorationsByMarkerId[id]
58-
delete this.decorationSubscriptionsByMarkerId[id]
60+
this.decorationsByMarkerId.delete(id)
61+
this.decorationSubscriptionsByMarkerId.delete(id)
5962
}
6063

6164
this.subscriptions.dispose()

lib/minimap-bookmarks.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module.exports = {
1515
activate () {
1616
this.active = false
1717
this.subscriptions = new CompositeDisposable()
18-
this.bindings = {}
18+
this.bindings = new Map()
1919
require('atom-package-deps').install('minimap-git-diff')
2020
},
2121

@@ -49,13 +49,13 @@ module.exports = {
4949
}
5050

5151
const binding = new MinimapBookmarksBinding(minimap, bookmarks)
52-
this.bindings[minimap.id] = binding
52+
this.bindings.set(minimap.id, binding)
5353

5454
const subscription = minimap.onDidDestroy(() => {
5555
binding.destroy()
5656
this.subscriptions.remove(subscription)
5757
subscription.dispose()
58-
delete this.bindings[minimap.id]
58+
this.bindings.delete(minimap.id)
5959
})
6060
this.subscriptions.add(subscription)
6161
})
@@ -64,8 +64,9 @@ module.exports = {
6464
deactivatePlugin () {
6565
if (!this.active) { return }
6666

67-
for (const id in this.bindings) { const binding = this.bindings[id]; binding.destroy() }
68-
this.bindings = {}
67+
const bindings = this.bindings.values()
68+
for (const binding of bindings) { binding.destroy() }
69+
this.bindings.clear()
6970
this.active = false
7071
this.minimapsSubscription.dispose()
7172
this.subscriptions.dispose()

styles/minimap-bookmarks.less

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
@import "ui-variables";
66

77
.minimap .bookmark {
8+
contain: layout size paint style;
89
background: @background-color-info;
910
}

0 commit comments

Comments
 (0)