From 2b218d2e01ea608132dbd871cb4b00dcd5c2def2 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 15 Oct 2014 12:30:53 -0600 Subject: [PATCH] Only update atom-styles children on context attribute change if attached --- src/styles-element.coffee | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/styles-element.coffee b/src/styles-element.coffee index 8c97f2d44..309ac5065 100644 --- a/src/styles-element.coffee +++ b/src/styles-element.coffee @@ -1,6 +1,8 @@ {Emitter, CompositeDisposable} = require 'event-kit' class StylesElement extends HTMLElement + attached: false + createdCallback: -> @emitter = new Emitter @styleElementClonesByOriginalElement = new WeakMap @@ -19,11 +21,17 @@ class StylesElement extends HTMLElement @emitter.on 'did-update-style-element', callback attachedCallback: -> + @attached = true + @subscriptions = new CompositeDisposable @subscriptions.add atom.styles.observeStyleElements(@styleElementAdded.bind(this)) @subscriptions.add atom.styles.onDidRemoveStyleElement(@styleElementRemoved.bind(this)) @subscriptions.add atom.styles.onDidUpdateStyleElement(@styleElementUpdated.bind(this)) + detachedCallback: -> + @attached = false + @subscriptions.dispose() + styleElementAdded: (styleElement) -> return unless styleElement.context is @context @@ -56,11 +64,9 @@ class StylesElement extends HTMLElement @emitter.emit 'did-update-style-element', styleElementClone contextChanged: -> - @styleElementRemoved(child) for child in Array::slice.call(@children) @context = @getAttribute('context') - @styleElementAdded(styleElement) for styleElement in atom.styles.getStyleElements() - - detachedCallback: -> - @subscriptions.dispose() + if @attached + @styleElementRemoved(child) for child in Array::slice.call(@children) + @styleElementAdded(styleElement) for styleElement in atom.styles.getStyleElements() module.exports = StylesElement = document.registerElement 'atom-styles', prototype: StylesElement.prototype