Skip to content

Commit 84a026f

Browse files
authored
Merge pull request atom#22750 from atom/use-custom-elements-pane-container
Use custom element on pane container element
2 parents 91c3a69 + 5799920 commit 84a026f

File tree

3 files changed

+39
-30
lines changed

3 files changed

+39
-30
lines changed

spec/pane-container-element-spec.js

+22-23
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ describe('PaneContainerElement', function() {
4242
]);
4343

4444
paneAxis.removeChild(paneAxis.getChildren()[2]);
45-
return expect(childTagNames()).toEqual([
45+
expect(childTagNames()).toEqual([
4646
'atom-pane-axis',
4747
'atom-pane-resize-handle',
4848
'atom-pane-axis'
4949
]);
5050
});
5151

52-
return it('transfers focus to the next pane if a focused pane is removed', function() {
52+
it('transfers focus to the next pane if a focused pane is removed', function() {
5353
const container = new PaneContainer(params);
5454
const containerElement = container.getElement();
5555
const leftPane = container.getActivePane();
@@ -62,7 +62,8 @@ describe('PaneContainerElement', function() {
6262
expect(document.activeElement).toBe(rightPaneElement);
6363

6464
rightPane.destroy();
65-
return expect(document.activeElement).toBe(leftPaneElement);
65+
expect(containerElement).toHaveClass('panes');
66+
expect(document.activeElement).toBe(leftPaneElement);
6667
});
6768
});
6869

@@ -94,7 +95,7 @@ describe('PaneContainerElement', function() {
9495
);
9596
expect(verticalPanes.length).toBe(2);
9697
expect(verticalPanes[0]).toBe(pane2.getElement());
97-
return expect(verticalPanes[1]).toBe(pane3.getElement());
98+
expect(verticalPanes[1]).toBe(pane3.getElement());
9899
}));
99100

