Skip to content

Commit

Permalink
Add infrastructure for updating connections in state
Browse files Browse the repository at this point in the history
  • Loading branch information
carterjbastian committed Mar 7, 2017
1 parent bf72806 commit 1e9a1ae
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions app/components/Diagram.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,39 @@ export default class Diagram extends Component {
this.handleClick = this.handleClick.bind(this);
};

createConnection(component, e) {
// If not currently connection, start connecting
if (this.state.setConnectionPoint == null ||
!this.state.isConnection) {
this.setState({
circles: this.state.circles,
squares: this.state.squares,
setConnectionPoint: component.props.id, // The connection point last clicked
isConnecting: true, // The currently connection point
connectionPoints: this.state.connectionPoints,
connections: this.state.connections,
});
} else { // End the connection by adding a connection point
// Get the current list of connections and add it to the state
let updatedConnections = this.state.connections.slice();

updatedConnections.push({
start: this.state.setConnectionPoint,
end: component.props.id,
});

this.setState({
circles: this.state.circles,
squares: this.state.squares,
setConnectionPoint: null, // The connection point last clicked
isConnecting: false, // The currently connection point
connectionPoints: this.state.connectionPoints,
connections: updatedConnections,
});

}
};

handleClick(e) {
// On a click, add a block to the diagram on the click location
e.preventDefault();
Expand Down

0 comments on commit 1e9a1ae

Please sign in to comment.