Skip to content

Commit

Permalink
🐎 Register to styles changes only after being attached
Browse files Browse the repository at this point in the history
It limits the amount of events an element receives on startup.
  • Loading branch information
abe33 committed Apr 2, 2015
1 parent 383000b commit f466703
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lib/minimap-element.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,6 @@ class MinimapElement extends HTMLElement
@subscriptions = new CompositeDisposable
@initializeContent()

# Uses of `atom.styles.onDidAddStyleElement` instead of
# `atom.themes.onDidChangeActiveThemes`.
# Why?
# Currently, The styleElement will be removed first,
# and then re-add. So the `change` event has not be triggered.
@subscriptions.add atom.styles.onDidAddStyleElement =>
@invalidateCache()
@requestForcedUpdate()

@observeConfig
'minimap.displayMinimapOnLeft': (displayMinimapOnLeft) =>
swapPosition = @minimap? and displayMinimapOnLeft isnt @displayMinimapOnLeft
Expand Down Expand Up @@ -89,6 +80,15 @@ class MinimapElement extends HTMLElement
@measureHeightAndWidth()
@attached = true

# Uses of `atom.styles.onDidAddStyleElement` instead of
# `atom.themes.onDidChangeActiveThemes`.
# Why?
# Currently, The styleElement will be removed first,
# and then re-add. So the `change` event has not be triggered.
@subscriptions.add atom.styles.onDidAddStyleElement =>
@invalidateCache()
@requestForcedUpdate()

# Internal: DOM callback invoked when a new {MinimapElement} is detached
# from the DOM.
detachedCallback: ->
Expand Down

0 comments on commit f466703

Please sign in to comment.