Skip to content

Commit

Permalink
Merge 9fdc6b0 into 50a94dc
Browse files Browse the repository at this point in the history
  • Loading branch information
BarbourSmith committed Oct 5, 2019
2 parents 50a94dc + 9fdc6b0 commit 6cf410c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
18 changes: 11 additions & 7 deletions src/js/molecules/equation.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,24 @@ export default class Equation extends Atom {
var re = /[a-zA-Z]/g
const variables = this.currentEquation.match(re)

//Remove any inputs which are not needed
const deleteExtraInputs = () => {
this.inputs.forEach( input => {
if( !variables.includes(input.name) ){
this.removeIO('input', input.name, this)
deleteExtraInputs() //This needs to be called recursively to make sure all the inputs are deleted
}
})
}
deleteExtraInputs()

//Add any inputs which are needed
for (var variable in variables){
if(!this.inputs.some(input => input.Name === variables[variable])){
this.addIO('input', variables[variable], this, 'number', 1)
}
}

//Remove any inputs which are not needed
for (var input in this.inputs){
if( !variables.includes(this.inputs[input].name) ){
this.removeIO('input', this.inputs[input].name, this)
}
}

if(this.inputs.every(x => x.ready)){

//Substitute numbers into the string
Expand Down
6 changes: 2 additions & 4 deletions src/js/prototypes/attachmentpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,12 +360,10 @@ export default class AttachmentPoint {
*/
deleteSelf(){
//remove any connectors which were attached to this attachment point

this.connectors.forEach( connector => {
var connectorsList = this.connectors //Make a copy of the list so that we can delete elements without having issues with forEach as we remove things from the list
connectorsList.forEach( connector => {
connector.deleteSelf()
this.deleteSelf() //This is a bit of a hack. It calls itself recursively until there are no connectors left because a single call will fail for multiple connectors. Each time one is removed from the list it messes up the forEach...There must be a better way
})

}

/**
Expand Down
1 change: 1 addition & 0 deletions src/js/prototypes/connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export default class Connector {

//Free up the input to which this was attached
this.attachmentPoint2.deleteConnector(this)
this.attachmentPoint2.setDefault()
}

/**
Expand Down

0 comments on commit 6cf410c

Please sign in to comment.