Skip to content

Commit

Permalink
fix: lazy load Main because of race conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Dec 25, 2020
1 parent 927cc1e commit 948f642
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/minimap-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ const include = require('./decorators/include')
const element = require('./decorators/element')
const elementResizeDetector = require('element-resize-detector')({ strategy: 'scroll' })
const MinimapQuickSettingsElement = require('./minimap-quick-settings-element')
const Main = require('./main')

let overlayStyle
let Main // TODO: lazy loaded because of race confitions

const ensureOverlayStyle = () => {
if (!overlayStyle) {
Expand Down Expand Up @@ -682,6 +682,8 @@ class MinimapElement {
* @return {Minimap} this element's Minimap
*/
setModel (minimap) {
if (!Main) { Main = require('./main') }

this.minimap = minimap
this.subscriptions.add(this.minimap.onDidChangeScrollTop(() => {
this.requestUpdate()
Expand Down
6 changes: 5 additions & 1 deletion lib/mixins/canvas-drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

const _ = require('underscore-plus')
const Mixin = require('mixto')
const Main = require('../main')

const CanvasLayer = require('../canvas-layer')

let Main // TODO: lazy loaded because of race confitions

/**
* The `CanvasDrawer` mixin is responsible for the rendering of a `Minimap`
* in a `canvas` element.
Expand Down Expand Up @@ -326,6 +328,7 @@ module.exports = class CanvasDrawer extends Mixin {
*/
drawBackDecorationsForLines (firstRow, lastRow, offsetRow) {
if (firstRow > lastRow) { return }
if (!Main) { Main = require('../main') }

const devicePixelRatio = this.minimap.getDevicePixelRatio()
const lineHeight = this.minimap.getLineHeight() * devicePixelRatio
Expand Down Expand Up @@ -372,6 +375,7 @@ module.exports = class CanvasDrawer extends Mixin {
*/
drawFrontDecorationsForLines (firstRow, lastRow, offsetRow) {
if (firstRow > lastRow) { return }
if (!Main) { Main = require('../main') }

const devicePixelRatio = this.minimap.getDevicePixelRatio()
const lineHeight = this.minimap.getLineHeight() * devicePixelRatio
Expand Down

0 comments on commit 948f642

Please sign in to comment.