Skip to content

Commit d0a2cbe

Browse files
committed
fix: use Map for decorationsByMarkerId
1 parent 1fc7bc8 commit d0a2cbe

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

lib/mixins/decoration-management.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default class DecorationManagement {
3737
* @type {Object}
3838
* @access private
3939
*/
40-
this.decorationsByMarkerId = {}
40+
this.decorationsByMarkerId = new Map()
4141
/**
4242
* The subscriptions to the markers `did-change` event indexed using the
4343
* marker id.
@@ -187,7 +187,7 @@ export default class DecorationManagement {
187187

188188
for (let i = 0, len = markers.length; i < len; i++) {
189189
const marker = markers[i]
190-
const decorations = this.decorationsByMarkerId[marker.id]
190+
const decorations = this.decorationsByMarkerId.get(marker.id)
191191

192192
if (decorations != null) {
193193
decorationsByMarkerId[marker.id] = decorations
@@ -348,7 +348,7 @@ export default class DecorationManagement {
348348
if (this.decorationMarkerChangedSubscriptions[id] == null) {
349349
this.decorationMarkerChangedSubscriptions[id] =
350350
marker.onDidChange((event) => {
351-
const decorations = this.decorationsByMarkerId[id]
351+
const decorations = this.decorationsByMarkerId.get(id)
352352
const screenRange = marker.getScreenRange()
353353

354354
this.invalidateDecorationForScreenRowsCache()
@@ -395,11 +395,11 @@ export default class DecorationManagement {
395395

396396
const decoration = new Decoration(marker, this, decorationParams)
397397

398-
if (this.decorationsByMarkerId[id] == null) {
399-
this.decorationsByMarkerId[id] = []
398+
if (!this.decorationsByMarkerId.has(id)) {
399+
this.decorationsByMarkerId.set(id, [])
400400
}
401401

402-
this.decorationsByMarkerId[id].push(decoration)
402+
this.decorationsByMarkerId.get(id).push(decoration)
403403
this.decorationsById.set(decoration.id, decoration)
404404

405405
if (this.decorationUpdatedSubscriptions[decoration.id] == null) {
@@ -535,7 +535,7 @@ export default class DecorationManagement {
535535
delete this.decorationUpdatedSubscriptions[decoration.id]
536536
delete this.decorationDestroyedSubscriptions[decoration.id]
537537

538-
const decorations = this.decorationsByMarkerId[marker.id]
538+
const decorations = this.decorationsByMarkerId.get(marker.id)
539539
if (!decorations) { return }
540540

541541
this.emitDecorationChanges(decoration.getProperties().type, decoration)
@@ -565,7 +565,7 @@ export default class DecorationManagement {
565565
removeAllDecorationsForMarker (marker) {
566566
if (marker == null) { return }
567567

568-
const decorations = this.decorationsByMarkerId[marker.id]
568+
const decorations = this.decorationsByMarkerId.get(marker.id)
569569
if (!decorations) { return }
570570

571571
for (let i = 0, len = decorations.length; i < len; i++) {
@@ -595,7 +595,7 @@ export default class DecorationManagement {
595595
this.decorationMarkerChangedSubscriptions[marker.id].dispose()
596596
this.decorationMarkerDestroyedSubscriptions[marker.id].dispose()
597597

598-
delete this.decorationsByMarkerId[marker.id]
598+
this.decorationsByMarkerId.delete(marker.id)
599599
delete this.decorationMarkerChangedSubscriptions[marker.id]
600600
delete this.decorationMarkerDestroyedSubscriptions[marker.id]
601601
}
@@ -626,7 +626,7 @@ export default class DecorationManagement {
626626
}
627627

628628
this.decorationsById.clear()
629-
this.decorationsByMarkerId = {}
629+
this.decorationsByMarkerId.clear()
630630
this.decorationMarkerChangedSubscriptions = {}
631631
this.decorationMarkerDestroyedSubscriptions = {}
632632
this.decorationUpdatedSubscriptions = {}

spec/minimap-spec.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ describe('Minimap', () => {
336336
})
337337

338338
it('creates a decoration for the given marker', () => {
339-
expect(minimap.decorationsByMarkerId[marker.id]).toBeDefined()
339+
expect(minimap.decorationsByMarkerId.get(marker.id)).toBeDefined()
340340
})
341341

342342
it('creates a change corresponding to the marker range', () => {
@@ -367,7 +367,7 @@ describe('Minimap', () => {
367367
})
368368

369369
it('removes the decoration from the render view', () => {
370-
expect(minimap.decorationsByMarkerId[marker.id]).toBeUndefined()
370+
expect(minimap.decorationsByMarkerId.get(marker.id)).toBeUndefined()
371371
})
372372

373373
it('creates a change corresponding to the marker range', () => {
@@ -382,7 +382,7 @@ describe('Minimap', () => {
382382
})
383383

384384
it('removes the decoration from the render view', () => {
385-
expect(minimap.decorationsByMarkerId[marker.id]).toBeUndefined()
385+
expect(minimap.decorationsByMarkerId.get(marker.id)).toBeUndefined()
386386
})
387387

388388
it('creates a change corresponding to the marker range', () => {
@@ -397,7 +397,7 @@ describe('Minimap', () => {
397397
})
398398

399399
it('removes the decoration from the render view', () => {
400-
expect(minimap.decorationsByMarkerId[marker.id]).toBeUndefined()
400+
expect(minimap.decorationsByMarkerId.get(marker.id)).toBeUndefined()
401401
})
402402

403403
it('creates a change corresponding to the marker range', () => {
@@ -413,7 +413,7 @@ describe('Minimap', () => {
413413

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

419419
it('prevents the creation of new decorations', () => {

0 commit comments

Comments
 (0)