Skip to content

Commit

Permalink
fix(ExternalReader): Add support for external readers
Browse files Browse the repository at this point in the history
  • Loading branch information
jourdain committed Jan 26, 2018
1 parent 3592696 commit 323064a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
9 changes: 7 additions & 2 deletions Sources/controls/FileLoader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,19 @@ export default class FileLoader extends React.Component {
ReaderFactory.loadFiles(files).then(
(readers) => {
for (let i = 0; i < readers.length; i++) {
const { reader, sourceType, name } = readers[i];
const { reader, sourceType, name, dataset } = readers[i];
if (reader) {
const source = this.props.proxyManager.createProxy(
'Sources',
'TrivialProducer',
{ name }
);
source.setInputAlgorithm(reader, sourceType);
if (dataset) {
source.setInputData(dataset, sourceType);
} else {
source.setInputAlgorithm(reader, sourceType);
}

this.props.proxyManager.createRepresentationInAllViews(source);
this.props.proxyManager.renderAllViews();
}
Expand Down
2 changes: 2 additions & 0 deletions Sources/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import defaultConfig from './config/glanceProxyConfig';
import MainView from './MainView';
import ReaderFactory from './io/ReaderFactory';

export const { registerReader } = ReaderFactory;

export function createViewer(container, proxyConfiguration = defaultConfig) {
const proxyManager = vtkProxyManager.newInstance({ proxyConfiguration });
const mainView = ReactDOM.render(
Expand Down
6 changes: 4 additions & 2 deletions Sources/io/ReaderFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ function readFile(file) {
const reader = vtkReader.newInstance();
const io = new FileReader();
io.onload = function onLoad(e) {
reader[parseMethod](io.result);
resolve({ reader, sourceType, name: file.name });
const ds = reader[parseMethod](io.result);
Promise.resolve(ds).then((dataset) => {
resolve({ dataset, reader, sourceType, name: file.name });
});
};
io[readMethod](file);
} else {
Expand Down

0 comments on commit 323064a

Please sign in to comment.