Skip to content

Commit

Permalink
fix: use Map for decorationsByMarkerId
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Dec 29, 2020
1 parent 1fc7bc8 commit d0a2cbe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
20 changes: 10 additions & 10 deletions lib/mixins/decoration-management.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default class DecorationManagement {
* @type {Object}
* @access private
*/
this.decorationsByMarkerId = {}
this.decorationsByMarkerId = new Map()
/**
* The subscriptions to the markers `did-change` event indexed using the
* marker id.
Expand Down Expand Up @@ -187,7 +187,7 @@ export default class DecorationManagement {

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

if (decorations != null) {
decorationsByMarkerId[marker.id] = decorations
Expand Down Expand Up @@ -348,7 +348,7 @@ export default class DecorationManagement {
if (this.decorationMarkerChangedSubscriptions[id] == null) {
this.decorationMarkerChangedSubscriptions[id] =
marker.onDidChange((event) => {
const decorations = this.decorationsByMarkerId[id]
const decorations = this.decorationsByMarkerId.get(id)
const screenRange = marker.getScreenRange()

this.invalidateDecorationForScreenRowsCache()
Expand Down Expand Up @@ -395,11 +395,11 @@ export default class DecorationManagement {

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

if (this.decorationsByMarkerId[id] == null) {
this.decorationsByMarkerId[id] = []
if (!this.decorationsByMarkerId.has(id)) {
this.decorationsByMarkerId.set(id, [])
}

this.decorationsByMarkerId[id].push(decoration)
this.decorationsByMarkerId.get(id).push(decoration)
this.decorationsById.set(decoration.id, decoration)

if (this.decorationUpdatedSubscriptions[decoration.id] == null) {
Expand Down Expand Up @@ -535,7 +535,7 @@ export default class DecorationManagement {
delete this.decorationUpdatedSubscriptions[decoration.id]
delete this.decorationDestroyedSubscriptions[decoration.id]

const decorations = this.decorationsByMarkerId[marker.id]
const decorations = this.decorationsByMarkerId.get(marker.id)
if (!decorations) { return }

this.emitDecorationChanges(decoration.getProperties().type, decoration)
Expand Down Expand Up @@ -565,7 +565,7 @@ export default class DecorationManagement {
removeAllDecorationsForMarker (marker) {
if (marker == null) { return }

const decorations = this.decorationsByMarkerId[marker.id]
const decorations = this.decorationsByMarkerId.get(marker.id)
if (!decorations) { return }

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

delete this.decorationsByMarkerId[marker.id]
this.decorationsByMarkerId.delete(marker.id)
delete this.decorationMarkerChangedSubscriptions[marker.id]
delete this.decorationMarkerDestroyedSubscriptions[marker.id]
}
Expand Down Expand Up @@ -626,7 +626,7 @@ export default class DecorationManagement {
}

this.decorationsById.clear()
this.decorationsByMarkerId = {}
this.decorationsByMarkerId.clear()
this.decorationMarkerChangedSubscriptions = {}
this.decorationMarkerDestroyedSubscriptions = {}
this.decorationUpdatedSubscriptions = {}
Expand Down
10 changes: 5 additions & 5 deletions spec/minimap-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ describe('Minimap', () => {
})

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

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

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

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

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

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

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

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

it('removes all the previously added decorations', () => {
expect(minimap.decorationsById.size).toEqual(0)
expect(minimap.decorationsByMarkerId).toEqual({})
expect(minimap.decorationsByMarkerId.size).toEqual(0)
})

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

0 comments on commit d0a2cbe

Please sign in to comment.