Added fromXml and toXml to Fields #2407
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The basics
The details
Resolves
#1627
Proposed Changes
Adds fromXml and toXml methods to fields that Blockly.Xml.domToField_ and fieldToDom_ can call.
Also changes the playground over to the new value-attribute rather than textContent based xml because... I thought it would be nice I guess ¯\_(ツ)_/¯
Reason for Changes
Some fields (e.g. variable fields) need more information to be serialized to xml than just the field name and value. This adds functions that custom fields can override so people can impliment more advanced fields without having to change the core.
Test Coverage
Added backwards compatibility mocha tests:
Also here's a gif of some things serializing and deserializing:
That generated this XML:
Switching the playground over also allowed me to test that the deserialization was working.
Tested on:
Additional Information
It may be better to call the 'variablename' attribute 'value' (even though it's more confusing) because I think having them be different is more prone to errors (i.e. when I was switching the playground over I messed it up a bunch).
Also I'm cool with removing the value attribute stuff all together, that was just in the original solution proposal so I went with it.