My main object represents an instance c1 of a Condition Java class. Initially it is loaded with 2 attributes
that is mandatory to set. From the mutator I want to be able to add optional attributes of the class.
To do this, within the workspace of the mutator UI I make a copy of my class block.
As you can see in the second image, the attributes to be added can be instances
of other classes. When I add a "class sub-block" in the mutator,
main block creates a complex block with its own mutator.
In the third image you can see how I modify an instance of the Reference class,
by adding an instance of the CodeableConcept class.
In the fourth image you can see how the resulting block remains. Until that point
Everything works fine.
The real problem is when removing blocks. To paint the attributes of the mutator,
I run the childBlocks of the mutator container and connect them in order to the input statement
Of the main block. But before, I have to delete the previous blocks. The problem I have
Is that those previous blocks have been modified and if I disconnect them and I simply catch the
Mutator childBlocks, I lose blocks that have been modified.
The fifth image shows the problem, I reopened the mutator of the main block and added
an instance of an Identifier object. As you can see I have lost the changes I had made
In the subject object.
I do not know if blockly implements some function that helps in some similar problem. Or if someone has faced
before some style problem. I do not know how to approach the problem.
/**
* Reconfigure this block based on the mutator dialog's components.
* @param {!Blockly.Block} containerBlock Root block in mutator.
* @this Blockly.Block
*/
compose(containerBlock) {
var childBlock = containerBlock.getInputTargetBlock('attributes');
this.mutatorChildBlocks_ = [];
while (childBlock) {
this.mutatorChildBlocks_.push(childBlock);
childBlock = childBlock.nextConnection &&
childBlock.nextConnection.targetBlock();
}
this.updateShape_();
},
/**
* Modify this block to have the correct child blocks.
* @private
* @this Blockly.Block
*/
updateShape_() {
let connection = this.getInput('attributes').connection;
// First, dispose of all my children.
for (let child of this.getChildren()) {
child.dispose();
}
for (let mutatorChildBlock of this.mutatorChildBlocks_) {
let childBlock;
//...
childBlock.initSvg();
childBlock.render();
connection.connect(childBlock.previousConnection);
connection = childBlock.nextConnection;
}
}