Only define MyElement when needed (#11069)

This commit is contained in:
Brandon Dail
2017-10-03 10:23:59 -07:00
committed by GitHub
parent 589c0a25df
commit f6a79d1f16
@@ -12,24 +12,23 @@ class HelloWorld extends React.Component {
}
}
// Babel breaks web components.
// https://github.com/w3c/webcomponents/issues/587
// eslint-disable-next-line no-new-func
const MyElement = new Function(
'React',
'ReactDOM',
'HelloWorld',
`
return class MyElement extends HTMLElement {
constructor() {
super();
const shadowRoot = this.attachShadow({ mode:'open' });
ReactDOM.render(React.createElement(HelloWorld), shadowRoot);
}
}`
)(React, ReactDOM, HelloWorld);
if (supportsCustomElements) {
// Babel breaks web components.
// https://github.com/w3c/webcomponents/issues/587
// eslint-disable-next-line no-new-func
const MyElement = new Function(
'React',
'ReactDOM',
'HelloWorld',
`
return class MyElement extends HTMLElement {
constructor() {
super();
const shadowRoot = this.attachShadow({ mode:'open' });
ReactDOM.render(React.createElement(HelloWorld), shadowRoot);
}
}`
)(React, ReactDOM, HelloWorld);
customElements.define('my-element', MyElement);
}