Skip to content

Commit

Permalink
Implement minimap element destruction
Browse files Browse the repository at this point in the history
  • Loading branch information
abe33 committed Dec 17, 2014
1 parent cf61a8e commit 6008181
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/minimap-element.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,18 @@ class MinimapElement extends HTMLElement
detach: ->
return unless @attached
return unless @parentNode?

@parentNode.removeChild(this)

destroy: ->
@subscriptions.dispose()
@detach()

getModel: -> @minimap

setModel: (@minimap) ->
@subscriptions.add @minimap.onDidChangeScrollTop => @requestUpdate()
@subscriptions.add @minimap.onDidChangeScrollLeft => @requestUpdate()
@subscriptions.add @minimap.onDidDestroy => @destroy()
@subscriptions.add @minimap.onDidChangeConfig =>
@requestForcedUpdate() if @attached
@subscriptions.add @minimap.onDidChange (change) =>
Expand Down Expand Up @@ -185,7 +189,7 @@ class MinimapElement extends HTMLElement
@requestUpdate()

update: ->
return unless @attached and @isVisible()
return unless @attached and @isVisible() and not @minimap.isDestroyed()

if @adjustToSoftWrap
@style.marginRight = @marginRight + 'px'
Expand Down
22 changes: 22 additions & 0 deletions spec/minimap-element-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,28 @@ describe 'MinimapElement', ->
expect(minimapElement.canvas.width).toEqual(canvasWidth)
expect(minimapElement.canvas.height).toEqual(canvasHeight)

# ######## ######## ###### ######## ######## ####### ## ##
# ## ## ## ## ## ## ## ## ## ## ## ##
# ## ## ## ## ## ## ## ## ## ####
# ## ## ###### ###### ## ######## ## ## ##
# ## ## ## ## ## ## ## ## ## ##
# ## ## ## ## ## ## ## ## ## ## ##
# ######## ######## ###### ## ## ## ####### ##

describe 'when the model is destroyed', ->
beforeEach ->
minimap.destroy()

it 'detaches itself from its parent', ->
expect(minimapElement.parentNode).toBeNull()

it 'stops the DOM polling interval', ->
spyOn(minimapElement, 'pollDOM')

advanceClock(200)

expect(minimapElement.pollDOM).not.toHaveBeenCalled()

# ###### ####### ## ## ######## #### ######
# ## ## ## ## ### ## ## ## ## ##
# ## ## ## #### ## ## ## ##
Expand Down

0 comments on commit 6008181

Please sign in to comment.