Hi there, sorry if this has been asked for already, I tried to read through the forum here and the issue tracker and I don't see it listed but maybe I was just looking for the wrong words.
We are using blockly as part of an application, this application has the ability to inject blocks into the blockly workspace through some buttons. The blocks it injects need to hold on to some hidden state that is not visible to the user. For example, we have a block to read a text field (named "read_text") from an object, but regardless of what object that block is "operating" on it will appear the same. We define the blocks like this:
Blockly.Blocks.read_text = {
init: function() {
this.setOutput(true, 'String');
this.setColour(160);
}
};
Then when they are injected into the workspace to keep track of the extra data when we generate the code I do something like this:
block = Blockly.Block.obtain(blockly.mainWorkspace, 'read_text');
block.appendDummyInput().appendField(ctrl.fieldName);
block.VariableName = ctrl.variableName;
...
So that you end up with a block that just has a label on it such as "Owner" but it knows that it belongs to a particular variable. Having this information lets me do this to generate the code:
blockly.CSharp.text_field = function(block) {
return ['ReadTextField' + '('+block.VariableName+', "' + block.Path + '")', blockly.CSharp.ORDER_ATOMIC];
};
Which will then generate code that looks like this:
ReadTextField(m_documentData, 'OWNER');
That C# code is sent to our server where it is stored in that format. This all works great, except when we try to retrieve these blockly configurations from our server. When retrieving the blockly configuration from our server we have the server generate XML for the blocks from the C# code and hand that over, but for the extra data fields (.Path, .VariableName, etc.) we have to ship those along in a second data structure. This causes problems when we expect the blocks to get created in one order but blockly creates them in a different order. It has been very difficult to get the IDs we specify in the XML and extra data structure that is sent to the client to match the IDs generated by blockly so that we can fetch the blocks and attach this extra data.
Would it be possible to add some kind of provision to the XML parser for extra data tags? Perhaps any attributes prefixed with "data-" or something like that could get added to the blocks after they are created?
This would save us from having to send a second data structure that is connected by a very fragile ID mapping to the XML.
Also, would it be possible for the xml to workspace method to respect the IDs specified in the XML? If the first thing cannot be done we can continue to operate without trouble so long as we can be certain that the ID we specify for a block is the ID it will get within blockly.
Thanks so much for any input or solutions!