Skip to content

Commit b721396

Browse files
committed
Packaged component as a web component.
1 parent 3caebd9 commit b721396

File tree

5 files changed

+98
-15
lines changed

5 files changed

+98
-15
lines changed

package-lock.json

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

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"react-redux": "^5.0.7",
5252
"react-router": "^4.2.0",
5353
"react-router-dom": "^4.2.2",
54+
"react-shadow-dom-retarget-events": "^1.0.10",
5455
"redux": "^4.0.1",
5556
"redux-thunk": "^2.3.0"
5657
},
@@ -72,7 +73,7 @@
7273
"react-router-config": "^1.0.0-beta.4",
7374
"redux-devtools-extension": "^2.13.8",
7475
"sass-loader": "^6.0.6",
75-
"style-loader": "^0.18.2",
76+
"style-loader": "^0.23.1",
7677
"url-loader": "^0.5.9",
7778
"webpack": "^3.12.0",
7879
"webpack-dev-server": "^2.5.0"

src/app.jsx

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,51 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom';
3+
import retargetEvents from 'react-shadow-dom-retarget-events';
34
import {Provider} from 'react-redux';
45

56
import SequenceSearch from 'containers/SequenceSearch/index.jsx';
67
import configureStore from 'store/configureStore.js';
78

89

10+
// Prepare data
911
export const store = configureStore();
1012
export const databases = ['mirbase'];
13+
//
14+
// // Get the shadow root
15+
// const shadowHost = document.querySelector('div#sequence-search');
16+
// const shadowRoot = shadowHost.attachShadow({ mode: 'open' });
17+
//
18+
// // Create div element for react to render into
19+
// const reactRoot = document.createElement('div');
20+
// reactRoot.setAttribute('id', 'react-root');
21+
//
22+
// // Append react root to shadow root
23+
// shadowRoot.appendChild(reactRoot);
24+
//
25+
// // Render react
26+
// ReactDOM.render(
27+
// <Provider store={store}>
28+
// <SequenceSearch databases={databases}/>
29+
// </Provider>,
30+
// reactRoot
31+
// );
1132

12-
ReactDOM.render(
13-
<Provider store={store}>
14-
<SequenceSearch databases={databases}/>
15-
</Provider>,
16-
document.querySelector('div#sequence-search')
17-
);
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+
}
48+
}
49+
});
50+
51+
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-
<div id="sequence-search"></div>
37+
<RNAcentral-sequence-search />
3838
</body>
3939
</html>

webpack.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ module.exports = function(env) {
1818
output: {
1919
path: path.join(__dirname, 'dist'),
2020
publicPath: environment === 'production' ? '/rnacentral-sequence-search-embed/dist/' : '/',
21-
filename: 'app.[hash:7].js'
21+
filename: 'RNAcentral-sequence-search.js'
2222
},
2323
resolve: {
2424
modules: [path.join(__dirname, 'src'), path.join(__dirname, 'node_modules')]
2525
},
2626
plugins: [
2727
new webpack.HotModuleReplacementPlugin(),
28-
new ExtractTextPlugin('app.[hash:7].css'),
28+
new ExtractTextPlugin('RNAcentral-sequence-search.css'),
2929
new HtmlWebpackPlugin({
3030
inject: "body",
3131
template: "src/index.html",

0 commit comments

Comments
 (0)