Skip to content

Commit 1fc7bc8

Browse files
committed
fix: use Map for decorationsById
1 parent 099dab0 commit 1fc7bc8

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

lib/mixins/decoration-management.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default class DecorationManagement {
3131
* @type {Object}
3232
* @access private
3333
*/
34-
this.decorationsById = {}
34+
this.decorationsById = new Map()
3535
/**
3636
* The decorations stored in an array indexed with their marker id.
3737
* @type {Object}
@@ -74,12 +74,7 @@ export default class DecorationManagement {
7474
* @return {Array<Decoration>} all the decorations in this `Minimap`
7575
*/
7676
getDecorations () {
77-
const decorations = this.decorationsById
78-
const results = []
79-
80-
for (const id in decorations) { results.push(decorations[id]) }
81-
82-
return results
77+
return this.decorationsById.values()
8378
}
8479

8580
/**
@@ -173,7 +168,7 @@ export default class DecorationManagement {
173168
* @return {Decoration} the decoration with the given id
174169
*/
175170
decorationForId (id) {
176-
return this.decorationsById[id]
171+
return this.decorationsById.get(id)
177172
}
178173

179174
/**
@@ -235,8 +230,10 @@ export default class DecorationManagement {
235230
}
236231

237232
const cache = {}
238-
for (const id in this.decorationsById) {
239-
const decoration = this.decorationsById[id]
233+
234+
const decorations = this.decorationsById.values()
235+
for (const decoration of decorations) {
236+
240237
const range = decoration.marker.getScreenRange()
241238
const type = decoration.getProperties().type
242239

@@ -403,7 +400,7 @@ export default class DecorationManagement {
403400
}
404401

405402
this.decorationsByMarkerId[id].push(decoration)
406-
this.decorationsById[decoration.id] = decoration
403+
this.decorationsById.set(decoration.id, decoration)
407404

408405
if (this.decorationUpdatedSubscriptions[decoration.id] == null) {
409406
this.decorationUpdatedSubscriptions[decoration.id] =
@@ -527,7 +524,7 @@ export default class DecorationManagement {
527524
const marker = decoration.marker
528525
let subscription
529526

530-
delete this.decorationsById[decoration.id]
527+
this.decorationsById.delete(decoration.id)
531528

532529
subscription = this.decorationUpdatedSubscriptions[decoration.id]
533530
if (subscription != null) { subscription.dispose() }
@@ -623,11 +620,12 @@ export default class DecorationManagement {
623620
this.decorationDestroyedSubscriptions[id].dispose()
624621
}
625622

626-
for (const id in this.decorationsById) {
627-
this.decorationsById[id].destroy()
623+
const decorationsByIdValues = this.decorationsById.values()
624+
for (const decoration of decorationsByIdValues) {
625+
decoration.destroy()
628626
}
629627

630-
this.decorationsById = {}
628+
this.decorationsById.clear()
631629
this.decorationsByMarkerId = {}
632630
this.decorationMarkerChangedSubscriptions = {}
633631
this.decorationMarkerDestroyedSubscriptions = {}

spec/minimap-spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ describe('Minimap', () => {
412412
})
413413

414414
it('removes all the previously added decorations', () => {
415-
expect(minimap.decorationsById).toEqual({})
415+
expect(minimap.decorationsById.size).toEqual(0)
416416
expect(minimap.decorationsByMarkerId).toEqual({})
417417
})
418418

0 commit comments

Comments
 (0)