Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #329 from carteb/iframe-client
Browse files Browse the repository at this point in the history
Split client into client and iframe client
  • Loading branch information
nikgraf authored Jun 12, 2016
2 parents 85e8ee5 + 1d1b7d1 commit a01f774
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 68 deletions.
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ npm-debug.log.*
dist
stats.json
webpack-plugin/src/assets/client-bundle.js
webpack-plugin/src/client-bundle.js
webpack-plugin/src/assets/main.css
webpack-plugin/src/main.css
webpack-plugin/src/assets/iframe-client-bundle.js
webpack-plugin/src/assets/client.css
webpack-plugin/dist
client/user-bundle.js

Expand Down
100 changes: 41 additions & 59 deletions client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,70 +13,52 @@ import Plugins from './components/Plugins';
import App from './components/App';
import FourOhFour from './components/FourOhFour';
import map from 'lodash/map';
import find from 'lodash/find';
import createNavigationStore from './navigationStore';

if (window.frameElement) {
// in iframe
window.$INITIALIZE_COMPONENT_GUI = function initializeComponentGui(components) {
const componentData = components[window.COMPONENT_PATH];
let Component = componentData.getCompiledComponent();
if (Component.default) {
Component = Component.default;
}
const activePlugin = find(componentData.getMeta(), (plugin) => plugin.name === 'react');
let rootElement;
window.$INITIALIZE_COMPONENT_GUI = function initializeComponentGui(components) {
if (rootElement) {
rootElement.forceUpdate();
return;
}

ReactDOM.render(
(activePlugin.frontendPlugin(Component)),
document.getElementById('root')
);
};
} else {
let rootElement;
window.$INITIALIZE_COMPONENT_GUI = function initializeComponentGui(components) {
if (rootElement) {
rootElement.forceUpdate();
return;
}
const navigationStore = createNavigationStore(components);

const navigationStore = createNavigationStore(components);
// Generate a view per user component that renders the frontend part of the
// plugins for each component
const routes = map(components, (component, componentPath) => (
<Route
key={componentPath}
path={componentPath}
component={() => (
<Plugins
componentPath={componentPath}
componentData={component}
navigationStore={navigationStore}
/>
)}
/>
));

// Generate a view per user component that renders the frontend part of the
// plugins for each component
const routes = map(components, (component, componentPath) => (
const appRoute = (<Route
path="/"
component={(props) => (
<App {...props} navigationStore={navigationStore} />
)}
>
{routes}
</Route>);

rootElement = ReactDOM.render(
(<Router history={hashHistory}>
{appRoute}
<Route
key={componentPath}
path={componentPath}
component={() => (
<Plugins
componentPath={componentPath}
componentData={component}
navigationStore={navigationStore}
/>
path="*"
component={(props) => (
<FourOhFour {...props} navigationStore={navigationStore} />
)}
/>
));

const appRoute = (<Route
path="/"
component={(props) => (
<App {...props} navigationStore={navigationStore} />
)}
>
{routes}
</Route>);

rootElement = ReactDOM.render(
(<Router history={hashHistory}>
{appRoute}
<Route
path="*"
component={(props) => (
<FourOhFour {...props} navigationStore={navigationStore} />
)}
/>
</Router>),
document.getElementById('carte-blanche-root')
);
};
}
</Router>),
document.getElementById('carte-blanche-root')
);
};
20 changes: 20 additions & 0 deletions client/iframe-client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Main entry point for the CarteBlanche iframes
*/

import ReactDOM from 'react-dom';
import find from 'lodash/find';

window.$INITIALIZE_COMPONENT_GUI = function initializeComponentGui(components) {
const componentData = components[window.COMPONENT_PATH];
let Component = componentData.getCompiledComponent();
if (Component.default) {
Component = Component.default;
}
const activePlugin = find(componentData.getMeta(), (plugin) => plugin.name === 'react');

ReactDOM.render(
(activePlugin.frontendPlugin(Component)),
document.getElementById('root')
);
};
9 changes: 5 additions & 4 deletions client/webpack.prod.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ export default {
devtool: 'eval',
output: {
path: path.join(__dirname, '../webpack-plugin/src/assets/'),
filename: 'client-bundle.js',
filename: '[name]-bundle.js',
publicPath: '/',
},
entry: [
path.join(__dirname, './client.js'),
],
entry: {
client: path.join(__dirname, './client.js'),
'iframe-client': path.join(__dirname, './iframe-client.js'),
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
Expand Down
2 changes: 1 addition & 1 deletion plugins/react/frontend/components/common/IFrame/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const createHtml = (componentPath, dest, userFiles, injectTags, commonsChunkFile
<script>
${userFiles && userFiles.scripts.join('\n')}
</script>
<script src="${(dest) ? `/${path.join(dest, 'client-bundle.js')}` : 'client-bundle.js'}"></script>
<script src="${(dest) ? `/${path.join(dest, 'iframe-client-bundle.js')}` : 'iframe-client-bundle.js'}"></script>
<script src="${(dest) ? `/${path.join(dest, 'user-bundle.js')}` : 'user-bundle.js'}"></script>
</body>
</html>
Expand Down
5 changes: 4 additions & 1 deletion webpack-plugin/src/apply.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ function apply(compiler) {
const clientAssets = {
'index.html': createHTML({ dest, commonsChunkFilename }),
'client-bundle.js': fs.readFileSync(path.resolve(__dirname, './assets/client-bundle.js')),
'client-bundle.css': fs.readFileSync(path.resolve(__dirname, './assets/main.css')),
'client-bundle.css': fs.readFileSync(path.resolve(__dirname, './assets/client.css')),
'iframe-client-bundle.js': fs.readFileSync(
path.resolve(__dirname, './assets/iframe-client-bundle.js')
),
};

compiler.plugin('emit', (compilation, callback) => {
Expand Down

0 comments on commit a01f774

Please sign in to comment.