Skip to content

Commit

Permalink
fix: memoize this.emitter
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Jan 16, 2021
1 parent 5d4c1dc commit 6235c2e
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions lib/decoration-management.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ export default class DecorationManagement {
initializeDecorations (minimap) {
this.minimap = minimap

if (this.minimap.emitter == null) {
if (this.emitter == null) {
/**
* The minimap emitter, lazily created if not created yet.
* @type {Emitter}
* @access private
*/
this.minimap.emitter = new Emitter()
this.emitter = new Emitter()
} else {
this.emitter = this.minimap.emitter
}

/**
Expand Down Expand Up @@ -92,7 +94,7 @@ export default class DecorationManagement {
* @return {Disposable} a disposable to stop listening to the event
*/
onDidAddDecoration (callback) {
return this.minimap.emitter.on('did-add-decoration', callback)
return this.emitter.on('did-add-decoration', callback)
}

/**
Expand All @@ -108,7 +110,7 @@ export default class DecorationManagement {
* @return {Disposable} a disposable to stop listening to the event
*/
onDidRemoveDecoration (callback) {
return this.minimap.emitter.on('did-remove-decoration', callback)
return this.emitter.on('did-remove-decoration', callback)
}

/**
Expand All @@ -127,7 +129,7 @@ export default class DecorationManagement {
* @return {Disposable} a disposable to stop listening to the event
*/
onDidChangeDecoration (callback) {
return this.minimap.emitter.on('did-change-decoration', callback)
return this.emitter.on('did-change-decoration', callback)
}

/**
Expand All @@ -146,7 +148,7 @@ export default class DecorationManagement {
* @return {Disposable} a disposable to stop listening to the event
*/
onDidChangeDecorationRange (callback) {
return this.minimap.emitter.on('did-change-decoration-range', callback)
return this.emitter.on('did-change-decoration-range', callback)
}

/**
Expand All @@ -160,7 +162,7 @@ export default class DecorationManagement {
* @return {Disposable} a disposable to stop listening to the event
*/
onDidUpdateDecoration (callback) {
return this.minimap.emitter.on('did-update-decoration', callback)
return this.emitter.on('did-update-decoration', callback)
}

/**
Expand Down Expand Up @@ -357,7 +359,7 @@ export default class DecorationManagement {
if (decorations !== undefined) {
for (let i = 0, len = decorations.length; i < len; i++) {
const decoration = decorations[i]
this.minimap.emitter.emit('did-change-decoration', {
this.emitter.emit('did-change-decoration', {
marker,
decoration,
event
Expand Down Expand Up @@ -416,7 +418,7 @@ export default class DecorationManagement {
}))

this.emitDecorationChanges(type, decoration)
this.minimap.emitter.emit('did-add-decoration', {
this.emitter.emit('did-add-decoration', {
marker,
decoration
})
Expand Down Expand Up @@ -470,7 +472,7 @@ export default class DecorationManagement {
type
}

this.minimap.emitter.emit('did-change-decoration-range', changeEvent)
this.emitter.emit('did-change-decoration-range', changeEvent)
}

/**
Expand Down Expand Up @@ -506,7 +508,7 @@ export default class DecorationManagement {
if (index > -1) {
decorations.splice(index, 1)

this.minimap.emitter.emit('did-remove-decoration', {
this.emitter.emit('did-remove-decoration', {
marker,
decoration
})
Expand Down Expand Up @@ -536,7 +538,7 @@ export default class DecorationManagement {
if (!this.minimap.editorDestroyed()) {
this.emitDecorationChanges(decoration.getProperties().type, decoration)
}
this.minimap.emitter.emit('did-remove-decoration', {
this.emitter.emit('did-remove-decoration', {
marker,
decoration
})
Expand Down

0 comments on commit 6235c2e

Please sign in to comment.