Skip to content

Commit 80888a9

Browse files
committed
Migrate to custom elements
document.registerElement will be deprecated which will make moving to later electrons imposible.
1 parent 311309a commit 80888a9

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

spec/styles-element-spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const StylesElement = require('../src/styles-element');
1+
const { createStylesElement } = require('../src/styles-element');
22

33
describe('StylesElement', function() {
44
let [
@@ -9,7 +9,7 @@ describe('StylesElement', function() {
99
] = [];
1010

1111
beforeEach(function() {
12-
element = new StylesElement();
12+
element = createStylesElement();
1313
element.initialize(atom.styles);
1414
document.querySelector('#jasmine-content').appendChild(element);
1515
addedStyleElements = [];

src/style-manager.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const fs = require('fs-plus');
44
const path = require('path');
55
const postcss = require('postcss');
66
const selectorParser = require('postcss-selector-parser');
7-
const StylesElement = require('./styles-element');
7+
const { createStylesElement } = require('./styles-element');
88
const DEPRECATED_SYNTAX_SELECTORS = require('./deprecated-syntax-selectors');
99

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

256256
buildStylesElement() {
257-
const stylesElement = new StylesElement();
257+
const stylesElement = createStylesElement();
258258
stylesElement.initialize(this);
259259
return stylesElement;
260260
}

src/styles-element.js

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ const { Emitter, CompositeDisposable } = require('event-kit');
33
class StylesElement extends HTMLElement {
44
constructor() {
55
super();
6-
this.subscriptions = null;
6+
this.subscriptions = new CompositeDisposable();
7+
this.emitter = new Emitter();
8+
this.styleElementClonesByOriginalElement = new WeakMap();
79
this.context = null;
810
}
911

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

22-
createdCallback() {
23-
this.subscriptions = new CompositeDisposable();
24-
this.emitter = new Emitter();
25-
this.styleElementClonesByOriginalElement = new WeakMap();
26-
}
27-
28-
attachedCallback() {
24+
connectedCallback() {
2925
let left;
3026
this.context =
3127
(left = this.getAttribute('context')) != null ? left : undefined;
3228
}
3329

34-
detachedCallback() {
30+
disconnectedCallback() {
3531
this.subscriptions.dispose();
3632
this.subscriptions = new CompositeDisposable();
3733
}
3834

35+
static get observedAttributes() {
36+
return ['context'];
37+
}
38+
3939
attributeChangedCallback(attrName) {
4040
if (attrName === 'context') {
4141
return this.contextChanged();
@@ -58,7 +58,7 @@ class StylesElement extends HTMLElement {
5858
this.styleElementRemoved.bind(this)
5959
)
6060
);
61-
return this.subscriptions.add(
61+
this.subscriptions.add(
6262
this.styleManager.onDidUpdateStyleElement(
6363
this.styleElementUpdated.bind(this)
6464
)
@@ -140,6 +140,12 @@ class StylesElement extends HTMLElement {
140140
}
141141
}
142142

143-
module.exports = document.registerElement('atom-styles', {
144-
prototype: StylesElement.prototype
145-
});
143+
window.customElements.define('atom-styles', StylesElement);
144+
145+
function createStylesElement() {
146+
return document.createElement('atom-styles');
147+
}
148+
149+
module.exports = {
150+
createStylesElement
151+
};

0 commit comments

Comments
 (0)