100101
describe('when the resize element is dragged ', function() {
@@ -103,9 +104,7 @@ describe('PaneContainerElement', function() {
103104
beforeEach(function() {
104105
container = new PaneContainer(params);
105106
containerElement = container.getElement();
106-
return document
107-
.querySelector('#jasmine-content')
108-
.appendChild(containerElement);
107+
document.querySelector('#jasmine-content').appendChild(containerElement);
109108
});
110109

111110
const dragElementToPosition = function(element, clientX) {
@@ -125,7 +124,7 @@ describe('PaneContainerElement', function() {
125124
})
126125
);
127126

128-
return element.dispatchEvent(
127+
element.dispatchEvent(
129128
new MouseEvent('mouseup', {
130129
iew: window,
131130
bubbles: true,
@@ -180,7 +179,7 @@ describe('PaneContainerElement', function() {
180179
runs(() => expectPaneScale([leftPane, 0.44], [rightPane, 1.55]));
181180

182181
waitsForPromise(() => leftPane.close());
183-
return runs(() => expectPaneScale([rightPane, 1]));
182+
runs(() => expectPaneScale([rightPane, 1]));
184183
});
185184

186185
it('splits or closes panes in orthogonal direction that the pane is being dragged', function() {
@@ -206,7 +205,7 @@ describe('PaneContainerElement', function() {
206205

207206
// dynamically close pane, the pane's flexscale will recover to origin value
208207
waitsForPromise(() => lowerPane.close());
209-
return runs(() => expectPaneScale([leftPane, 0.5], [rightPane, 1.5]));
208+
runs(() => expectPaneScale([leftPane, 0.5], [rightPane, 1.5]));
210209
});
211210

212211
it('unsubscribes from mouse events when the pane is detached', function() {
@@ -226,19 +225,19 @@ describe('PaneContainerElement', function() {
226225

227226
waitsFor(() => document.addEventListener.callCount === 2);
228227

229-
return runs(function() {
228+
runs(function() {
230229
expect(element.resizeStopped.callCount).toBe(0);
231230
container.destroy();
232231
expect(element.resizeStopped.callCount).toBe(1);
233-
return expect(document.removeEventListener.callCount).toBe(2);
232+
expect(document.removeEventListener.callCount).toBe(2);
234233
});
235234
});
236235

237-
return it('does not throw an error when resized to fit content in a detached state', function() {
236+
it('does not throw an error when resized to fit content in a detached state', function() {
238237
container.getActivePane().splitRight();
239238
const element = getResizeElement(0);
240239
element.remove();
241-
return expect(() => element.resizeToFitContent()).not.toThrow();
240+
expect(() => element.resizeToFitContent()).not.toThrow();
242241
});
243242
});
244243

@@ -248,7 +247,7 @@ describe('PaneContainerElement', function() {
248247
beforeEach(function() {
249248
const container = new PaneContainer(params);
250249
leftPane = container.getActivePane();
251-
return (rightPane = leftPane.splitRight());
250+
rightPane = leftPane.splitRight();
252251
});
253252

254253
describe('when pane:increase-size is triggered', () =>
@@ -262,10 +261,10 @@ describe('PaneContainerElement', function() {
262261

263262
atom.commands.dispatch(rightPane.getElement(), 'pane:increase-size');
264263
expect(leftPane.getFlexScale()).toBe(1.1);
265-
return expect(rightPane.getFlexScale()).toBe(1.1);
264+
expect(rightPane.getFlexScale()).toBe(1.1);
266265
}));
267266

268-
return describe('when pane:decrease-size is triggered', () =>
267+
describe('when pane:decrease-size is triggered', () =>
269268
it('decreases the size of the pane', function() {
270269
expect(leftPane.getFlexScale()).toBe(1);
271270
expect(rightPane.getFlexScale()).toBe(1);
@@ -276,16 +275,16 @@ describe('PaneContainerElement', function() {
276275

277276
atom.commands.dispatch(rightPane.getElement(), 'pane:decrease-size');
278277
expect(leftPane.getFlexScale()).toBe(1 / 1.1);
279-
return expect(rightPane.getFlexScale()).toBe(1 / 1.1);
278+
expect(rightPane.getFlexScale()).toBe(1 / 1.1);
280279
}));
281280
});
282281

283-
return describe('when only a single pane is present', function() {
282+
describe('when only a single pane is present', function() {
284283
let [singlePane] = [];
285284

286285
beforeEach(function() {
287286
const container = new PaneContainer(params);
288-
return (singlePane = container.getActivePane());
287+
singlePane = container.getActivePane();
289288
});
290289

291290
describe('when pane:increase-size is triggered', () =>
@@ -296,18 +295,18 @@ describe('PaneContainerElement', function() {
296295
expect(singlePane.getFlexScale()).toBe(1);
297296

298297
atom.commands.dispatch(singlePane.getElement(), 'pane:increase-size');
299-
return expect(singlePane.getFlexScale()).toBe(1);
298+
expect(singlePane.getFlexScale()).toBe(1);
300299
}));
301300

302-
return describe('when pane:decrease-size is triggered', () =>
301+
describe('when pane:decrease-size is triggered', () =>
303302
it('does not decreases the size of the pane', function() {
304303
expect(singlePane.getFlexScale()).toBe(1);
305304

306305
atom.commands.dispatch(singlePane.getElement(), 'pane:decrease-size');
307306
expect(singlePane.getFlexScale()).toBe(1);
308307

309308
atom.commands.dispatch(singlePane.getElement(), 'pane:decrease-size');
310-
return expect(singlePane.getFlexScale()).toBe(1);
309+
expect(singlePane.getFlexScale()).toBe(1);
311310
}));
312311
});
313312
});

src/pane-container-element.js

+15-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
const { CompositeDisposable } = require('event-kit');
22

33
class PaneContainerElement extends HTMLElement {
4-
createdCallback() {
4+
constructor() {
5+
super();
56
this.subscriptions = new CompositeDisposable();
6-
this.classList.add('panes');
77
}
88

99
initialize(model, { views }) {
@@ -18,6 +18,10 @@ class PaneContainerElement extends HTMLElement {
1818
return this;
1919
}
2020

21+
connectedCallback() {
22+
this.classList.add('panes');
23+
}
24+
2125
rootChanged(root) {
2226
const focusedElement = this.hasFocus() ? document.activeElement : null;
2327
if (this.firstChild != null) {
@@ -39,6 +43,12 @@ class PaneContainerElement extends HTMLElement {
3943
}
4044
}
4145

42-
module.exports = document.registerElement('atom-pane-container', {
43-
prototype: PaneContainerElement.prototype
44-
});
46+
window.customElements.define('atom-pane-container', PaneContainerElement);
47+
48+
function createPaneContainerElement() {
49+
return document.createElement('atom-pane-container');
50+
}
51+
52+
module.exports = {
53+
createPaneContainerElement
54+
};

src/pane-container.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const { find } = require('underscore-plus');
22
const { Emitter, CompositeDisposable } = require('event-kit');
33
const Pane = require('./pane');
44
const ItemRegistry = require('./item-registry');
5-
const PaneContainerElement = require('./pane-container-element');
5+
const { createPaneContainerElement } = require('./pane-container-element');
66

77
const SERIALIZATION_VERSION = 1;
88
const STOPPED_CHANGING_ACTIVE_PANE_ITEM_DELAY = 100;
@@ -44,7 +44,7 @@ module.exports = class PaneContainer {
4444
getElement() {
4545
return this.element != null
4646
? this.element
47-
: (this.element = new PaneContainerElement().initialize(this, {
47+
: (this.element = createPaneContainerElement().initialize(this, {
4848
views: this.viewRegistry
4949
}));
5050
}

0 commit comments

Comments
 (0)