This commit is contained in:
Tiago Koji Castro Shibata 2018-07-19 17:29:02 -07:00
Родитель e9ed969656
Коммит 038ea59dbb
4 изменённых файлов: 26 добавлений и 4 удалений

Просмотреть файл

@ -6,6 +6,11 @@ export const updateGraph = (graph: any) => ({
type: actions.UPDATE_GRAPH,
})
export const updateInputs = (inputs: any) => ({
inputs,
type: actions.UPDATE_INPUTS,
})
export const updateMetadataProps = (metadataProps: IMetadataProps) => ({
metadataProps,
type: actions.UPDATE_METADATA_PROPS,

Просмотреть файл

@ -1,12 +1,14 @@
import { IMetadataProps, IProperties } from './state';
export const UPDATE_GRAPH = 'UPDATE_GRAPH';
export const UPDATE_INPUTS = 'UPDATE_INPUTS';
export const UPDATE_METADATA_PROPS = 'UPDATE_METADATA_PROPS';
export const UPDATE_PROPERTIES = 'UPDATE_PROPERTIES';
export interface IAction {
type: string,
graph: any,
inputs: [{description: string, id: string, name: string, type: string}],
metadataProps: IMetadataProps,
properties: IProperties,
}

Просмотреть файл

@ -7,6 +7,8 @@ export function rootReducer(state: IState, action: actions.IAction) {
case actions.UPDATE_GRAPH:
throw new Error('Not implemented');
// return { ...state, graph: action.graph };
case actions.UPDATE_INPUTS:
return { ...state, inputs: action.inputs };
case actions.UPDATE_METADATA_PROPS:
return { ...state, metadataProps: action.metadataProps };
case actions.UPDATE_PROPERTIES:

Просмотреть файл

@ -6,7 +6,7 @@ import 'netron/src/view-sidebar.css';
import 'netron/src/view.css';
import 'npm-font-open-sans/open-sans.css';
import { updateGraph, updateMetadataProps, updateProperties } from '../../../datastore/actionCreators';
import { updateGraph, updateInputs, updateMetadataProps, updateProperties } from '../../../datastore/actionCreators';
import IState from '../../../datastore/state';
import './fixed-position-override.css';
@ -17,6 +17,7 @@ interface IComponentProperties {
// Redux properties
updateGraph: typeof updateGraph,
updateInputs: typeof updateInputs,
updateMetadataProps: typeof updateMetadataProps,
updateProperties: typeof updateProperties,
}
@ -141,12 +142,23 @@ class NetronComponent extends React.Component<IComponentProperties, IComponentSt
}, {});
}
private installModelLoadedProxy() {
private installModelLoadedProxy = () => {
// Install proxy on browserGlobal.view.updateGraph and update the data store
const handler = {
apply: (target: any, thisArg: any, args: any) => {
const model = args[0];
// const graph = model.graphs[0];
// this.props.updateGraph(graph);
// FIXME What to do when model has multiple graphs?
const graph = model.graphs[0];
this.props.updateInputs(graph.inputs);
// Normalize graph
// const normalizedGraph: Array<{}> = [];
// for (const node of graph.nodes) {
// normalizedGraph.push({
// inputs: node.inputs,
// // ... Add other properties of interest
// });
// }
// this.props.updateGraph(normalizedGraph);
this.props.updateMetadataProps(this.propsToObject(model._metadataProps));
this.props.updateProperties(this.propsToObject(model.properties));
return target.apply(thisArg, args);
@ -166,6 +178,7 @@ const mapStateToProps = (state: IState) => ({
const mapDispatchToProps = {
updateGraph,
updateInputs,
updateMetadataProps,
updateProperties,
}