Skip to content

Commit ecf2116

Browse files
committed
Created a proper custom element out of rnacentral-sequence-search.
1 parent b721396 commit ecf2116

File tree

5 files changed

+52
-19
lines changed

5 files changed

+52
-19
lines changed

package-lock.json

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"babel-core": "^6.25.0",
6060
"babel-jest": "^23.6.0",
6161
"babel-loader": "^7.1.1",
62+
"babel-plugin-transform-custom-element-classes": "^0.1.0",
6263
"babel-plugin-transform-es2015-destructuring": "^6.23.0",
6364
"babel-plugin-transform-object-rest-spread": "^6.26.0",
6465
"babel-preset-es2015": "^6.24.1",

src/app.jsx

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,45 @@ export const databases = ['mirbase'];
3030
// reactRoot
3131
// );
3232

33-
const proto = Object.create(HTMLElement.prototype, {
34-
attachedCallback: {
35-
value: function() {
36-
const mountPoint = document.createElement('div');
37-
const shadowRoot = this.createShadowRoot();
38-
shadowRoot.appendChild(mountPoint);
39-
ReactDOM.render([
40-
<link key='styles' href="RNAcentral-sequence-search.css" rel="stylesheet" />,
41-
<Provider key='provider' store={store}>
42-
<SequenceSearch databases={databases}/>
43-
</Provider>],
44-
mountPoint
45-
);
46-
retargetEvents(shadowRoot);
47-
}
33+
34+
class RNAcentralSequenceSearch extends HTMLElement {
35+
constructor() {
36+
super();
37+
38+
const mountPoint = document.createElement('div');
39+
const shadowRoot = this.attachShadow({mode: 'open'});
40+
shadowRoot.appendChild(mountPoint);
41+
ReactDOM.render([
42+
<link key='styles' href="RNAcentral-sequence-search.css" rel="stylesheet" />,
43+
<Provider key='provider' store={store}>
44+
<SequenceSearch databases={databases}/>
45+
</Provider>],
46+
mountPoint
47+
);
48+
retargetEvents(shadowRoot);
4849
}
49-
});
50+
}
51+
52+
customElements.define('rnacentral-sequence-search', RNAcentralSequenceSearch);
53+
54+
55+
56+
// const proto = Object.create(HTMLElement.prototype, {
57+
// attachedCallback: {
58+
// value: function() {
59+
// const mountPoint = document.createElement('div');
60+
// const shadowRoot = this.createShadowRoot();
61+
// shadowRoot.appendChild(mountPoint);
62+
// ReactDOM.render([
63+
// <link key='styles' href="RNAcentral-sequence-search.css" rel="stylesheet" />,
64+
// <Provider key='provider' store={store}>
65+
// <SequenceSearch databases={databases}/>
66+
// </Provider>],
67+
// mountPoint
68+
// );
69+
// retargetEvents(shadowRoot);
70+
// }
71+
// }
72+
// });
5073

51-
document.registerElement('RNAcentral-sequence-search', {prototype: proto});
74+
// document.registerElement('RNAcentral-sequence-search', {prototype: proto});

src/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@
3434
<meta name="msapplication-TileImage" content="//www.ebi.ac.uk/web_guidelines/EBI-Framework/v1.2/images/logos/EMBL-EBI/favicons/mstile-144x144.png" />
3535
</head>
3636
<body class="level2">
37-
<RNAcentral-sequence-search />
37+
<rnacentral-sequence-search />
3838
</body>
3939
</html>

webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module.exports = function(env) {
4141
exclude: /node_modules/,
4242
query: {
4343
presets: ['es2015', 'react'],
44-
plugins: ['transform-es2015-destructuring', 'transform-object-rest-spread']
44+
plugins: ['transform-es2015-destructuring', 'transform-object-rest-spread', 'transform-custom-element-classes']
4545
}
4646
},
4747
{

0 commit comments

Comments
 (0)