Skip to content

Commit

Permalink
Fix equation not deleting extra port
Browse files Browse the repository at this point in the history
  • Loading branch information
BarbourSmith committed Oct 5, 2019
1 parent 94f334d commit 9fdc6b0
Showing 1 changed file with 11 additions and 7 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

0 comments on commit 9fdc6b0

Please sign in to comment.