Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the way assembly inputs are deleted and the way equation inputs are deleted #269

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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