Skip to content

Commit 2fcd6de

Browse files
update viz.js and redux-thunk usage (#1174)
1 parent 6d27808 commit 2fcd6de

File tree

2 files changed

+47
-19
lines changed

2 files changed

+47
-19
lines changed

dash-renderer/src/components/error/CallbackGraph/CallbackGraphContainer.react.js

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,34 @@
11
import React, {Component} from 'react';
22
import './CallbackGraphContainer.css';
33

4-
import viz from 'viz.js';
4+
import Viz from 'viz.js';
5+
import {Module, render} from 'viz.js/full.render';
56

67
import PropTypes from 'prop-types';
78

89
class CallbackGraphContainer extends Component {
910
constructor(props) {
1011
super(props);
12+
13+
this.viz = null;
14+
this.updateViz = this.updateViz.bind(this);
15+
}
16+
17+
componentDidMount() {
18+
this.updateViz();
19+
}
20+
21+
componentDidUpdate() {
22+
this.updateViz();
1123
}
24+
1225
render() {
26+
return <div className="dash-callback-dag--container" ref="el" />;
27+
}
28+
29+
updateViz() {
30+
this.viz = this.viz || new Viz({Module, render});
31+
1332
const {dependenciesRequest} = this.props;
1433
const elements = {};
1534
const callbacks = [];
@@ -55,14 +74,21 @@ class CallbackGraphContainer extends Component {
5574
5675
${links.join('\n')} }`;
5776

58-
return (
59-
<div
60-
className="dash-callback-dag--container"
61-
dangerouslySetInnerHTML={{
62-
__html: viz(dot, {format: 'svg'}),
63-
}}
64-
/>
65-
);
77+
const el = this.refs.el;
78+
79+
this.viz
80+
.renderSVGElement(dot)
81+
.then(vizEl => {
82+
el.innerHTML = '';
83+
el.appendChild(vizEl);
84+
})
85+
.catch(e => {
86+
// https://github.com/mdaines/viz.js/wiki/Caveats
87+
this.viz = new Viz({Module, render});
88+
// eslint-disable-next-line no-console
89+
console.error(e);
90+
el.innerHTML = 'Error creating callback graph';
91+
});
6692
}
6793
}
6894

dash-renderer/src/store.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,18 @@ const initializeStore = reset => {
1919

2020
const reducer = createReducer();
2121

22-
// only attach logger to middleware in non-production mode
23-
store =
24-
process.env.NODE_ENV === 'production' // eslint-disable-line no-process-env
25-
? createStore(reducer, applyMiddleware(thunk))
26-
: createStore(
27-
reducer,
28-
window.__REDUX_DEVTOOLS_EXTENSION__ &&
29-
window.__REDUX_DEVTOOLS_EXTENSION__(),
30-
applyMiddleware(thunk)
31-
);
22+
// eslint-disable-next-line no-process-env
23+
if (process.env.NODE_ENV === 'production') {
24+
store = createStore(reducer, applyMiddleware(thunk));
25+
} else {
26+
// only attach logger to middleware in non-production mode
27+
const reduxDTEC = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__;
28+
if (reduxDTEC) {
29+
store = createStore(reducer, reduxDTEC(applyMiddleware(thunk)));
30+
} else {
31+
store = createStore(reducer, applyMiddleware(thunk));
32+
}
33+
}
3234

3335
if (!reset) {
3436
// TODO - Protect this under a debug mode?

0 commit comments

Comments
 (0)