Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update viz.js and redux-thunk usage #1174

Merged
merged 1 commit into from
Apr 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
import React, {Component} from 'react';
import './CallbackGraphContainer.css';

import viz from 'viz.js';
import Viz from 'viz.js';
import {Module, render} from 'viz.js/full.render';

import PropTypes from 'prop-types';

class CallbackGraphContainer extends Component {
constructor(props) {
super(props);

this.viz = null;
this.updateViz = this.updateViz.bind(this);
}

componentDidMount() {
this.updateViz();
}

componentDidUpdate() {
this.updateViz();
}

render() {
return <div className="dash-callback-dag--container" ref="el" />;
}

updateViz() {
this.viz = this.viz || new Viz({Module, render});

const {dependenciesRequest} = this.props;
const elements = {};
const callbacks = [];
Expand Down Expand Up @@ -55,14 +74,21 @@ class CallbackGraphContainer extends Component {

${links.join('\n')} }`;

return (
<div
className="dash-callback-dag--container"
dangerouslySetInnerHTML={{
__html: viz(dot, {format: 'svg'}),
}}
/>
);
const el = this.refs.el;

this.viz
.renderSVGElement(dot)
.then(vizEl => {
el.innerHTML = '';
el.appendChild(vizEl);
})
.catch(e => {
// https://github.com/mdaines/viz.js/wiki/Caveats
this.viz = new Viz({Module, render});
// eslint-disable-next-line no-console
console.error(e);
el.innerHTML = 'Error creating callback graph';
});
}
}

Expand Down
22 changes: 12 additions & 10 deletions dash-renderer/src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@ const initializeStore = reset => {

const reducer = createReducer();

// only attach logger to middleware in non-production mode
store =
process.env.NODE_ENV === 'production' // eslint-disable-line no-process-env
? createStore(reducer, applyMiddleware(thunk))
: createStore(
reducer,
window.__REDUX_DEVTOOLS_EXTENSION__ &&
window.__REDUX_DEVTOOLS_EXTENSION__(),
applyMiddleware(thunk)
);
// eslint-disable-next-line no-process-env
if (process.env.NODE_ENV === 'production') {
store = createStore(reducer, applyMiddleware(thunk));
} else {
// only attach logger to middleware in non-production mode
const reduxDTEC = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__;
if (reduxDTEC) {
store = createStore(reducer, reduxDTEC(applyMiddleware(thunk)));
} else {
store = createStore(reducer, applyMiddleware(thunk));
}
}

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