Make XML format extensible#3222
Conversation
Change-Id: Id88d09120b32a2f7bfa72b89719082f5d4d93b05
NeilFraser
left a comment
There was a problem hiding this comment.
Just some code style comments. No thoughts on the functionality.
| if (state.variablesFirst) { | ||
| Blockly.Xml.domToVariables(xmlChild, workspace); | ||
| } else { | ||
| Blockly.Xml.onError('\'variables\' tag must exist once before ' + |
There was a problem hiding this comment.
onError throws, so if you negate the if condition then you can drop the else, resulting in smaller, simpler code.
| } | ||
| state.variablesFirst = false; | ||
| } else { | ||
| throw TypeError('Shadow block cannot be a top-level block.'); |
There was a problem hiding this comment.
This is a throw, so negate the if statement, and drop the else.
Change-Id: I83d781ed04e150ec4cc2ee606c876782d608ee0a
|
Should parsing be per workspace? ie: do we see the need for some workspaces to have different parsing logic than others on a page. |
|
@samelhusseini With this solution one could install the appropriate handlers just before parsing a workspace, allowing for per-workspace parsing. I'm not sure that I would want to tie parsing structure to the workspace in case people want to leverage other formats in the future (I've been playing with JSON and protobufs, for example). |
|
This will be covered by the new JSON serialization system, so I'm going to go ahead and close this. |
The basics
The details
This is based on work I did at the hackathon in 2018 (yes, yes I know it's late). I'm motivated to add it sooner rather than later though due to some features we want to put into App Inventor that will require new top level elements in the XML.
Proposed Changes
This PR makes it so that one can register tags to be parsed, and can register serialization functions to serialize different parts of the workspace. This change also implements #3025.
Reason for Changes
In App Inventor, we store additional versioning metadata in the XML file that is used to determine when to upgrade from one version of the language to the next. Similarly, we are looking to add new features (such as folders), that might not be part of core Blockly, but still need to be serialized/deserialized preferably without modifying core.
Test Coverage
Ran the npm tests to confirm that nothing broke when parsing/serializing workspaces. Also tested with airstrike in the playground.
Tested on:
Documentation
There is now a
registerTopLevelTagmethod that takes:tagName(e.g.,'block')loadfunction that will be called with the XML element, workspace, and a statesavefunction that will be called with the workspace, XML rootopt_force, that will overwrite any previously registered save/load for the giventagName. This could be used, for example, to overwrite the default handling of<block>from outside of core.Additional Information
I'm putting this up for PR because I'd like to get some feedback from the team. Mainly:
registerTopLevelTagdesign?