Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions spec/styles-element-spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const StylesElement = require('../src/styles-element');
const { createStylesElement } = require('../src/styles-element');

describe('StylesElement', function() {
let [
Expand All @@ -9,7 +9,7 @@ describe('StylesElement', function() {
] = [];

beforeEach(function() {
element = new StylesElement();
element = createStylesElement();
element.initialize(atom.styles);
document.querySelector('#jasmine-content').appendChild(element);
addedStyleElements = [];
Expand Down
4 changes: 2 additions & 2 deletions src/style-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const fs = require('fs-plus');
const path = require('path');
const postcss = require('postcss');
const selectorParser = require('postcss-selector-parser');
const StylesElement = require('./styles-element');
const { createStylesElement } = require('./styles-element');
const DEPRECATED_SYNTAX_SELECTORS = require('./deprecated-syntax-selectors');

// Extended: A singleton instance of this class available via `atom.styles`,
Expand Down Expand Up @@ -254,7 +254,7 @@ module.exports = class StyleManager {
}

buildStylesElement() {
const stylesElement = new StylesElement();
const stylesElement = createStylesElement();
stylesElement.initialize(this);
return stylesElement;
}
Expand Down
32 changes: 19 additions & 13 deletions src/styles-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ const { Emitter, CompositeDisposable } = require('event-kit');
class StylesElement extends HTMLElement {
constructor() {
super();
this.subscriptions = null;
this.subscriptions = new CompositeDisposable();
this.emitter = new Emitter();
this.styleElementClonesByOriginalElement = new WeakMap();
this.context = null;
}

Expand All @@ -19,23 +21,21 @@ class StylesElement extends HTMLElement {
this.emitter.on('did-update-style-element', callback);
}

createdCallback() {
this.subscriptions = new CompositeDisposable();
this.emitter = new Emitter();
this.styleElementClonesByOriginalElement = new WeakMap();
}

attachedCallback() {
connectedCallback() {
let left;
this.context =
(left = this.getAttribute('context')) != null ? left : undefined;
}

detachedCallback() {
disconnectedCallback() {
this.subscriptions.dispose();
this.subscriptions = new CompositeDisposable();
}

static get observedAttributes() {
return ['context'];
}

attributeChangedCallback(attrName) {
if (attrName === 'context') {
return this.contextChanged();
Expand All @@ -58,7 +58,7 @@ class StylesElement extends HTMLElement {
this.styleElementRemoved.bind(this)
)
);
return this.subscriptions.add(
this.subscriptions.add(
this.styleManager.onDidUpdateStyleElement(
this.styleElementUpdated.bind(this)
)
Expand Down Expand Up @@ -140,6 +140,12 @@ class StylesElement extends HTMLElement {
}
}

module.exports = document.registerElement('atom-styles', {
prototype: StylesElement.prototype
});
window.customElements.define('atom-styles', StylesElement);

function createStylesElement() {
return document.createElement('atom-styles');
}

module.exports = {
createStylesElement
};