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

Decoupled renderer #173

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
c96a277
chore: updated webpack config to allow multiple compilers
lucasconstantino May 12, 2019
826cc54
feat: added initial decoupled build
lucasconstantino May 12, 2019
b3ea00c
chore: renamed decoupled build file name to allow dev version
lucasconstantino May 12, 2019
38eded5
feat: updated AppProvider to accept initialConfig as prop
lucasconstantino May 13, 2019
0ef15b1
feat: exposed AppProvider on decoupled bundle
lucasconstantino May 13, 2019
a7b5d6d
style: formatted TreeContainer code
lucasconstantino May 13, 2019
61b1019
feat: added registry override possibility
lucasconstantino May 13, 2019
7747ad1
feat: updated redux store creation to allow multiple instances
lucasconstantino May 13, 2019
2c1adca
chore: updated builds
lucasconstantino May 14, 2019
056e2ae
chore: updated entrypoint
lucasconstantino May 22, 2019
29cb3d1
chore: ignore linting on build dir
lucasconstantino May 23, 2019
ba68e84
chore: updated bundles
lucasconstantino Jun 24, 2019
806e0ad
chore: always use .min. name
lucasconstantino Jun 24, 2019
94f402c
chore: updated layout crawling to enter component props
lucasconstantino Jun 24, 2019
8364114
chore: updated bundles
lucasconstantino Jun 24, 2019
7ff5088
feat: fixed state on proxy component (ExtraProps)
lucasconstantino Jun 24, 2019
ea79392
feat: fixed nested proxy component state (ExtraProps)
lucasconstantino Jun 24, 2019
09f4dc7
chore: fixed nestedId crawling on TreeContainer
lucasconstantino Jun 24, 2019
129428a
chore: updated bundles
lucasconstantino Jun 24, 2019
eac97ac
feat: allow sub-prop modification on Input/Output/State
lucasconstantino Jul 3, 2019
65011b1
chore: updated bundles
lucasconstantino Jul 3, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions dash_renderer/dash_renderer.commonjs.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dash_renderer/dash_renderer.commonjs.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.23.0",
"description": "render dash components in react",
"main": "src/index.js",
"module": "dash_renderer/dash_renderer.commonjs.js",
"scripts": {
"lint": "./node_modules/.bin/eslint --quiet --fix .",
"lint:test": "./node_modules/.bin/eslint .",
Expand Down
5 changes: 3 additions & 2 deletions src/AppContainer.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class UnconnectedAppContainer extends React.Component {
}

componentWillMount() {
const {dispatch} = this.props;
dispatch(readConfig());
const {dispatch, initialConfig} = this.props;
dispatch(readConfig({config: initialConfig}));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move || JSON.parse(document.getElementById('_dash-config').textContent) up here. We never should have put that in the reducer in the first place, but with the extra logic it's even more out of place.

Also the extra nesting is unnecessary, can't we just do readConfig(initialConfig || ...)?

}

render() {
Expand All @@ -46,6 +46,7 @@ UnconnectedAppContainer.propTypes = {
hooks: PropTypes.object,
dispatch: PropTypes.func,
config: PropTypes.object,
initialConfig: PropTypes.object,
};

const AppContainer = connect(
Expand Down
5 changes: 3 additions & 2 deletions src/AppProvider.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import PropTypes from 'prop-types';

const store = initializeStore();

const AppProvider = ({hooks}) => {
const AppProvider = ({hooks, initialConfig}) => {
return (
<Provider store={store}>
<AppContainer hooks={hooks} />
<AppContainer hooks={hooks} initialConfig={initialConfig} />
</Provider>
);
};
Expand All @@ -21,6 +21,7 @@ AppProvider.propTypes = {
request_pre: PropTypes.func,
request_post: PropTypes.func,
}),
initialConfig: PropTypes.object,
};

AppProvider.defaultProps = {
Expand Down
4 changes: 4 additions & 0 deletions src/decoupled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* eslint-env browser */

'use strict';
export {DashRenderer} from './DashRenderer';
5 changes: 4 additions & 1 deletion src/reducers/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import {getAction} from '../actions/constants';

export default function config(state = null, action) {
if (action.type === getAction('READ_CONFIG')) {
return JSON.parse(document.getElementById('_dash-config').textContent);
return (
action.payload.config ||
JSON.parse(document.getElementById('_dash-config').textContent)
);
}
return state;
}
142 changes: 81 additions & 61 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const packagejson = require('./package.json');

const dashLibraryName = packagejson.name.replace(/-/g, '_');

module.exports = (env, argv) => {
const getMode = (env, argv) => {
let mode;

// if user specified mode flag take that value
Expand All @@ -21,66 +21,86 @@ module.exports = (env, argv) => {
else {
mode = 'production';
}
return {
entry: {main: ['@babel/polyfill', 'whatwg-fetch', './src/index.js']},
output: {
path: path.resolve(__dirname, dashLibraryName),
filename:
mode === 'development'
? `${dashLibraryName}.dev.js`
: `${dashLibraryName}.min.js`,
library: dashLibraryName,
libraryTarget: 'window',
},
devtool: 'source-map',
externals: {
react: 'React',
'react-dom': 'ReactDOM',
'plotly.js': 'Plotly',
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
},
{
test: /\.css$/,
use: [
{
loader: 'style-loader',
},
{
loader: 'css-loader',
},
],
},
{
test: /\.svg$/,
use: ['@svgr/webpack']
},
{
test: /\.txt$/i,
use: 'raw-loader',

return mode;
};

const common = (env, argv) => ({
devtool: 'source-map',
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
],
},
plugins: [
new webpack.NormalModuleReplacementPlugin(
/(.*)GlobalErrorContainer.react(\.*)/,
function(resource) {
if (mode === 'production') {
resource.request = resource.request.replace(
/GlobalErrorContainer.react/,
'GlobalErrorContainerPassthrough.react'
);
}
}
),
},
{
test: /\.css$/,
use: [
{
loader: 'style-loader',
},
{
loader: 'css-loader',
},
],
},
{
test: /\.svg$/,
use: ['@svgr/webpack'],
},
{
test: /\.txt$/i,
use: 'raw-loader',
},
],
};
};
},
plugins: [
new webpack.NormalModuleReplacementPlugin(
/(.*)GlobalErrorContainer.react(\.*)/,
function(resource) {
if (getMode(env, argv) === 'production') {
resource.request = resource.request.replace(
/GlobalErrorContainer.react/,
'GlobalErrorContainerPassthrough.react'
);
}
}
),
],
});

const standalone = (env, argv) => ({
...common(env, argv),
name: 'standalone',
entry: {main: ['@babel/polyfill', 'whatwg-fetch', './src/index.js']},
output: {
path: path.resolve(__dirname, dashLibraryName),
filename:
getMode(env, argv) === 'development'
? `${dashLibraryName}.dev.js`
: `${dashLibraryName}.min.js`,
library: dashLibraryName,
libraryTarget: 'window',
},
externals: {
react: 'React',
'react-dom': 'ReactDOM',
'plotly.js': 'Plotly',
},
});

const decoupled = (env, argv) => ({
...common(env, argv),
name: 'decoupled',
entry: './src/decoupled.js',
output: {
path: path.resolve(__dirname, dashLibraryName),
filename: `${dashLibraryName}.commonjs.js`,
libraryTarget: 'commonjs2',
},
});

module.exports = [standalone, decoupled];