Skip to content

Commit 6235c2e

Browse files
committed
fix: memoize this.emitter
1 parent 5d4c1dc commit 6235c2e

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

lib/decoration-management.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ export default class DecorationManagement {
1919
initializeDecorations (minimap) {
2020
this.minimap = minimap
2121

22-
if (this.minimap.emitter == null) {
22+
if (this.emitter == null) {
2323
/**
2424
* The minimap emitter, lazily created if not created yet.
2525
* @type {Emitter}
2626
* @access private
2727
*/
28-
this.minimap.emitter = new Emitter()
28+
this.emitter = new Emitter()
29+
} else {
30+
this.emitter = this.minimap.emitter
2931
}
3032

3133
/**
@@ -92,7 +94,7 @@ export default class DecorationManagement {
9294
* @return {Disposable} a disposable to stop listening to the event
9395
*/
9496
onDidAddDecoration (callback) {
95-
return this.minimap.emitter.on('did-add-decoration', callback)
97+
return this.emitter.on('did-add-decoration', callback)
9698
}
9799

98100
/**
@@ -108,7 +110,7 @@ export default class DecorationManagement {
108110
* @return {Disposable} a disposable to stop listening to the event
109111
*/
110112
onDidRemoveDecoration (callback) {
111-
return this.minimap.emitter.on('did-remove-decoration', callback)
113+
return this.emitter.on('did-remove-decoration', callback)
112114
}
113115

114116
/**
@@ -127,7 +129,7 @@ export default class DecorationManagement {
127129
* @return {Disposable} a disposable to stop listening to the event
128130
*/
129131
onDidChangeDecoration (callback) {
130-
return this.minimap.emitter.on('did-change-decoration', callback)
132+
return this.emitter.on('did-change-decoration', callback)
131133
}
132134

133135
/**
@@ -146,7 +148,7 @@ export default class DecorationManagement {
146148
* @return {Disposable} a disposable to stop listening to the event
147149
*/
148150
onDidChangeDecorationRange (callback) {
149-
return this.minimap.emitter.on('did-change-decoration-range', callback)
151+
return this.emitter.on('did-change-decoration-range', callback)
150152
}
151153

152154
/**
@@ -160,7 +162,7 @@ export default class DecorationManagement {
160162
* @return {Disposable} a disposable to stop listening to the event
161163
*/
162164
onDidUpdateDecoration (callback) {
163-
return this.minimap.emitter.on('did-update-decoration', callback)
165+
return this.emitter.on('did-update-decoration', callback)
164166
}
165167

166168
/**
@@ -357,7 +359,7 @@ export default class DecorationManagement {
357359
if (decorations !== undefined) {
358360
for (let i = 0, len = decorations.length; i < len; i++) {
359361
const decoration = decorations[i]
360-
this.minimap.emitter.emit('did-change-decoration', {
362+
this.emitter.emit('did-change-decoration', {
361363
marker,
362364
decoration,
363365
event
@@ -416,7 +418,7 @@ export default class DecorationManagement {
416418
}))
417419

418420
this.emitDecorationChanges(type, decoration)
419-
this.minimap.emitter.emit('did-add-decoration', {
421+
this.emitter.emit('did-add-decoration', {
420422
marker,
421423
decoration
422424
})
@@ -470,7 +472,7 @@ export default class DecorationManagement {
470472
type
471473
}
472474

473-
this.minimap.emitter.emit('did-change-decoration-range', changeEvent)
475+
this.emitter.emit('did-change-decoration-range', changeEvent)
474476
}
475477

476478
/**
@@ -506,7 +508,7 @@ export default class DecorationManagement {
506508
if (index > -1) {
507509
decorations.splice(index, 1)
508510

509-
this.minimap.emitter.emit('did-remove-decoration', {
511+
this.emitter.emit('did-remove-decoration', {
510512
marker,
511513
decoration
512514
})
@@ -536,7 +538,7 @@ export default class DecorationManagement {
536538
if (!this.minimap.editorDestroyed()) {
537539
this.emitDecorationChanges(decoration.getProperties().type, decoration)
538540
}
539-
this.minimap.emitter.emit('did-remove-decoration', {
541+
this.emitter.emit('did-remove-decoration', {
540542
marker,
541543
decoration
542544
})

0 commit comments

Comments
 (0)