Skip to content

Commit 7582e26

Browse files
committed
fix(Render): Trigger render when algo change
1 parent 7c45a3f commit 7582e26

File tree

2 files changed

+34
-24
lines changed

2 files changed

+34
-24
lines changed

src/core/Algorithm.js

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { Component } from 'react';
22
import PropTypes from 'prop-types';
33

4-
import { DownstreamContext } from './View';
4+
import { RepresentationContext, DownstreamContext } from './View';
55

66
import vtk from 'vtk.js/vtk.js';
77

@@ -21,28 +21,33 @@ export default class Algorithm extends Component {
2121

2222
render() {
2323
return (
24-
<DownstreamContext.Consumer>
25-
{(downstream) => {
26-
if (!this.algo) {
27-
const { vtkClass, state } = this.props;
28-
this.algo = vtk({ vtkClass, ...state });
29-
}
30-
if (!this.downstream) {
31-
downstream.setInputConnection(
32-
this.algo.getOutputPort(),
33-
this.props.port
34-
);
35-
this.downstream = downstream;
36-
}
37-
return (
38-
<DownstreamContext.Provider value={this.algo}>
39-
<div key={this.props.id} id={this.props.id}>
40-
{this.props.children}
41-
</div>
42-
</DownstreamContext.Provider>
43-
);
44-
}}
45-
</DownstreamContext.Consumer>
24+
<RepresentationContext.Consumer>
25+
{(representation) => (
26+
<DownstreamContext.Consumer>
27+
{(downstream) => {
28+
this.representation = representation;
29+
if (!this.algo) {
30+
const { vtkClass, state } = this.props;
31+
this.algo = vtk({ vtkClass, ...state });
32+
}
33+
if (!this.downstream) {
34+
downstream.setInputConnection(
35+
this.algo.getOutputPort(),
36+
this.props.port
37+
);
38+
this.downstream = downstream;
39+
}
40+
return (
41+
<DownstreamContext.Provider value={this.algo}>
42+
<div key={this.props.id} id={this.props.id}>
43+
{this.props.children}
44+
</div>
45+
</DownstreamContext.Provider>
46+
);
47+
}}
48+
</DownstreamContext.Consumer>
49+
)}
50+
</RepresentationContext.Consumer>
4651
);
4752
}
4853

@@ -68,6 +73,9 @@ export default class Algorithm extends Component {
6873

6974
if (state && (!previous || state !== previous.state)) {
7075
this.algo.set(state);
76+
if (this.representation) {
77+
this.representation.dataChanged();
78+
}
7179
}
7280
}
7381
}

src/core/GeometryRepresentation.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ export default class GeometryRepresentation extends Component {
106106
}
107107

108108
dataChanged() {
109-
console.log('dataChanged');
109+
if (this.view) {
110+
this.view.renderView();
111+
}
110112
}
111113
}
112114

0 commit comments

Comments
 (0)