Skip to content

Commit 62692b1

Browse files
authored
Merge pull request #13 from Grindlemire/ListenerBugFix
Fixes Bug with event listeners
2 parents 83f6190 + f08efa0 commit 62692b1

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/PlotlyComponent.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,7 @@ var PlotlyComponent = React.createClass({
1616
onSelected: React.PropTypes.func
1717
},
1818

19-
shouldComponentUpdate(nextProps) {
20-
//TODO logic for detecting change in props
21-
return true;
22-
},
23-
24-
componentDidMount() {
25-
let {data, layout, config} = this.props;
26-
Plotly.newPlot(this.container, data, cloneDeep(layout), config); //We clone the layout as plotly mutates it.
19+
attachListeners: function() {
2720
if (this.props.onClick)
2821
this.container.on('plotly_click', this.props.onClick);
2922
if (this.props.onBeforeHover)
@@ -36,10 +29,22 @@ var PlotlyComponent = React.createClass({
3629
this.container.on('plotly_selected', this.props.onSelected);
3730
},
3831

32+
shouldComponentUpdate(nextProps) {
33+
//TODO logic for detecting change in props
34+
return true;
35+
},
36+
37+
componentDidMount() {
38+
let {data, layout, config} = this.props;
39+
Plotly.newPlot(this.container, data, cloneDeep(layout), config); //We clone the layout as plotly mutates it.
40+
this.attachListeners();
41+
},
42+
3943
componentDidUpdate(prevProps) {
4044
//TODO use minimal update for given changes
4145
if (prevProps.data !== this.props.data || prevProps.layout !== this.props.layout) {
4246
Plotly.newPlot(this.container, this.props.data, this.props.layout);
47+
this.attachListeners();
4348
}
4449
},
4550

0 commit comments

Comments
 (0)